Reset Postgress user password in PostgreSQL

Reset Postgress user password in PostgreSQL

Follow below steps to Reset password for Postgress user in PostgreSQL:

Also follow other topics:

Find the location of pg_hba.conf
# find / -name pg_hba*
/usr/local/pgsql/data/pg_hba.conf

# vi /usr/local/pgsql/data/pg_hba.conf

Add below parameter:
local   all             all                                     trust

Note: "trust" will allow all connection without prompting for password

Login to Postgres:
# psql -U postgres

postgres=#

Use below command to change password for postgress user:
postgres=# alter user postgres with password 'NEW_PASSWORD';

Check for database:
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

Exit from postgreSQL:
postgresl=# \q

Revert back the original configuration:
# vi /usr/local/pgsql/data/pg_hba.conf

Comment below parameter:
local   all             all                                     trust

or change as below:
local   all             all                                     password

Login to postgres:
# psql -U postgres
Password for user postgres: <New_Password>

psql (11.4)
Type "help" for help.

postgres=#

Check for database:
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

Exit from postgreSQL:
postgresl=# \q

Comments

Popular posts from this blog

How to install glibc 2.14 on RHEL 6/ RHEL 7/ CentOS 7

Export and Import users/groups and OU in AD Server 2008 using LDIFDE command.

How to Set Up and Configure latest yum repository on CentOS