Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Postgres import error: is the server running locally and accepting connections on Unix domain socket?

I am running on a shared bluehost box. The weird thing is that my site runs fine online. I can pull up the django /admin/ site just fine. However, I can't run manage.py migrate or make any queries to the database through the manage.py shell. Here is the error I am getting:

File "/home2/univetg1/python3/lib/python3.5/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 172, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home2/univetg1/python3/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: 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"?

here are my database settings in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'univetg1_lunchbox',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '',
        'PORT': '',
    }
}

It's weird because I haven't been playing around with my settings.py file or anything and things have been working fine until just now.

like image 969
Chase Roberts Avatar asked Dec 01 '25 04:12

Chase Roberts


1 Answers

If you get an error like:

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"?

then the server is:

  • not running;
  • running on a port other than 5432; or
  • configured with a different unix_socket_directories path so it's not listening for the socket in /tmp

We know that the server is running since your Django site is working. So it's presumably a matter of connection info. Assuming that Django is actually using the data in settings.py, it must be on port 5432 as well.

So my guess is that it's using a different unix_socket_directories. Maybe the libpq you're linking to at runtime on an interactive console is different to the one being linked to when running the service.

You could try connecting over TCP/IP by specifying the host as localhost. Otherwise, check what unix_socket_directories is set to in postgresql.conf and set that as your HOST.

like image 131
Craig Ringer Avatar answered Dec 03 '25 17:12

Craig Ringer