简体   繁体   中英

PG could not connect to server when trying to install postgresql on Manjaro

I tried to install postgresql on Linux Manjaro and create db and user.

I have executed next commands:

$ sudo pacman -S postgresql postgis
$ sudo -u postgres -i

Than

$ initdb  -D '/var/lib/postgres/data'

returns 'access denied' error.

I was trying to create connection via pgAdmin4. Than I got next error:

createuser: could not connect to database postgres: 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"?

I found a lot of similar issues. So tried some solves like changing the path of db location or reinstall postgresql.

My aim is to run pg in Rails. But now I have

PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"

when I am trying to execute

$ rails db:create

Seems, I do not understand the whole way of pg configuring. Thank you!

UPDATED: Next commands solved the problem:

sudo pacman -R postgresql
sudo pacman -S postgresql postgis
sudo su - postgres -c "initdb -E UTF8 -D '/var/lib/postgres/data'"
systemctl start postgresql
systemctl status postgresql
sudo su - postgres
createuser user1
createdb -O user1 db1
psql db1 -U user1

Next commands solved the problem:

sudo pacman -R postgresql
sudo pacman -S postgresql postgis
sudo su - postgres -c "initdb -E UTF8 -D '/var/lib/postgres/data'"
systemctl start postgresql
systemctl status postgresql
sudo su - postgres
createuser user1
createdb -O user1 db1
psql db1 -U user1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM