Ubuntu – Postgres 9.4 running but “service status” reports it down

14.04postgresqlservices

Ubuntu 14.04.3 LTS and a new installation of Postgres 9.4 (with apt-get install postgresql-9.4, nothing fancy). Postgres was started with pg_ctl start by the postgres user.

The status command reports the service as down:

[root@box ~]# service postgresql status
9.4/main (port 5432): down

However, the server is running; I can see it's listening on 5432 and I can connect to it with psql.

[root@box ~]# netstat -a -n -p | grep 5432
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      19377/postgres
tcp        0      0 127.0.0.1:5432          127.0.0.1:45724         ESTABLISHED 20280/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45725         ESTABLISHED 20281/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45732         ESTABLISHED 20288/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45726         ESTABLISHED 20282/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45729         ESTABLISHED 20285/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45723         ESTABLISHED 20279/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45730         ESTABLISHED 20286/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45731         ESTABLISHED 20287/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45728         ESTABLISHED 20284/postgres: ice
tcp        0      0 127.0.0.1:5432          127.0.0.1:45727         ESTABLISHED 20283/postgres: ice
unix  2      [ ACC ]     STREAM     LISTENING     4295677  19377/postgres      /var/run/postgresql/.s.PGSQL.5432

psql connection:

[postgres@box~]$ psql
Password:
psql (9.4.5)

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".

Do I need to do anything else to run Postgres as a service?

Best Answer

To summarize, you added a 3rd party repository,installed a later version of a program than offered by the Ubuntu Software Center, and while you got runnable executables, you are missing some "glue" scripts to integrate them into your system. I'd recommend removing the added repository, then update the package lists:

sudo apt-get update

Then install postgresql (will get the latest offered version)

sudo apt-get install postgresql postgresql-contrib

See https://help.ubuntu.com/community/PostgreSQL

Now 14.04 will allow multiple postgresql version installations -- but I'm sure the expectation is that the version being installed will be the latest. Not sure what happens when an existing version is a later one, and not really set up in the "expected" way. Best case, it will pick it up, and run it with the assigned port(5432), and put the "new" version from the Software Center on the next port (5433). Both versions may be run simultaneously, but will need different ports. If the 9.3 installation is given the 5432 port already in use by 9.4, and the 9.4 is just ignored, you at least have a 9.3 template of expected locations to move/add the 9.4. Things like the /etc/rc2.d/S19postgresql link to /etc/init.d/postgresql and the /usr/share/postgresql/9.4

Then track down the conf file assigning the ports and ensure the 9.4 version is on the default 5432 (if that's what you want).

Related Question