Disclaimer: I did a lot of research throughout the internet for the solutions, but somehow none of them solve my case
Background: I want to directly connect my ML python source code to my DBMS which is Postgre using psycopg2.
connection = psycopg2.connect(
dbname = '<databasename>',
user = 'postgres',
password = '<mypass>',
host = 'localhost',
port = '5432',
requiressl = 0
)
cursor = connection.cursor()
Error: Somehow it throws me an error like this
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?
It seems like the port is listening only to the localhost IP (127.0.0.1).
What I’ve done:
- Stated from other sources, it seems like we have to adjust the listening addresses through the
postgresql.conf
file so that the machine could give permission for access outside the local one. - I also did change the
pg_hba.conf
source code, by changing
`
IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
to
IPv4 local connections:
host all all 0.0.0.0/0 scram-sha-256
I restarted the machine, but still nothings work.
I also did make sure that my port is listening to the right address
`enter image description here
Note: My directories for the 2 files above is Program FilesPostgreSQL16data<both files> and I am running on Windows
Fhlipfhlop is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.