我试图用postgresSQL ( package)更新psycopg2表,但有时由于以下错误而失败。
服务器意外地关闭了连接,这可能意味着服务器在处理请求之前或处理过程中异常终止。
from psycopg2 import pool
now = datetime.now()
logoff_time = datetime(now.year, now.month, now.day, 15, 0, 0)
while True:
time.sleep(1)
try:
status = 'EXECUTED'
exec_type1 = 'CANCELLED'
exec_type2 = 'COMPLETED'
try:
postgreSQL_pool = pool.SimpleConnectionPool(1, 20, host = db_host,
database = db_name,
port = db_port,
user = db_user,
password = db_pwd)
if postgreSQL_pool:
print("Connection pool created successfully")
conn = postgreSQL_pool.getconn()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
sql = """ UPDATE orders SET status = %s, executed_type = %s WHERE order_id = %s"""
updated_rows = 0
try:
cur = conn.cursor()
cur.execute(sql, (status, exec_type1, order_id,))
conn.commit()
updated_rows = cur.rowcount
cur.close()
break
except (Exception, psycopg2.DatabaseError) as error:
print(error)
print(updated_rows)
except Exception as e:
print(e)psycopg2版本:'2.8.6 (dt dec pq3 ext lo64)‘Postgres: PostgreSQL 12.7 on x86_64-pc-linux-gnu,由gcc (GCC) 4.8.3 20140911 (Red 4.8.3-9),64位编辑
这是一个简单的任务,但也面临着挑战。请提出建议
发布于 2021-10-11 22:45:52
服务器正在崩溃,原因是您可能能够读取服务器的日志。
https://stackoverflow.com/questions/69490285
复制相似问题