PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
Home / PostgreSQL Administration / Reset Forgotten Password For postgres User

Reset Forgotten Password For postgres User

Summary: in this tutorial, we will show you step by step how to reset forgotten password of postgres user in PostgreSQL.

For some reasons, after installing PostgreSQL, you may forget the password for the postgres user. In this case, you need to know how to reset the password.

PostgreSQL uses the  pg_hba.conf configuration file that is stored in the database data directory to control the client authentication. HBA means host-based authentication. To reset the password for the postgres user, you need to modify some parameters in this configuration file.

Step 1. Backup the pg_dba.conf file by copying it to a different location or just rename it to pg_dba_bk.conf

Step 2. Edit the pg_dba.conf file by adding the following line as the first line after the comment lines. The comment line starts with the # sign.

1
local  all   all   trust

If your PostgreSQL installation does not support local, which indicates UNIX sockets, for example, if you install PostgreSQL on Windows OS. If you use local in this case, you cannot start PostgreSQL service. In this situation, you need to use the following entry in the pg_hba.conf file:

1
host    all              postgres        127.0.0.1/32            trust

This step ensures that you can log into PostgreSQL database server without using the password.

Step 3. Restart PostgreSQL server e.g., in Linux, you use the following command:

1
sudo /etc/init.d/postgresql restart

Step 4. Connect to PostgreSQL database server and change the password of the postgres user.

1
ALTER USER postgres with password 'very_secure_password';

Step 5. Restore the pg_db.conf file and restart the server, and connect to the PostgreSQL database server with new password.

1
sudo /etc/init.d/postgresql restart

In this tutorial, we have shown you how to reset the forgotten password of the postgres user.

Previous Tutorial: PostgreSQL ALTER TABLESPACE
Next Tutorial: Deleting Tablespaces Using PostgreSQL DROP TABLESPACE Statement

PostgreSQL Quick Start

  • What is PostgreSQL?
  • Install PostgreSQL
  • Connect to Database
  • Download PostgreSQL Sample Database
  • Load Sample Database
  • Explore Server and Database Objects

PostgreSQL Fundamentals

  • PostgreSQL Select
  • PostgreSQL Order By
  • PostgreSQL Select Distinct
  • PostgreSQL Where
  • PostgreSQL LIMIT
  • PostgreSQL IN
  • PostgreSQL Between
  • PostgreSQL Like
  • PostgreSQL Inner Join
  • PostgreSQL Left Join
  • PostgreSQL Full Outer Join
  • PostgreSQL Cross Join
  • PostgreSQL Natural Join
  • PostgreSQL Group By
  • PostgreSQL Having
  • PostgreSQL Union
  • PostgreSQL Intersect
  • PostgreSQL Except
  • PostgreSQL Subquery
  • PostgreSQL Insert
  • PostgreSQL Update
  • PostgreSQL Delete

Managing Table Structure

  • PostgreSQL Data Types
  • PostgreSQL Create Table
  • PostgreSQL Alter Table
  • PostgreSQL Drop Table
  • PostgreSQL Truncate Table
  • PostgreSQL CHECK Constraint
  • PostgreSQL Not-Null Constraint
  • PostgreSQL Foreign Key
  • PostgreSQL Primary Key
  • PostgreSQL UNIQUE Constraint

PostgreSQL Views

  • Managing PostgreSQL Views
  • Creating Updatable Views
  • PostgreSQL Materialized Views
  • The WITH CHECK OPTION Views
  • PostgreSQL Recursive View

PostgreSQL Triggers

  • Introduction to Trigger
  • Creating A Trigger
  • Managing PostgreSQL Triggers

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • How To Change The Password of a PostgreSQL User
  • PostgreSQL AGE Function
  • PostgreSQL DATE_PART Function
  • PostgreSQL List Users
  • PostgreSQL NOW Function
  • PostgreSQL DATE_TRUNC Function
  • PostgreSQL TO_DATE Function: Convert String to Date
  • A Look at PostgreSQL User-defined Data Types
  • PostgreSQL Copy Database Made Easy
  • How to Get Table, Database, Indexes, Tablespace, and Value Size in PostgreSQL

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.