13

I have successfully installed PostgreSQL 9.3 from the APT repository on 2 VM's running Ubuntu 12.04 and 13.04...however, I cannot get it to install properly on my host machine running Ubuntu 12.04.

The install (this time) seems to have gone ok, but perhaps there is an error I'm not understanding:

* No PostgreSQL clusters exist; see "man pg_createcluster"
Setting up postgresql-9.3 (9.3.0-2.pgdg12.4+1) ...
Creating new cluster 9.3/main ...
  config /etc/postgresql/9.3/main
  data   /var/lib/postgresql/9.3/main
  locale en_US.UTF-8
  port   5432
update-alternatives: using /usr/share/postgresql/9.3/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode.

So I then try to add myself as a PostgreSQL user, but I get 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 "/var/run/postgresql/.s.PGSQL.5432"?

I cannot see PostgreSQL running in system monitor, and there is no file in the /var/run/postgresql/ folder...completely empty.

EDIT: On the VM's, there is a file in /var/run/postgresql/ called 9.3-main.pid

There is nothing on the host machine log file located /var/log/postgresql

So... what's going on here that isn't going on in my VM's? Like I said, the other installations on the VM's, including PostGIS and PGAdmin came in perfect...no idea why this host machine isn't going through...

Inactivated Account
  • 303
  • 2
  • 3
  • 12

7 Answers7

17

My locale settings were not properly configured when PostgreSQL was installed. Purging and reinstalling didn't help. I followed the instructions here and that did the trick for me.

Essential parts of the linked information reproduced below:

The problem showed itself in the following manner:

warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
...
are supported and installed on your system.

The first one was very easy to solve by executing:

#dpkg-reconfigure locales

...and choosing the preferred locales.

But after that PostgreSQL still refused to start. This is due to the fact that the installation process tried to create a cluster at installation time but because of the bad locales this wasn't done. So we have to redo this step by executing:

#pg_createcluster 9.3 main --start

(For the 9.3 version of PostgreSQL)

After that step PostgreSQL starts flawlessly via

#/etc/init.d/postgresql start
Paul White
  • 94,921
  • 30
  • 437
  • 687
Marko Benko
  • 186
  • 1
  • 4
6

Hopefully you've already solved this issue, but I'm running into a similar problem that seems to have a different source, and maybe my experience will help if you're still having a problem.

My problem with 9.3 on Ubuntu relates to the socket dir being a transient dir in /run. Basically, the init.d script is supposed to take care of creating the socket dir in /run/postgresql if it doesn't exist during the start action. This is always going to be the state of things after a reboot.

The problem is, however, that the init.d script will exit before executing the start action if the socket dir doesn't exist. This is because the call to pg_lsclusters will fail w/o the socket dir, which in turn prevents the start action from ever creating the socket dir.

I haven't figured out what the best solution is, but if I relocate the logic for creating the socket dir from the start action to before the call to pg_lsclusters, I am able to start the server after reboot without a problem.

Here is the portion of the start action that handles creating the socket dir:

# create socket directory
if [ -d /var/run/postgresql ]; then
  chmod 2775 /var/run/postgresql
else
  install -d -m 2775 -o postgres -g postgres /var/run/postgresql
  [ -x /sbin/restorecon ] && restorecon -R /var/run/postgresql || true
fi

I'll post an update if the root cause of this becomes clear to me, because this clearly can't be the expected behavior.

ADDENDUM:

I think the reason I was running into this problem is because I didn't have a good value configured for unix_socket_directories. On 9.2 this configuration option used to be unix_socket_directory, which I removed rather than switching to unix_socket_directories. Since I set a value for unix_socket_directories, I haven't had any issues with the server starting.

alfonx
  • 857
  • 1
  • 12
  • 22
tdg5
  • 161
  • 1
  • 3
3

I've had several problems with the sockets file, in your case /var/run/postgresql/.s.PGSQL.5432

make sure /var/run/postgresql directory exists and is writable before starting postgresql for more info see this discussion.

also, when connecting use -h flag:

psql -h localhost 

and see if that resolves it.

Joe Love
  • 163
  • 6
1

I´m new in PSQL but I solved the problem by editing start.conf I had commented the "auto" setting to manage the server manually, but it needs a value: auto, manual or disabled.

EGD.

Ernesto
  • 11
  • 1
1

On my side the start up script is incorrect. The configuration files are installed in /etc/postgresql/9.3/main but the script /usr/share/postgresql-common/init.d-functions is searching in

for c in /etc/postgresql/"$2"/*; do 

Replace this line with

for c in /etc/postgresql/"$2"/main; do
k_o_
  • 129
  • 4
1

This seems to fix the problem on Ubuntu:

Edit postgresql.conf:

unix_socket_directories='/var/run/postgresql

Now do service postgresql start

sorin
  • 1,242
  • 3
  • 11
  • 14
-2

All,

after some digging, I found (a) solution here:

http://ubuntuforums.org/showthread.php?t=869080

Which contained these instructions:

Run in terminal:

sudo mkdir -p /usr/local/pgsql/data
sudo chown -R postgres:postgres /usr/local/pgsql/
sudo su - postgres
cd /usr/lib/postgresql/9.3/bin/
./initdb -D /usr/local/pgsql/data
./postgres -D /usr/local/pgsql/data

Now my server is up and running!!!

EDIT: after a restart, the server is still not running...

Any thoughts as to why I needed to run this are appreciated!

Inactivated Account
  • 303
  • 2
  • 3
  • 12