PostgreSQL: Can't log into Postgres - sudo broken?
Asked Answered
E

3

13

Hey so after I ran into somes issues I decided to uninstall Postgres and re-install it (re install a newer version btw).

I'm trying to access postgres to create a new db for my Rails app so I run su postgresor su _postgres then I am asked a password but nothing that I enter works.

So I tried sudo -u postgres psql and got

sudo: unknown user: postgres
sudo: unable to initialize policy plugin

I tried also to disable SIP (see: here)

but it didn't work either. same results.

I don't know what to do. Any idea ? I am using Mac OS High Sierra 10.13.6.

Enarthrosis answered 22/9, 2018 at 17:22 Comment(6)
What about sudo -u _postgres psql?Philbo
thank you @GordonDavisson the password works ! however, I then get: psql: FATAL: role "_postgres" does not exist. What's wrong ?Enarthrosis
Try: psql -u postgresCtn
@Ctn thank you for you help; it says psql: invalid option -- uEnarthrosis
Oops, that should have been a capital U: psql -U postgresCtn
@Ctn now I get psql: FATAL: role "postgres" does not existEnarthrosis
E
35

Thanks to @gordon Davidson and @wildplasser 's help, I found the solution:

sudo -u myusername psql postgres

Enarthrosis answered 24/9, 2018 at 6:45 Comment(4)
alternatively: psql -U myusername -d postgres without the need for sudoNich
I am having the same error, Could you please help me what i am suppose to do right? sudo: unknown user: postgres sudo: unable to initialize policy pluginBewilder
@MushahidKhan did you run the above mentionned command to try and solve your issue ?Enarthrosis
@JulesCorb, obvious, i tried , but not table to log in, working on it, hopefully will get some solutionBewilder
U
2

I had this same challenge when trying to access a PostgreSQL database.

When I run the command below:

sudo -u postgres psql

I get the error below:

sudo: unknown user: postgres
sudo: unable to initialize policy plugin

The issue was that I did not have the PostgreSQL database server installed on the server. The server only had a MySQL database server set up on it.

That's all.

I hope this helps

Ursuline answered 18/3, 2021 at 15:18 Comment(0)
H
0

From your EC2 node issue the following command to test if database is reachable.

/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h AWS-RDS-POSTGRES-ENDPOINT
Helicoid answered 7/1, 2021 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.