1

I'm connecting Redshift through Python from PC, Python from Lambda and SQL Workbench. SQL Workbech always connects without any issues. Both PC and Lambda often work correctly, but sometimes they can't connect - it looks like connection is waiting for Redshift to accept request, just nothing happens until, for ex. Lambda times out.

There's no log in run, no feedback information, nothing in redshift logs I can find about it. I can fix every single run manually by connecting in Workbench, while the script is waiting for connection - it apparently refreshes something, allowing Python to connect and work properly. What is the reason for this and how can I fix it?

Here's my connection:

conn = psycopg2.connect(
    host=host,
    database=db,
    user=user,
    password=pwd,
    port=port
)

I went through several questions regarding connections like:

AWS Lambda times out connecting to RedShift

AWS Serverless lambda times out while connecting to redshift

python socket Windows 10 connection times out

but nothing looks like its related to my issue.

Manaslu
  • 228
  • 1
  • 13

1 Answers1

0

Found an answer - SQL Workbench blocked the connection. When Workbench is connected, all other sources happen to fail. Easiest solution is to disconnect Workbench connection before other client tries to connect. If other client already tried connecting, then disconnecting is not enough - it requires reconnecting, so the other client refreshes (I have no idea why, found it by trial and error).

Disconnection may also not work, if there was any error query run in the past and it was not rolled back. After error, rollback and disconnection everything is fine.

Manaslu
  • 228
  • 1
  • 13