Nu-B here

Started by Amn Ojee Uwover 2 years ago6 messagesgeneral
Jump to latest
#1Amn Ojee Uw
amnojeeuw@gmail.com

After this command 'sudo -u postgres psql'
I get this message :
*could not change directory to "/home/my_account": Permission denied**
**psql (12.15 (Debian 12.15-1.pgdg120+1))**
**Type "help" for help.*

I tried using help, but to no avail.
What am I doing wrong?

Thanks in advance!

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amn Ojee Uw (#1)
Re: Nu-B here

Amn Ojee Uw <amnojeeuw@gmail.com> writes:

After this command 'sudo -u postgres psql'
I get this message :
*could not change directory to "/home/my_account": Permission denied**
**psql (12.15 (Debian 12.15-1.pgdg120+1))**
**Type "help" for help.*

This is normal if you launch psql via "sudo -u postgres" in a directory
that the postgres user doesn't have permissions to read/chdir to.
psql will still start, but its working directory will not be what
you'd expect, so commands that involve local filesystem access might
misbehave.

We have a fix for this error report in the upcoming v16, but psql commands
that involve local filesystem access will still not act very nicely if
psql can't read your directory.

regards, tom lane

#3Maciek Sakrejda
m.sakrejda@gmail.com
In reply to: Amn Ojee Uw (#1)
Re: Nu-B here

On Wed, Jul 19, 2023, 17:36 Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

After this command 'sudo -u postgres psql'
I get this message :
*could not change directory to "/home/my_account": Permission denied*
*psql (12.15 (Debian 12.15-1.pgdg120+1))*
*Type "help" for help.*

I tried using help, but to no avail.
What am I doing wrong?

It looks like you're hitting a non-fatal error at some point during psql
startup when you're running as the "postgres" user. It seems to be a
permissions issue. Do you still get the error if you run

sudo -u postgres psql --no-psqlrc

?

You may also want to create a Postgres user (possibly a superuser) matching
your operating system user if you have not already done so to avoid having
to deal with sudo for connecting.

Thanks
Maciek

#4Alban Hertroys
haramrae@gmail.com
In reply to: Amn Ojee Uw (#1)
Re: Nu-B here

On 20 Jul 2023, at 02:36, Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

After this command 'sudo -u postgres psql'
I get this message :
could not change directory to "/home/my_account": Permission denied

What’s the reason that you’re using the OS user postgres?

If you’re simply trying to connect to the database named postgres as database user postgres, you can instead use the command 'psql -U postgres postgres’.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.

#5Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Alban Hertroys (#4)
Re: Nu-B here

On 7/19/23 23:32, Alban Hertroys wrote:

On 20 Jul 2023, at 02:36, Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

After this command 'sudo -u postgres psql'
I get this message :
could not change directory to "/home/my_account": Permission denied

What’s the reason that you’re using the OS user postgres?

Because the Debian/Ubuntu packaging sets up pg_hba.conf to use peer auth
for local connections and the only database user created is postgres.

See:

https://ubuntu.com/server/docs/databases-postgresql

for more information.

If you’re simply trying to connect to the database named postgres as database user postgres, you can instead use the command 'psql -U postgres postgres’.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.

--
Adrian Klaver
adrian.klaver@aklaver.com

#6Amn Ojee Uw
amnojeeuw@gmail.com
In reply to: Adrian Klaver (#5)
Re: Nu-B here

Please note the following :
/psql (12.15 (Debian 12.15-1.pgdg120+1
/Thanks in advance
//

Show quoted text

On 7/20/23 10:41 a.m., Adrian Klaver wrote:

On 7/19/23 23:32, Alban Hertroys wrote:

On 20 Jul 2023, at 02:36, Amn Ojee Uw <amnojeeuw@gmail.com> wrote:

After this command 'sudo -u postgres psql'
I get this message :
could not change directory to "/home/my_account": Permission denied

What’s the reason that you’re using the OS user postgres?

Because the Debian/Ubuntu packaging sets up pg_hba.conf to use peer
auth for local connections and the only database user created is
postgres.

See:

https://ubuntu.com/server/docs/databases-postgresql

for more information.

If you’re simply trying to connect to the database named postgres as
database user postgres, you can instead use the command 'psql -U
postgres postgres’.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.