简体   繁体   中英

Postgres could not connect to database postgres: could not connect to server: No such file or directory?

I am using 4.14.10-2-MANJARO. I have tried to install Postgres Database. I have installed postgresql 10.1-1 by using command:

yaourt -S postgresql

And then:

sudo -u postgres -i

initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'

createuser --interactive

And then I have got something like this:

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 "/run/postgresql/.s.PGSQL.5432"?

I don't know how to solve it. I have been using this website:

https://wiki.archlinux.org/index.php/PostgreSQL#Installing_PostgreSQL

Then I would like to create a new database by command:

createdb myDatabaseName

Thank you.

After creating the data directory with initdb , you need to start the database server process with

pg_ctl -D /var/lib/postgres/data start

But before that, you should edit /var/lib/postgres/data.postgresql.conf and set parameters like listen_addresses , port , shared_buffers and everything concerning logging.

That way, you can consult the log file after starting the server to see if everything went well.

I had the same problem and I am also running 4.19.1-1-MANJARO and postgresql 10.5-3 , but most answers are for Ubuntu and refers to directories that don't exist on Manjaro.

You have to run systemctl to check the service to see what is wrong

sudo systemctl status postgresql

It gives something like this

systemd[1]: Starting PostgreSQL database server...
postgres[3902]: "/var/lib/postgres/data" is missing >
postgres[3902]:   su - postgres -c "initdb --locale >

and it tells you to run the su command listed above. But this requires the password of the user postgres . To go around this we sudo the command instead.

sudo su - postgres -c "initdb --locale en_US.UTF-8 -D /var/lib/postgres/data'"

When this command is finished it tells you to run pg_ctl -D /var/lib/postgres/data start , but instead just start it via systemctl.

sudo systemctl enable postgresql
sudo systemctl start postgresql

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