使用 psycopg2 连接到 postgres 数据库时出错

时间:2021-02-11 00:51:15

标签: python postgresql amazon-web-services boto3 psycopg2

我正在尝试连接到 postgres 数据库以运行一些查询以进行验证。尝试通过 psycopg2 建立连接。已尝试为主机而不是变量传递实际值。

尝试使用 psql 连接以验证连接参数、密码等,它们也是正确的。 但是对于下面的代码,它总是会出现下面的错误

    conn1 = psycopg2.connect(host=db_host,database=db_instance_name,user=masterusername,port=db_port,password=masterpassword)
    cur1 = conn1.cursor()
    print ('\n************Connection is successful ************ \n')
Traceback (most recent call last):
  File "restored_db_details_draft.py", line 50, in <module>
    conn_test = psycopg2.connect(host="***",database="my_db_name",user="master",port="9876",password="****")
  File "/Users/me/Library/Python/3.8/lib/python/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

0 个答案:

没有答案