6

I have two postgresql installations:

$ sudo /etc/init.d/postgresql status 9.1/main (port 5432): online 9.2/main (port 5433): online 

I was used to restarting the postgres database doing a:

$ sudo /etc/init.d/postgresql restart 

... but now that there's two of them, how to choose which one to restart?

UPDATE: following the answer I received from Micah Yoder I did a:

/usr/lib/postgresql/9.2/bin/pg_ctl -D /var/lib/postgresql/9.2/main restart 

which was met with "could not open PID file /var/lib/postgresql/9.2/main/main/postmaster.pid permission denied". When I tried to run pg_ctl in a sudo-i session I was met with:

pg_ctl: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process. 

How am I supposed to run the pg_ctl program? Also I don't see why I have to indicate the data file for a restart. Doesn't the process know which data file it is using?

UPDATE 2 Finally I gave up on the pg_ctl and did a:

sudo /etc/init.d/postgresql restart 9.2 

.. as per the accepted answer.

3 Answers 3

6

If you are using debian, you can tell the init script, which version(s) you want to manage:

pg01:~# /etc/init.d/postgresql Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ..] pg01:~# 
2
  • Is this still true on 9.4? I see the version option, but that argument doesn't seem to get passed through to the script which does the heavy lifting (/usr/share/postgresql-common/init.d-functions) Commented Sep 22, 2015 at 3:02
  • 1
    Have filed: bugs.launchpad.net/ubuntu/+source/postgresql-common/+bug/… Commented Sep 22, 2015 at 3:14
2

First, are you running two side by side intentionally or did you just install 9.2 from a different package and it did not remove 9.1? (Postgres packages are now often set up that way.) If you've migrated, then 9.1 should be removed.

If you need both, then each should have its own pg_ctl executable which can do the same thing as the normal initscript. Run it as the 'postgres' user. See .../path/bin/pg_ctl --help

1
  • am running two side by side intentionally Commented Apr 5, 2013 at 16:24
0

You are probably having two postgresql instances running using two different configurations files named postgresql.conf stored at two places.

You should check /etc/sysconfig/pgsql/postgresql config file to verify which pgsql it is using for /etc/init.d/postgresql. It must be having location of pgsql directory where postgresql.conf file will be stored. In this conf file, there will be port number for that specific pgsql.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.