Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql cannot change to root with -u shortcut

Recently updated from Postgresql 9.1 to 9.3.

Everything works fine, but I noticed now when I type in:

sudo -u postgres psql

I am getting hit with a permission denied error for changing dir to root.

"Could not change directory to /home/root.

However, when I use:

sudo su - postgres 
psql

It accesses it fine. How can I fix this?

like image 446
Johnathan Avatar asked Mar 03 '16 20:03

Johnathan


2 Answers

change directory to someplace that postgres has access to:

cd /tmp
sudo -u postgres psql
like image 81
Kirk Roybal Avatar answered Sep 22 '22 16:09

Kirk Roybal


Try this:

sudo -i -u postgres psql

This accomplishes (almost) the same thing as your

sudo su - postgres 

The - in the above indicates that you want to use the postgres account's environment. If you remove the -, it will fail similarly to sudo -u

The -i indicates that you want to run the postgres account's login shell (hence cding to their home directory).

like image 34
DylanYoung Avatar answered Sep 19 '22 16:09

DylanYoung