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

9
  • Do you actually have a /var/run/postgresql directory? At one stage after succesful installation that folder was missing on my machine. What does the config say about which directory it should be using? Oct 2, 2013 at 20:55
  • @Colin'tHart I do have that directory...however there is nothing in it...in the VM's, there is a file created called 9.3-main.pid Where would I find that config information?
    – DPSSpatial
    Oct 2, 2013 at 21:01
  • postgresql.conf in the config directory, which according to above, is /etc/postgresql/9.3/main. You should also look in the log files, probably in /var/log/postgresql. Oct 2, 2013 at 21:10
  • @Colin'tHart The log file is empty...The config file - and I think this is what you're after - says # If external_pid_file is not explicitly set, no extra PID file is written. external_pid_file = '/var/run/postgresql/9.3-main.pid'
    – DPSSpatial
    Oct 2, 2013 at 21:16
  • Is there a socket file in that directory, or is it really completely empty? Oct 2, 2013 at 21:37

7 Answers 7

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
2
  • 2
    Saved my life. It's really sucky that purging and reinstalling doesn't help even when the locale is rectified. This wasted 2hrs of my life :(
    – Escher
    Apr 10, 2016 at 17:15
  • In case pg_createcluster tells you that the cluster already exists you need to drop it first (this will erase any data in it, so make sure you have a backup): pg_dropcluster 9.3 main. Dec 2, 2016 at 11:16
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.

4
  • thank you @tdg5!!! I haven't resolved this, but I think it comes down to several bad installs on my machine. Installing from the PostgreSQL Apt Repository on a fresh install of ubuntu solved my problems...
    – DPSSpatial
    Mar 28, 2014 at 14:51
  • 3
    @mapBaker - I updated my response to include the root cause of the PG 9.3 startup problem in my particular situation. Perhaps it will be helpful for you as well.
    – tdg5
    Apr 4, 2014 at 16:09
  • 1
    My PG9.3 did not start after reboot. Adding the line "unix_socket_directories='/var/run/postgresql'" to 9.3's postgresql.conf solved it. Thanks
    – alfonx
    Jun 13, 2014 at 5:15
  • Thanks! Been working on this for a while, glad to find this nugget! Jan 12, 2015 at 22:01
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.

1

This seems to fix the problem on Ubuntu:

Edit postgresql.conf:

unix_socket_directories='/var/run/postgresql

Now do service postgresql start

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.

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

4
  • Are you sure it is 9.3 running? The version number seems suspicious...
    – dezso
    Oct 4, 2013 at 21:49
  • @dezso sorry forgot to change the version # when I pasted in those commands...this is all at v9.3...
    – DPSSpatial
    Oct 4, 2013 at 22:39
  • You might need to specify the port. The default port is being used by your old installation of postgres. Your new installation is using port 5433 most likely, but this is something you can check for sure by reading the postgresql config file: /etc/postgresql/9.3/main/postgresql.conf
    – user35581
    Jul 7, 2014 at 15:26
  • 1
    This may be an workaround but clearly not a good solution. This one like is fixing the problem dba.stackexchange.com/a/91511/8099
    – sorin
    Feb 9, 2015 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.