首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >postgresSQL异常终止

postgresSQL异常终止
EN

Stack Overflow用户
提问于 2021-10-08 03:51:26
回答 1查看 123关注 0票数 1

我试图用postgresSQL ( package)更新psycopg2表,但有时由于以下错误而失败。

服务器意外地关闭了连接,这可能意味着服务器在处理请求之前或处理过程中异常终止。

代码语言:javascript
复制
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位编辑

这是一个简单的任务,但也面临着挑战。请提出建议

EN

回答 1

Stack Overflow用户

发布于 2021-10-11 22:45:52

服务器正在崩溃,原因是您可能能够读取服务器的日志。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69490285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档