Postgres SSL SYSCALL error: EOF detected with python and psycopg

前端 未结 7 1807
误落风尘
误落风尘 2020-12-15 03:40

Using psycopg2 package with python 2.7 I keep getting the titled error: psycopg2.DatabaseError: SSL SYSCALL error: EOF detected

It only occurs when I add a WHE

相关标签:
7条回答
  • 2020-12-15 04:16

    The error: psycopg2.operationalerror: SSL SYSCALL error: EOF detected

    The setup: Airflow + Redshift + psycopg2

    When: Queries take a long time to execute (more than 300 seconds).

    A socket timeout occurs in this instance. What solves this specific variant of the error is adding keepalive arguments to the connection string.

    keepalive_kwargs = {
        "keepalives": 1,
        "keepalives_idle": 30,
        "keepalives_interval": 5,
        "keepalives_count": 5,
    }
    
    conection = psycopg2.connect(connection_string, **keepalive_kwargs)
    

    Redshift requires a keepalives_idle of less than 300. A value of 30 worked for me, your mileage may vary. It is also possible that the keepalives_idle argument is the only one you need to set - but ensure keepalives is set to 1.

    Link to docs on postgres keepalives.

    Link to airflow doc advising on 300 timeout.

    0 讨论(0)
提交回复
热议问题