Welcome Guest, Not a member yet? Register   Sign In
Need help Resolving a PostgreSQL Connection Problem
#1

I'm presently working on a Python application that connects to a PostgreSQL database using the psycopg2 package, however I've run across a connection problem that has me stumped, so I read this post from a scaler for clarification but couldn't get it. The code I'm using to connect to the database is as follows:
Code:
import psycopg2

try:
    conn = psycopg2.connect(
        database="mydb",
        user="myuser",
        password="mypassword",
        host="localhost",
        port="5432"
    )
except psycopg2.Error as e:
    print(f"Error: {e}")

When I execute this code, however, I receive the following error message:
Code:
Error: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I confirmed that PostgreSQL is operating and that the connection information is valid. Could you possibly assist me in determining what is generating this problem and how to remedy it?

Your help is much appreciated.
Reply


Messages In This Thread
Need help Resolving a PostgreSQL Connection Problem - by leusiam - 10-15-2023, 01:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB