1

I'm running the new Windows Subsystem for Linux 2 (WSL-2), with Ubuntu 18.04. It is really fast, and running great, except I can't seem to connect to an external PostgreSQL database using Python. It just hangs, never responding. Here's a minimal reproduction:

$ python3.6
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> psycopg2.connect(host="my-pg-server.mydomain.com", port=5432, user="my_user", dbname="my_db", password="")
[...crickets... doesn't time out, just hangs forever (at least an hour)...]

It isn't a firewall issue, as I can connect with telnet to the same host:

$ telnet my-pg-server.mydomain.com 5432
Trying 123.456.789.100...
Connected to my-pg-server.mydomain.com.
Escape character is '^]'.

The other weird part is that I can connect to an external SQL Server database. I'm sure the credentials are correct for both servers, they're directly from a Django settings file that I'm using just fine on other systems. Any ideas? Is there something I have to do with psycopg2 specifically for WSL-2?

1 Answer 1

1

So it turns out I was pointing the finger in the wrong direction.

I logged into the PostgreSQL server box with a colleague, and issued this command:

ps -ef --sort=start_time | fgrep [db host name] | more

It turns out, the existing connections to the server were fine, but something is jammed up. I have a bunch of idle processes, then a slew of ones saying "startup waiting" - over 100. Here's the output from the command:

[...about 100 idle processes, truncated...]
postgres 26815 48821  0 Aug16 ? 00:00:00 postgres: my-pg-server: web_user web 192.168.9.187(55972) idle
postgres 27525 48821  0 Aug16 ? 00:00:00 postgres: my-pg-server: web_user web 192.168.9.187(55976) idle
postgres 14781 48821  0 00:00 ? 00:00:00 postgres: my-pg-server: postgres jsmith_d [local] VACUUM waiting
postgres 22738 48821  0 00:01 ? 00:00:00 postgres: my-pg-server: other_user other_db 192.168.9.187(57692) startup waiting
postgres  7683 48821  0 00:15 ? 00:00:00 postgres: my-pg-server: yetanother_user yetanother_db 192.168.9.187(57694) startup waiting
postgres 15951 48821  0 00:30 ? 00:00:00 postgres: my-pg-server: yetanother_user yetanother_db 192.168.9.187(57696) startup waiting
[...and about another 100 startup waiting processes, truncated...]

Aha! The culprit it found:

postgres 14781 48821 0 00:00 ? 00:00:00 postgres: my-pg-server: postgres jsmith_d [local] VACUUM waiting

It appears something is jammed up in the VACUUM process, which is causing the new connections to just hang, without failing. Time to dig a little deeper and clean it up, but there's the answer to this behavior.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.