Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The installation of postgresql server in Ubuntu 12.04 fails. Its seem to be due to incomplete configuration of postgresql-common package. I purged all packages related to postgresql, tried to reinstall postgresql-common package only. Still error was occuring.

The error is:

$ sudo apt-get install postgresql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  postgresql-common
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/96.5 kB of archives.
After this operation, 442 kB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package postgresql-common.
(Reading database ... 176855 files and directories currently installed.)
Unpacking postgresql-common (from .../postgresql-common_129ubuntu1_all.deb) ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Processing triggers for ureadahead ...
Processing triggers for man-db ...
Setting up postgresql-common (129ubuntu1) ...
adduser: The user `postgres' does not exist.
dpkg: error processing postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 postgresql-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

Any idea how to overcome/solve this?

N.B:

  1. I updated and tried again, same error is occuring.
  2. I purged the postgresql related packages and tried to install both postgresql-8.4 and postgresql-9.1, in both cases, it failed due to the dependency to postgresql-common package.
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

The problem was that postgres user was not getting created.(Looks like an error with the package configuration scripts, not sure though) I then created the user manually using:

sudo useradd -r -s /bin/false postgres

The above command is to create a user, without home directory.(Courtesy)

After that I tried to install again, and it succeeded, without any problems.

N.B:
Some guys at the Ubuntu IRC channel helped me with the solution.

Update:

After restart postgresql server was not accessible, so tried to restart postgresql server, and got the following error:

$ sudo service postgresql restart
[sudo] password for username: 
 * Restarting PostgreSQL 8.4 database server                                     
 * The PostgreSQL server failed to start. Please check the log output:
2014-04-03 09:54:22 IST FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
[fail]

Solved it by editing the postgresql.conf file. We have to look for the line that begins with that begins unix_socket_directory and change it to read as the following:

unix_socket_directory='/tmp'

Now start the postgresql server using:

sudo service postgresql start

The problem was because

the default directory for lock files in Ubuntu was changed to /var/run/postgresql, which is not world-writable. However, simply changing write permissions on the directory does not work; they are reset when the default init script runs.

Courtesy: http://eclecticquill.com/2013/02/26/postgresql-fails-to-start-on-ubuntu-12-10/

Got more info from this link:

But if you are trying a to run an instance of the PostgreSQL server owned by your local user, you need to ensure that the unix socket directory is writable by the user that owns the PostgreSQL server process. Try:

unix_socket_directory='/tmp'

In short:

We had to do that because we created the postgres user manually.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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