PostgreSQL: Why psql can't connect to server?

前端 未结 22 2133
情书的邮戳
情书的邮戳 2020-12-07 10:40

I typed psql and I get this:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    con         


        
相关标签:
22条回答
  • 2020-12-07 10:53

    Just want to make a small addition: if your instance is complaining on a socket, you can also check unix_socket_directories at /data/postgresql.conf file which could have been set to /tmp, for example, if you have used a 3rd party distribution. You can change it to /var/run/postgresql and restart the service. That may also require creating a postgresql dir at /var/run and subsys/postgresql-9.6 at /var/lock if those doesn't already exist (worked for me with postgresql 9.6).

    0 讨论(0)
  • 2020-12-07 10:58

    It can cause anything for example, my issue was caused for typo error on configuration files. Some of people says caused by certificate files, another group says caused by unmatched locals.

    If you cant find any solution about your issue, remove postgres and reinstall it.This is the best solution.

    0 讨论(0)
  • 2020-12-07 11:00

    I had the same issue on Devuan ascii (maybe Debian, too?). The config file /etc/postgresql/9.6/main/postgresql.conf contains a directive unix_socket_directories which points to /var/run/postgresql by default. Changing it to /tmp, where most clients look by default, fixed it for me.

    0 讨论(0)
  • 2020-12-07 11:02

    quick howto on debian to remotely access postgres database on server from the psql client: (the changed config is doc'd in the files):

    1. edit /etc/postgresql/10/main/postgresql.conf with listen_address *
    2. edit /etc/postgresql/10/main/pg_hba.conf and add line in the end with host all all 0/0 md5
    3. create login role postgres=# CREATE ROLE remoteuser LOGIN WITH PASSWORD 'foo'
    4. sudo /etc/init.d/postgresql restart changes take effect

    5. login from clientside with psql --host=ipofserver --port=5432 --username=remoteuser --password --dbname=mydb

    6. the password is interactivly asked which in this case is foo
    0 讨论(0)
  • 2020-12-07 11:03

    During fresh installation of postgresql. By default, user name and password is assigned as "postgres". The feature this RDBMS provides is to add role for new user and create database. If you are getting such errors:

    1. login in by default username:

      root@kalilinux:~# sudo -i -u postgres

    2. ype psql for interactive prompt

      postgres@kalilinux:~$ psql

    3. To quit from prompt use

      \q

    4. To create new user role

      postgres@kalilinux:~$ createuser --interactive

    Now you are in interacive psql shell. Enjoy. Dont forget to login in from your username and type psql for shell.

    0 讨论(0)
  • 2020-12-07 11:06

    I had the same problem. It seems that there is no socket when there is no cluster.

    The default cluster creation failed during the installation because no default locale was set.

    0 讨论(0)
提交回复
热议问题