Eshwaran Venkat
05/12/2022, 7:29 AMjuanlu
import 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
.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
Eshwaran Venkat
05/14/2022, 2:51 PMRick Lamers
Eshwaran Venkat
05/14/2022, 2:54 PM