SoFunction
Updated on 2025-03-09

Sample code of how to reset PostgreSQL password in Mac system

PostgreSQL is an object-relational database management system (ORDBMS) with very complete features. It is an object-relational database management system based on POSTGRES, version 4.2, developed by the Department of Computer Science at the University of California. Many of the leading concepts of POSTGRES appear in commercial website databases only at a relatively late time. PostgreSQL supports most SQL standards and provides many other modern features, such as complex queries, foreign keys, triggers, views, transaction integrity, multi-version concurrency control, etc. Similarly, PostgreSQL can also be extended with many methods, such as by adding new data types, functions, operators, clustered functions, index methods, procedural languages, etc. Additionally, because of the flexibility of the license, anyone can use, modify and distribute PostgreSQL for free for any purpose.

Simply put: PostgreSQL is a free object-relational database server (ORDBMS), issued under a flexible BSD license.

PostgreSQL developers pronounce it as post-gress-Q-L.

PostgreSQL's Slogan is "the world's most advanced open source relational database".

The following is a description of how to reset PostgreSQL password through this article.

1. Modify the pg_hba.conf configuration file

sudo vi /Library/PostgreSQL/10 (write as your version)/data/pg_hba.conf

Change local from "md5" to "trust" near the end of the file:

Save and exit.

2. Check the service name of PostgreSQL

ls /Library/LaunchDaemons

Here PostgreSQL service name is:

3. Restart PostgreSQL service

Stop service:

sudo launchctl stop

Start the service:

sudo launchctl start

4. Start a Postgre session

psql -U postgres

Enter the psql session:

5. Reset password

Change password:

ALTER USER postgres WITH PASSWORD 'New Password';

The operation is completed, execute the \q command to enter and exit.

6. Restore pg_hba.conf to set to md5 and restart the service

Summarize

This is the end of this article about how to reset PostgreSQL password in Mac system. For more related content on resetting PostgreSQL password, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!