More

    Error: psql: 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”?

    While connecting to Postgres Database from any client we often face of not able to connect to the database server with following error.

    Error: psql: 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"?

     

    REASON:

    The Postmaster or PostgreSQL’s server daemon process is not running.

    Typically this error means PostgreSQL is not currently running on the system you are logged into. You will need to start the daemon, which is typically done through your distribution’s init system.

    Ways to check the services:

    1. ps -eaf | grep postgres

    postgres 18950 1 0 Feb10 ? 00:01:53 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/data
    postgres 18951 18950 0 Feb10 ? 00:00:00 postgres: logger
    postgres 18953 18950 0 Feb10 ? 00:00:04 postgres: checkpointer
    postgres 18954 18950 0 Feb10 ? 00:00:50 postgres: background writer
    postgres 18955 18950 0 Feb10 ? 00:00:52 postgres: walwriter
    postgres 18956 18950 0 Feb10 ? 00:01:10 postgres: autovacuum launcher
    postgres 18957 18950 0 Feb10 ? 00:00:13 postgres: archiver last was 0000000200000001000000E1
    postgres 18958 18950 0 Feb10 ? 00:02:11 postgres: stats collector
    postgres 18959 18950 0 Feb10 ? 00:00:03 postgres: logical replication launcher

    2. Another way to check using systemctl command.

    systemctl status postgresql-13.service
    postgresql-13.service - PostgreSQL 13 database server
    Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
    Active: active (running) since Wed 2021-02-10 12:49:01 IST; 2 months 18 days ago
    Docs: https://www.postgresql.org/docs/13/static/
    Main PID: 18950 (postmaster)
    Tasks: 9 (limit: 49252)
    Memory: 57.2M
    CGroup: /system.slice/postgresql-13.service
    ├─18950 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/data
    ├─18951 postgres: logger
    ├─18953 postgres: checkpointer
    ├─18954 postgres: background writer
    ├─18955 postgres: walwriter
    ├─18956 postgres: autovacuum launcher
    ├─18957 postgres: archiver last was 0000000200000001000000E1
    ├─18958 postgres: stats collector
    └─18959 postgres: logical replication launcher

    3. services can also be checked using pg_ctl command

    pg_ctl status -D /var/lib/pgsql/data
    pg_ctl: server is running (PID: 18950)
    /usr/pgsql-13/bin/postgres "-D" "/var/lib/pgsql/data/"

    SOLUTION:

    Start the PostgreSQL daemon, using any one of the following commands and check the status again. If it is up then you will be able to connect to the service.

    systemctl start postgresql-13.service
    or
    pg_ctl status -D /var/lib/pgsql/data

    Recent Articles

    spot_img

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Ge the daily news in your inbox