This function returns the connection object of psycopg
(db, username, password, host, port, sslmode="prefer",
max_connections=None)
| 51 | |
| 52 | |
| 53 | def get_db_connection(db, username, password, host, port, sslmode="prefer", |
| 54 | max_connections=None): |
| 55 | """This function returns the connection object of psycopg""" |
| 56 | if max_connections: |
| 57 | with psycopg.connect( |
| 58 | dbname=db, |
| 59 | user=username, |
| 60 | password=password, |
| 61 | host=host, |
| 62 | port=port, |
| 63 | sslmode=sslmode, |
| 64 | autocommit=True, |
| 65 | ) as conn: |
| 66 | cur = conn.cursor() |
| 67 | cur.execute('ALTER SYSTEM SET max_connections TO 100;') |
| 68 | cur.execute('SELECT pg_reload_conf();') |
| 69 | |
| 70 | connection = psycopg.connect( |
| 71 | dbname=db, |
| 72 | user=username, |
| 73 | password=password, |
| 74 | host=host, |
| 75 | port=port, |
| 76 | sslmode=sslmode |
| 77 | ) |
| 78 | return connection |
| 79 | |
| 80 | |
| 81 | def get_server_version(connection): |
no test coverage detected