Default Postgres Password

Photo of author

By Vijay Singh Khatri

If you happen to be those who are familiar with databases, you must have come across the name of PostgreSQL or Postgres. PostgreSQL is a robust, open-source ORDBMS (Object-Relational Database Management System) that has acquired a great reputation among the users, the main reasons being its trustworthiness, performance, and power. PostgreSQL doesn’t have a universal “default” password or anything like that. As a user, you will receive a unique username and a password during the WS_FTP server installation process. Later, you will have to configure the PostgreSQL SA account using these credentials. Here, we will give you detailed instructions on how to set the default Postgres password. So, read on.

PostgreSQL Overview

Before we start explaining the process of setting the default Postgres password, let us know a few things about the software itself. As we have already stated, PostgreSQL is a powerful, open-source ORDBMS. It runs on Linux OS, functioning with objects as a relational component in the DBMS. As its name suggests, the software utilizes the Structured Query Language or SQL to access the data in the DB tables.

One of the best things about PostgreSQL software is that it doesn’t demand a lot of technological knowledge. It is pretty easy to learn. Here are some of the most striking features of the software:

  1. Has a high availability.
  2. Supports a locking mechanism.
  3. Remains functional with minimum maintenance.
  4. Offers MVCC support.
  5. Can run on all operating systems out there.
  6. Has a high recovery.
  7. Offers the benefit of fault tolerance.
  8. Complies with ACID.
  9. Supports audio, video, photo storage, and graphical data.
  10. It is cost-free and open-source software.

Method of Setting the Default Postgres Password

First, you have to realize that you, as a default PostgreSQL user, won’t need any password for authentication for the majority of Unix distributions. Instead, depending on the method of the installation of Postgres and the version you currently have on your PC, you would need to authenticate using either the ident or peer authentication method. Ident utilizes your operating system’s identification server that runs on the TCP port 113 for verifying your credentials.

On the contrary, the peer authentication method is utilized for local connections. This method makes sure that the signed-in username of your OS matches the username for your PostgreSQL database.

Login and connect as the default user

For the lion’s share of systems, the chances of getting the username Postgres are extremely high. Also, you would not have to enter any password to authenticate. Therefore, to set a password, you must sign in first and connect as the default user. Execute the following command to do so:

sudo -u postgres psql template1

If your attempt to connect was a success and you are capable of viewing the psql prompt, you have to navigate to the section called ‘Changing the Password’.

If for some reason, you end up facing the error where it shows that the database Postgres doesn’t exist, attempt to connect to the template1 DB instead. If the process is a success, proceed as usual with ‘Changing the Password’:

Authentication error

Sometimes, you might end up encountering an authentication error issue while trying to connect to the psql client. In such a case, you might have to alter the Postgres authentication config file. Generally, you would find the config file residing at /etc/postgresql/#.#/main/pg_hba.conf. Here, the “#.#” signifies the Postgres version you currently have installed on your computer. Use the following command and don’t forget to replace the Postgres version with the one you’re using:

sudo nano /etc/postgresql/9.3/main/pg_hba.conf

Now, the auth config file is nothing but an authentication rules list. Keep scrolling down until you find the first line that shows the Postgres user in the third column. That is if such a line is present in the first place. If required, uncomment the line by simply removing the semicolon. Or, if the line is absent, you got to add the below line to the top of the file and save the modifications:

local all postgres peer

This authentication rule acts as an instructor to Postgres to use the peer authentication method for local connections established for all DBs for the user postgres.

After you have updated the config file, repeat the steps we mentioned in the ‘Login and connect as the default user’ section. This is for connecting to the default postgres user. Once the process is successful, you can change the password.

Change the password

Now that you have established a connection to Postgres at the psql prompt, utilize the ALTER USER command for modifying the Postgres user password. After successful execution, the output will display a confirmation of ALTER ROLE as below:

postgres=# ALTER USER Postgres PASSWORD ‘myPassword’;

ALTER ROLE

Lastly, use the following command to exit the psql client:

postgres=# \q

That’s all! You have successfully set the default Postgres password for further use. Congrats!

Conclusion

As you can see, the PostgreSQL or Postgres software is a perfect choice for your database management needs. The software is free and open-source. Apart from these, it provides the users with a whole bunch of great features and facilities. The best thing about using the software is that it is incredibly easy to use. So, Postgres doesn’t demand you to have a ton of tech knowledge beforehand. Hence, you can install the software and learn more about it on the fly.

This tutorial taught you how to set the default Postgres password. Also, as we already said, most default PostgreSQL users don’t need to provide a password for authentication for the lion’s share of Unix distributions. Thus, you need to first sign in and connect as the default user. Properly follow the steps mentioned in this article to do so. In case you face any authentication error, you can easily resolve it by going through the ‘Authentication error’ section of our tutorial. After you have resolved that pesky issue, it’s time for you to change the password. Once changed, you would be capable of making use of it for further purposes. Good luck!

Leave a Comment