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
The default system account in PostgreSQL is
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=# ALTER USER postgres PASSWORD 'password';
password is the password you wish to set for the
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:
- Locate the auth mode entry and change it to
- Restart the PostgreSQL Server.
- Connect to PostgreSQL Shell
psql -u postgres.
- Run the command shown below set a new password for the
ALTER USER postgres PASSWORD 'password';
- Exit the PostgreSQL Shell
pg_hba.confand restore the auth mode to
- Restart the PostgreSQL Server
- Login to the server with the
postgresuser and the new set password.
pg_hba.conffile 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.