-2

I got an error when I tried to access my database on postgresql:

sudo -i -u psquser psql psqdb

psql: 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 don't know what cause the problem since before that I could access it as normal.

As this problem before, I tried to reinstall postgresql by following this instrunction How to thoroughly purge and reinstall postgresql on ubuntu? [closed]. It took me lot of time since I have to to configured almost everything from scratch.

Is there an alternative better that I can solve this problem? Could I know what is the rootcause of this.

PS: I hosted this server on digital ocean.

Houy Narun
  • 1,557
  • 5
  • 37
  • 86

1 Answers1

2

Theres another thread that suggest Postgresql is not always running, check by;

sudo /etc/init.d/postgresql start
Slumdog
  • 470
  • 2
  • 4
  • thanks, It got rid of error message above, but when I tried access database again `sudo -i -u psquser psql psqdb`, I got role 'psquser' does not exist. – Houy Narun Aug 22 '18 at 03:58
  • even I try access via default user 'postgres' `psql -U postgres` to alter user 'psquser' also not work, it ask for password of user 'postgres'. Thanks – Houy Narun Aug 22 '18 at 04:01
  • 1
    Hmmm ok, you might need to check the pg_hba.conf for your psqdb setting and the postgresql logs. But wait, shouldn't you be using upper case -U psquser ? – Slumdog Aug 22 '18 at 09:19
  • after google around, I have changed `pg_hba.cong` to `local all postgres ident` and manually created role and privilege for user `psquser`. Then, I was enable access database and restore it successfully. Thanks very much for your answer, it really helped I will accept it :) – Houy Narun Aug 22 '18 at 09:28