Linux – Postgres /root”: Permission denied

amazon ec2linuxpostgresqlUbuntuunix

why on ubuntu 14.10 every time that i try to start the postgres on:

sudo -p 'sudo password: ' -u postgres /usr/lib/postgresql/9.4/bin/initdb -D /mnt/postgresql/9.4/data

show this:

could not change directory to "/root": Permission denied The files
belonging to this database system will be owned by user "postgres".
This user must also own the server process.

initdb: invalid locale settings; check LANG and LC_* environment
variables

Best Answer

There are three parts in the output:

  1. could not change directory to "/root": Permission denied: your 'sudo' succeeds but your postgres user fails to access the home of root. You may check for the setting of homedirectory for postgres in /etc/passwd.

  2. The files belonging to this database system will be owned by user "postgres". This user must also own the server process. : This is the normal permissions reminder from initdb. So you know initdb started regardles of failed directory change.

  3. initdb: invalid locale settings; check LANG and LC_* environment variables: here initdb fails for real due to missing locale settings.

I think You need to check your sudo configuration and make sure your postgres user has a proper environment before calling initdb.