FATAL: password authentication failed for user "postgres" pgadmin4 - postgresql

I'm using postgresql 12 with pgadmin4 on ubuntu 20.04. I'm having an issue with creating a new server. I don't remember specifying any password during installation but now i don't know what the password is and whatever i try to put it just gives a password error saying authentication failed. error message

You can reset the password or connect to PostgreSQL without password by modifying pgconf.hba file and then try to connect.
host all all 0.0.0.0/0 trust

Create a user and password with (don't miss the semicolon):
CREATE USER username WITH PASSWORD 'your password';
After this, try authenticating your USER in pgAdmin4
For more refer to this link: https://www.postgresql.org/docs/current/sql-createuser.html

I don't know how should I express my thanks to #1337.ishaan and #a_horse_with_no_name without which I couldn't have logged into Postgres through pgadmin4. But a small edit to that:
First we have to get inside postgres through using
sudo -u postgres psql postgres
Enter password for user postgres
Now the terminal will be like this:
postgres=#
Now enter the given line after postgres=#
CREATE USER username WITH PASSWORD 'your password';
(put your password inside quotes('') and don't forget semicolon(;)

Related

pgAdmin4 can not connect to postgres server though the password is correct?

I am newbie with pgAdmin4 and here is my problem.
I setup postgresql in ubuntu, everything seems ok, I change password for the account postgres by this command sudo passwd postgres and note it very carefully.
Then, I tried to connect to postgresql by pgAdmin4 follow this tutorial.
https://www.youtube.com/watch?v=XRdl0P4V-PU
Name is localhost
Hostname is localhost
Port is 5432
Maintenance database is postgres
Username is postgres
And password is the password I set above.
But they said to me that Unable to connect to server: FATAL: password authentication failed for user "postgres"
I tried to change the password, but still the same error. Seems something wrong ?
Could you please give me some ideas ? Thank you very much.
It seems like you only changed the password at the OS level. Basically, for the Ubuntu user postgres, you changed the password with sudo passwd postgres.
In order to change the password for the postgres user for the database, you need to log into the database and change the postgres user's password with ALTER ROLE postgres PASSWORD '<your password>';
In order to accomplish this, you will need to change your pg_hba.conf temporarily, allowing the postgres user to log in without a password (either set to trust or peer authentication method, change the password, and the switch back to password or other authentication method). After changing pg_hba.conf you will either want to issue a kill HUP to the parent postgres process (check the top-most process in your ps -ef | grep postgres output), or simply restart postgres with systemctl restart postgresql<your_postgres_version>

Change authentication method for postgres superuser

I am using psql to connect to a PostgreSQL database on Debian 10. I am trying to connect as the postgres user, to the default postgres database. By default, this is using the 'peer' authentication method, which does not require a password.
If I log in using the 'peer' authentication and set a password using the following command:
ALTER USER postgres WITH PASSWORD 'myPassword';
The query executes successfully, however when I edit pg_hba.conf to change the authentication method from:
local all postgres peer
to:
local all postgres scram-sha-256
and restart the server, I get the following error:
~$ sudo -u postgres psql postgres
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
~$
Does anyone know how to do this?
To change the authentication method in PostgreSQL:
Open a terminal window
Change into the postgres bin directory
Example: cd /usr/local/pgsql/bin
Note: Depending on your install environment the path to the bin directory may vary.
Type su – postgres and press Enter. This will change the logged in to the postgres user.
From the bin directory type ./psql
Type:
ALTER USER your_username password 'new_password'; and press Enter. ALTER ROLE should be displayed.
Type \q and press Enter
Open /path_to_data_directory/pg_hba.conf
Example: /etc/postgresql/11/main/pg_hba.conf
Modify the line at the bottom of the config file to resemble one of these examples.
Note: You will probably only have to change the word trust to md5. The line or lines should already exist.
host all postgres peer
host all your_username your.ip your.subnet md5
Save the changes
Restart PostgreSQL service with systemctl restart postgresql.service
Before you assign the password, you probably need to set the password_encryption to "scram-sha-256". Otherwise, you stored the password in the md5 format, and such a password cannot be used to login when pg_hba.conf calls for "scram-sha-256".
The default setting of password_encryption is still md5. It will change to be "scram-sha-256" in v14.
The error message sent to the unauthenticated user is intentionally vague. The error message in the server log file will probably say DETAIL: User "postgres" does not have a valid SCRAM secret. (If it does not, then ignore this answer, and edit your question to tell us what it does say)
You need to 1st in the shell change to be the "postgres" user which you're not doing correctly above:
sudo su - postgres
Then you can do the following as peer auth:
psql -d postgres -U postgres
Also recommend you set a pw for postgres sql user:
\password postgres
& change the authentication method to "md5", not "peer".

How to change the postgres database user role password from 'admin' to 'mypassword'?

I was trying to change PostgreSQL database user role password from 'admin' to 'mypassword' in odoo-10. I've tried ALTER ROLE "odoo" WITH PASSWORD 'mypassword'; in postgres and restarted postgresql service.
But it is not working.
When i start odoo server again it shows error like FATAL: password authentication failed for user "odoo" and It is working fine if I change this password back to 'admin'. I've tried of making corresponding changes in both "/etc/odoo.cof" and "/odoo/tools/config.py" and it does'nt solve my issue too.
Is there anything else that i missed to try ? Hope you'll help me to fix this issue.
Thanks in advance!!
Try this:
$sudo -u postgres psql database_name
$ALTER USER postgres with encrypted password 'ur password';
Try this single line:
sudo -u postgres psql -c "ALTER USER <user> WITH ENCRYPTED PASSWORD '<password>';"
replace <user> and <password> with corresponding data.

Why doesn't Postgres ask for password for user postgres?

From what I read in my pg_hba.conf, I'm inferring that, to make sure I'm prompted for a password for the postgres user, I should edit pg_hba.conf's first two entries' method from the current 'peer' to either 'password' or 'md5', but I don't want to break things if that's wrong. Am I on the right track? Or missing something obvious?
Anyway, more details-
After installing postgres 9.4 on debian, I changed the postgres user's password by doing this-
postgres=# \password postgres
...and entering in the new password twice.
Then I exited postgres (Ctrl+D), then restarted the server from bash-
sudo service postgresql restart
When I log back into postgres (sudo -u postgres psql), I'm not prompted for the new password. I just get-
psql (9.4.9)
Type "help" for help
postgres=#
Also, the .pgpass file is in my home directory, but it's empty. Finally, first two lines of pg_hba.conf are
local all postgres [blank] peer
local all all [blank] peer
Setting a password only provides the password for authentication methods that require it. It does not add the requirement that the password be specified for login.
Whether a password is required is controlled by pg_hba.conf. The peer auth mode does not require a password, it allows a user to log in if their unix username is the same as the postgres username they're trying to connect as.
Try md5 auth if you want password authentication.

Postgresql: How to check username and (forgotten) password on a Mac?

Hi I've tried looking around for an answer but don't know how to access my local machine's postgresql username and password. I'm a big noob when it comes to the command line and bash and etc, so please help. Can someone help in helping me find out my username and password for postgres on a Mac?
Edmunds-MacBook-Pro:postgres edmundmai$ psql -d db -U postgres
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
I don't know of a way to recover a password from PostgreSQL. However, if you add local all all trust to your pg_hba.conf file, it will allow you to log into the cluster without a password from your local machine. Once you've made the change, restart the server to get it to take effect, and then you can log in and change your password. Once you're done, be sure to remove this line from your pg_hba.conf and restart the server, as this isn't particularly secure.