Eshwaran Venkat
05/12/2022, 7:29 AMjuanlu
05/12/2022, 7:32 AMimport psycopg2
con = psycopg2.connect(host="your-host", user="postgres", dbname="postgres", password="postgres")
with con.cursor() as cursor:
cursor.execute("SELECT * FROM pg_stat_activity WHERE pid <> pg_backend_pid( ) AND datname = current_database()")
while row := cursor.fetchone():
print(row)
Eshwaran Venkat
05/12/2022, 7:37 AMJacopo
05/12/2022, 7:43 AMjuanlu
05/12/2022, 7:45 AM.sql
file in Python, it's enough to read all the contents and pass the string to the execute
method of the psycopg2 cursor, see https://stackoverflow.com/a/50006361/554319Rick Lamers
05/12/2022, 11:37 AMEshwaran Venkat
05/14/2022, 2:51 PMRick Lamers
05/14/2022, 2:53 PMEshwaran Venkat
05/14/2022, 2:54 PM