Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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:~#
share|improve this answer

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

share|improve this answer
    
am running two side by side intentionally –  Menelaos Perdikeas Apr 5 '13 at 16:24

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.

share|improve this answer

protected by Tom O'Connor Jul 26 '13 at 22:27

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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