Answers for "postgres connection check"

0

test the postgresql db connection

psql -U kodekloud_aim -d kodekloud_db8 -h 127.0.0.1 -W  ## Change name according to question
#### for the test on mode postgres u have
## \conninfo 
## \l
## \dg+
## \q   # to quit
psql -U kodekloud_gem -d kodekloud_db10 -h localhost -W
Posted by: Guest on January-08-2022
0

postgres connection check

from sqlalchemy import event
from sqlalchemy import create_engine

engine = create_engine("postgresql+psycopg2://scott:tiger@host/dbname")

@event.listens_for(engine, "connect", insert=True)
def set_search_path(dbapi_connection, connection_record):
    existing_autocommit = dbapi_connection.autocommit
    dbapi_connection.autocommit = True
    cursor = dbapi_connection.cursor()
    cursor.execute("SET SESSION search_path='%s'" % schema_name)
    cursor.close()
    dbapi_connection.autocommit = existing_autocommit
Posted by: Guest on April-27-2022

Python Answers by Framework

Browse Popular Code Answers by Language