I need to create database.
First I run: sudo su - postgres
, then: createdb test
And I keep getting this error:
createdb: could not connect to database template1: 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"
This is unexpected, I have never encountered any problems with psql, but this time I don't get what is wrong. And there is no external server, I am connected locally.
I am running on Ubuntu.
When connecting to Postgres you might see this error: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket <some socket> . This happens most often when Postgres' server daemon process is not running.
CREATE DATABASE actually works by copying an existing database. By default, it copies the standard system database named template1 . Thus that database is the “template” from which new databases are made.
“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.
PostgreSQL psql: could not connect to server: Connection refused Step # 1: Allow remote IP address to access PostgreSQL. Now append following line. ... Please replace 192.168.1.0 and... Step # 2: Allow communication over TCP/IP. Save and close the file. Step # 3: Restart PostgreSQL server. This ...
If your having trouble logging into Postgres make sure that you create a user in Postgres that allows the user to be able to CREATEDB. So if your user is JohnDoe make sure that you give permission for JohnDoe to create database. Links to help you out with granting permission.
In order to fix this error, you need to switch to a user that’s running PostgreSQL server. By default, UNIX user 'postgres' is the one that will be running PostgreSQL server. So the createdb & createuser commands should be executed as 'postgres' user account as shown below.
Use psql command from client system as follows: psql -h PostgreSQL-IP-ADDRESS -U USERNAME -d DATABASENAME Connect to remote server by IP address 192.168.1.5 and login using vivek user to connect to sales database, use: $ psql -h 192.168.1.5 -U vivek -d sales
The error message suggests:
Is the server running locally
and according to the result of ps -ef | grep "post"
posted in the comments, the answer is a definitive No, the server processes are not there, the server is not running.
That fact that you write i have never encountered any problems with psql, suggests that it was installed and working before, in that case look at the most recent log file inside /var/log/postgresql
to check for any fatal error message indicating why the server didn't start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With