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?