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
#2

You can try changing this some time this will fix the db problems connecting.

PHP Code:
// Change this
host="localhost",

// To this
host="127.0.0.1"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB