skip to Main Content

I am new to using postgres.I have it installed in my computer but as soon as I try running the psql command it throws the following error;

postgres@lennox-ThinkPad-T470s:~$ psql
psql: error: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I have tried restarting as per the documentation but it still keeps throwing the same error.

3

Answers


  1. This issue comes from installing the postgres package without a version number. Although postgres will be installed and it will be the correct version, the script to setup the cluster will not run correctly; it’s a packaging issue.

    If you’re comfortable with postgres there is a script you can run to create this cluster and get postgres running. However, there’s an easier way.

    First purge the old postgres install, which will remove everything of the old installation, including databases, so back up your databases first.. The issue currently lies with 9.1 so I will assume that’s what you have installed

    sudo apt-get remove --purge postgresql-9.1
    

    Now simply reinstall

    sudo apt-get install postgresql-9.1
    

    Note the package name with the version number. HTH.

    Login or Signup to reply.
  2. Or try this :
    Edit: postgresql.conf

    sudo nano /etc/postgresql/9.3/main/postgresql.conf
    

    Enable or add:

    listen_addresses = '*'
    

    Restart the database engine:

    sudo service postgresql restart
    

    Also, you can check the file pg_hba.conf

    sudo nano /etc/postgresql/9.3/main/pg_hba.conf
    

    And add your network or host address:

    host    all             all             192.168.1.0/24          md5
    
    Login or Signup to reply.
  3. My suggestion is you should see if you have initialized your database for that go to your postgreSQL

    cd postgresql-11.18/

    bin/initdb demo

    name of db cluster is demo

    then start the server

    bin/pg_ctl -D demo -l logfile start

    bin/createdb demodb

    then query the server

    bin/psql demodb

    if you have something running on the port 5434 you can change your port while creating the db and us this command insted

    bin/createdb –port=5430 demodb

    Hope this helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search