PostgreSQL Default Username and Password

In this brief post, we will cover some methods you can use to configure a password for the default user account in PostgreSQL Server.

PostgreSQL Default Username and Password

PostgreSQL, commonly known as Postgres is one of the most popular free and open source relational database management systems. PostgreSQL adopts a large scale features of ANSI SQL including but not limited to foreign keys, triggers, views, transactional integrity and more.

If you are coming from MySQL, you may be familiar with the default username and password configured in MySQL Server. Therefore, you may wonder what is the default username and password in PostgreSQL.

Unfortunately, PostgreSQL does not offer a default username and password. In most cases, you need to configure the auth credentials during the installation process. If you used an unattended installer, you may skip on credential configuration.

Method 1 - Use psql to Set the Password for the postrges User.

The default system account in PostgreSQL is postgres.

You can check if the postgres user exists in the system by running the command:

cat /etc/passwd | grep postgres

The command above should show the postgres user, including the shell.

To set the password for the postgres user, run the command below to login to the PostgreSQL shell.

sudo -i -u postgres

Finally, run the command belw to set a password for the postgres user:

postgres=# ALTER USER postgres PASSWORD 'password';

Where password is the password you wish to set for the postgres user.

NOTE: This method is applicable if you are running your PostgreSQL server as the postgres user.

Method 2 - Edit PostgreSQL Configuration File

Another method you can use is editing the PostgreSQL configuration file. If you do not know the default password, you can treat it as forgotten and allow all users to login into the server without a password.

This method works by temporarily disabling the authentication features. You can then login to the server, reset the password and restore the security.

Follow the steps as provided below:

  • Edit pg_hba.conf.
  • Locate the auth mode entry and change it to trust from md5.
  • Restart the PostgreSQL Server.
  • Connect to PostgreSQL Shell psql -u postgres.
  • Run the command shown below set a new password for the popstgres user.
  • ALTER USER postgres PASSWORD 'password';
  • Exit the PostgreSQL Shell
  • Edit pg_hba.conf and restore the auth mode to md5.
  • Restart the PostgreSQL Server
  • Login to the server with the postgres user and the new set password.
NOTE: The location of the pg_hba.conf file may differ depending on the host system and the installation method.

However, my default, you can find this file in %PROGRAMFILES%\PostgreSQL\<installed_version>\data where the installed_version is the actual version number of installed PostgreSQL instance.

On Linux, you can find this file in the etc directory as:


You can learn more about the PostgreSQL pg_hba.conf file in the documentation link below.


This tutorial covers two most basic methods you can use to 'determine` or restore your default username and password in your PostgreSQL Server.

We hope this article helped you, leave us a comment down below and share.

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.