Reputation: 6150
With a freshly installed version of Postgres 9.2 via yum repository on Centos 6, how do you run postgres as a different user when it is configured to run as 'postgres:postgres' (u:g) out of the box?
Upvotes: 3
Views: 19501
Reputation: 324531
In addition to AndrewPK's explanation, I'd like to note that you can also start new PostgreSQL instances as any user by stopping and disabling the system Pg service, then using:
initdb -D /path/to/data/directory
pg_ctl start -D /path/to/data/directory
This won't auto-start the server on boot, though. For that you must integrate into your init system. On CentOS 6 a simple System V-style init script in /etc/init.d/ and a suitable symlink into /etc/rc3.d/ or /etc/rc3.d/ (depending on default runlevel) is sufficient.
If running more than one instance at a time they must be on different ports. Change the port
directive in postgresql.conf
in the datadir or set it on startup with pg_ctl -o "-p 5433" ...
. You may also need to override the unix_socket_directories
if your user doesn't have write permission to the default socket directory.
Upvotes: 4
Reputation: 6150
This is only for a fresh installation (as it pertained to my situation) as it involves blowing away the data dir.
The steps I took to resolve this issue while utilizing the packaged startup scripts for a fresh installation:
/var/lib/pgsql/9.2/data
if you've already gone through the initdb process with the postgres user:group configured as default./etc/init.d/postgresql-9.2
) to replace all instances of postgres:postgres
with NEWUSER:NEWGROUP
.postgres
in any $SU -l postgres
lines with the NEWUSER
./etc/init.d/postgres initdb
to regenerate the cluster using the new username/var/lib/pgsql/9.2/data/postgresql.conf
).I understand this might not be what other people are looking for if they have existing postgres db's and want to restart the server to run as a different user/group combo - this was not my case, and I didn't see an answer posted anywhere for a 'fresh' install utilizing the pre-packaged startup scripts.
Upvotes: 1