Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL error: could not connect to database template1: could not connect to server: No such file or directory

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.

like image 456
pptt Avatar asked May 07 '15 08:05

pptt


People also ask

Can't connect to Postgres No such file or directory?

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.

What is template1 in Postgres?

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.

Can't connect to Postgres server?

“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.

How to fix PostgreSQL PSQL could not connect to server?

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 ...

Why can't I create a database in Postgres?

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.

How to fix PostgreSQL createb and createuser errors?

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.

How do I connect to a PostgreSQL database in Vivek?

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


1 Answers

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.

like image 76
Daniel Vérité Avatar answered Sep 16 '22 13:09

Daniel Vérité