The database detector exists, verified by \l
in psql.
The user postgres
exists verified by SELECT * FROM pg_user;
.
#1 test [solved]
I run
sudo -u postgres psql detector -c "SELECT * FROM pg_user"
but get
could not change directory to "/home/masi/det": Permission denied
while getting also the right output of the user table.
Solution in Fabricio's answer and comments i.e. restart shell; previously run the flag --password
causes the strange behavior.
#2 test [solved]
Other strange test. I run
sudo -u postgres psql detector --password -h localhost -c 'SELECT * FROM pg_user;'
which gives the following although I am the localhost.
psql: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
Solution in Fabricio's answer and comments i.e. restart shell and do not use the flag --password
with sudo.
Do not use the flag -h localhost
with sudo.
Why here is the permission denied error?