Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to run my second postgresql instance when linux boots. I added this command (like in postgresql documentation) in rc.local:

/usr/lib/postgresql/9.1/bin/pg_ctl start -l logfile -D /var/lib/postgresql/9.1/main2

But if I try to run pg_ctl:

cannot be run as root

Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
t, it gives me this error:

How can I specify to run that command as postgres, but actually execute it with root (because root owns it).

Or is there some better way to make second init script for postgresql?

P.S. (I'm using Ubuntu)

share|improve this question
Copied and pasted from . – Craig Ringer Jun 6 '14 at 9:28
up vote 1 down vote accepted

If you're on Ubuntu, which it seems like you are, you don't have to roll any of this yourself.

Read the docs for pg_ctlcluster, pg_createcluster, pg_lsclusters. These are part of the pg_wrapper package for Ubuntu, which provides management of multiple instances and versions built-in.

share|improve this answer
Thanks. This was very useful – Andrius Jun 6 '14 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .