CodeIgniter Forums
Need help Resolving a PostgreSQL Connection Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: Need help Resolving a PostgreSQL Connection Problem (/showthread.php?tid=88667)



Need help Resolving a PostgreSQL Connection Problem - leusiam - 10-15-2023

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.


RE: Need help Resolving a PostgreSQL Connection Problem - InsiteFX - 10-15-2023

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"