PostgreSQL : Maintaining connections?

The only DB I’ve used with Xojo has really been SQLite and as a single user DB.

When using SQLite I connect whenever the app needs to do something and disconnect …

For using Postgres with multiple uses on a separate server , is it best to connect and stay connected or connect only when the app needs to do a DB operation and then disconnect?

Also for a user to be able to log out of the DB without closing the app, would one just disconnect then set username and password to “” in the DB object or should one (after closing the connection) delete that DB instance and create a new one?

Thanks,
-Karen

If there is only one thread, you can maintain one connection, but periodically check to make sure it’s still alive. I use something simple like SELECT 1.

Each thread should have its own connection.

You can also open, use, and close, but that takes longer in theory. (In practice, you won’t notice.)

When done with the instance, I’d nil it and get a new one.

2 Likes

Thanks,
Kem