PostgreSQL: Why psql can't connect to server?

前端 未结 22 2191
情书的邮戳
情书的邮戳 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 11:08

    In my case, the service was running but the cluster was down and psql wouldn't start. My configuration files looked perfect but it kept throwing configuration errors and seemed to ignore the changes I was making.

    It turns out that whenever you use ALTER SYSTEM SET ... syntax, PostgreSQL writes to a file called postgresql.auto.conf. That file is read in addition to the regular postgresql.conf and pg_hba.conf files. In my distribution of Ubuntu (18.04), they are in different folders(!):
    - pg_hba.conf and postgresql.conf are both in /etc/postgresql/12/main
    - The auto-generated file is /var/lib/postgresql/12/main/postgresql.auto.conf

    I had tried to change the configuration using ALTER SYSTEM SET listen_addresses = , but had made a mistake and that created a broken "ghost" configuration that I couldn't find. As soon as I erased the offending line in postgresql.auto.conf, it fixed everything.

提交回复
热议问题