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.
If you are using debian, you can tell the init script, which version(s) you want to manage:
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
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.