0

PostgreSQL 8.4 Fails to Start on Ubuntu 10.10

sudo /etc/init.d/postgresql start
  * Starting PostgreSQL 8.4 database server                                                                                                                                                     
  * Error: could not exec /usr/lib/postgresql/8.4/bin/pg_ctl /usr/lib/postgresql/8.4/bin/pg_ctl start -D /var/lib/postgresql/8.4/main -l /var/log/postgresql/postgresql-8.4-main.log -s -o  -c config_file="/etc/postgresql/8.4/main/postgresql.conf" :

running ldd on /usr/lib/postgresql/8.4/bin/pg_ctl

ldd /usr/lib/postgresql/8.4/bin/pg_ctl
    linux-gate.so.1 =>  (0xb77e4000)
    libpq.so.5 => /usr/lib/libpq.so.5 (0xb77a2000)
    libc.so.6 => /lib/libc.so.6 (0xb7645000)
    libssl.so.0.9.8 => /lib/libssl.so.0.9.8 (0xb75fb000)
    libcrypto.so.0.9.8 => /lib/libcrypto.so.0.9.8 (0xb74ac000)
    libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0xb73fd000)
    libcom_err.so.2 => /lib/libcom_err.so.2 (0xb73f9000)
    libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0xb73ca000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7398000)
    libldap_r-2.4.so.2 => /usr/lib/libldap_r-2.4.so.2 (0xb7351000)
    libpthread.so.0 => /lib/libpthread.so.0 (0xb7337000)
    /lib/ld-linux.so.2 (0xb77e5000)
    libdl.so.2 => /lib/libdl.so.2 (0xb7333000)
    libz.so.1 => /lib/libz.so.1 (0xb731e000)
    libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0xb72fa000)
    libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0xb72f1000)
    libkeyutils.so.1 => /lib/libkeyutils.so.1 (0xb72ed000)
    libresolv.so.2 => /lib/libresolv.so.2 (0xb72d9000)
    liblber-2.4.so.2 => /usr/lib/liblber-2.4.so.2 (0xb72cc000)
    libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0xb72b4000)
    libgnutls.so.26 => /usr/lib/libgnutls.so.26 (0xb7218000)
    libtasn1.so.3 => /usr/lib/libtasn1.so.3 (0xb7207000)
    libgcrypt.so.11 => /lib/libgcrypt.so.11 (0xb7193000)
    libgpg-error.so.0 => /lib/libgpg-error.so.0 (0xb718e000)

I have checked permissions and have given root appropriate permissions, and I am trying to run postgresql as root.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Neel Basu
  • 12,638
  • 12
  • 82
  • 146
  • Is `/usr/lib/postgresql/8.4/bin/pg_ctl` executable? – Todd Dec 17 '11 at 15:57
  • Does the postgres user have full read and write privileges on `/var/lib/postgresql/8.4/main`? –  Dec 17 '11 at 16:28
  • no. `drwx------ 11 root postgres 4.0K 2011-12-13 13:55 main` user `postgres` can't even cd to `main`. But I am running `/etc/init.d/postgresql start` as `root` – Neel Basu Dec 17 '11 at 16:36
  • I assume the server itself is running as the postgres (at least that't the usual and sane way to do it) so it will need full read and write privs on that directory. Additionally PostgreSQL will refuse to start with root privileges (IIRC) - so that might be your problem –  Dec 17 '11 at 18:08
  • 4
    Even if you run `/etc/init.d/postgresql start` as system user `root` the server will *always* be started by the system user `postgres`. PostgreSQL does not want `root` to own the process, thereby giving the server process excessive rights that are not needed and could be exploited for bad things. – Erwin Brandstetter Dec 17 '11 at 18:08
  • So should I `chown` `/var/lib/postgresql/8.4/main` to `postgres` ? or I'd make postgres a member of some group ? – Neel Basu Dec 17 '11 at 19:49
  • 2
    Yes you want to chown that dir and all descendants to be owned by user postgres, group postgres. I just did a clean package install of postgres-8.4 on ubuntu 11.04 and every entity from /var/lib/postgresql on down is [67]00 postgres:prostgres, except for a couple symlinks to /etc/ssl/ certs. `sudo chown -R postgres. /var/lib/postgresql && sudo chown -h root. /var/lib/postgresql/8.4/main/server.{key,crt}` should get you back to the permissions set up by the debian/ubuntu package install. – dbenhur Dec 18 '11 at 23:04

1 Answers1

1

PostgreSQL refuses to run as root. This is so that bugs in the back-end, plus bugs in functions written in untrusted languages, cannot be used to do arbitrary actions over the whole system. PostgreSQL must run as a relatively limited user, usually the postgres user and the start-up scripts normally enforce this.

Grant permissions to the postgres user rather than root. Then everything should work fine.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182