import psycopg2
from psycopg2 import pool
connection_pool = psycopg2.pool.ThreadedConnectionPool(1, 50, user='A', password='S', host='D',port='D', database='AD')
def fetch_data(id):
try:
sql = build_sql_query('SELECT * FROM USERS')
connection = connection_pool.getconn()
cursor = connection.cursor()
cursor.execute(sql)
records = cursor.fetchall()
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
我不想断开连接。想用生命周期与 postgres 建立全球联系。我已经尝试了很多,但如果有的话,请告诉我。