I need to run my current Postgresql 9.3 under a system user other than postgres, say admin OR I need to install Postgresql 9.3 with the default user as say admin on Ubuntu 12.04

  • Why do you need to have user other than postgres? – Abhijeet Kasurde Apr 3 '14 at 10:55
  • to maintain a policy – Ajo Augustine Apr 3 '14 at 10:55
  • Normally you would just need to create a new user, ensure that the new user can write to the postgres data directories and create a startup script to start postgres as that user. – Stefan Lasiewski Apr 4 '14 at 16:52

An installed PostgreSQL on Debian/Ubuntu is essentially:

  • a set of binaries per version that any user can potentially run to spawn and manage a new instance.
  • a datadir per instance that only its owner can use.

If the initial situation consists of 9.3 binaries being installed through Ubuntu packages, a non-postgres Unix user can spawn an instance by doing:

/usr/lib/postgresql/9.3/bin/initdb --pgdata=$HOME/pginstance [other-options]

Then start this instance with:

/usr/lib/postgresql/9.3/bin/pg_ctl -D $HOME/pginstance start

and stop it with:

/usr/lib/postgresql/9.3/bin/pg_ctl -D $HOME/pginstance stop

Obviously $HOME/pginstance can be wherever the user has the permission to write.

This instance would be unrelated to the postgres user and the scripts that come with the Ubuntu packages wouldn't know or care about it. It's entirely managed by the user who started it. It may coexist with others, but each instance must have its own port (defined in postgresql.conf inside the data directory).

  • Thanks Daniel. It worked and this was what I was looking for. – Ajo Augustine Apr 11 '14 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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