1

I'm working in Datalore (a jupyter notebook IDE) and I'm trying to connect to a postgresql (version 14) table via the following line of code.

df = pd.read_sql_table('emp','postgresql://{username}:{password}@localhost:5432/postgres')

where username and password are supplied in my notebook.

This gives the following error message:

OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address Is the server running on that host and accepting TCP/IP connections? (Background on this error at: https://sqlalche.me/e/14/e3q8)

When trying to test the connection to my database from the Datalore side pane, I get the following error message:

Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

I have already altered the IP address in pg_hba.conf from 127.0.0.0/32 to 0.0.0.0/0. Additionally, I have checked postgresql.conf and the listen_addresses = '*'.

My thoughts are that localhost shouldn't be used or that postmaster needs to be reset. If I am correct:

  • What should be used instead of localhost, and where do I find the correct hostname
  • How do I reset postmaster (I manually installed postgresql, I did not use Homebrew).

Is there anything else I haven't considered?

gphull
  • 78
  • 5
  • Is the postgres server installed on the same computer you're running Datalore on? – Nick ODell Jul 01 '22 at 23:38
  • Yes and no. Postgres is installed on my laptop, the one I am writing this from. Datalore is running on this laptop as well. However, Datalore is an IDE, I believe in the form of a web app. Additionally, when running code on Datalore it runs via a cloud computer. So, technically the code is running on a different machine. It indicates that it is running via a t2.medium machine, which implies the AWS EC2 service is being used. I hope this helps, let me know if you need any clarification. – gphull Jul 02 '22 at 01:15
  • Well, if they're not on the same computer, then it won't work unless you do an SSH reverse tunnel or something like that. It's the -R option of SSH: https://linux.die.net/man/1/ssh – Nick ODell Jul 02 '22 at 07:39
  • @gphull, have you solved this? – Jia Gao Jan 20 '23 at 08:04

0 Answers0