diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-06-28 23:25:48 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-12-21 19:43:13 +0200 |
| commit | dd5ea8ca68f9f006b903e4b026172006cbaf8e18 (patch) | |
| tree | d6bb572f0c533832d86960a6590989cfb12b397e /db.py | |
| parent | 737302e1c18c71ac55c7e241c8ef30003ad64f97 (diff) | |
Add recommended Postgres connection options to reduce disconnections
Diffstat (limited to 'db.py')
| -rw-r--r-- | db.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -33,7 +33,23 @@ class Db: database=os.getenv('DB_DATABASE', 'postgres'), port=os.getenv('DB_PORT', '5432'), user=os.getenv('DB_USER', 'postgres'), - password=os.environ['DB_PASSWORD']) + password=os.environ['DB_PASSWORD'], + + keepalives=1, + keepalives_idle=30, + keepalives_interval=10, + keepalives_count=5, + + application_name='diddle', + connect_timeout=10, + sslmode='prefer', + client_encoding='UTF8', + ) + + # Set the transaction isolation level + with self.conn.cursor() as cursor: + cursor.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED") + self.conn.commit() def get_cursor(self): for _ in range(self.MAX_RETRIES): |
