How to Safely Change the Postgres User Password via PSQL

May 01, 2020

One of the most recurring questions I get from users that are starting their long and prosperous journey with PostgreSQL involves connecting with the “postgres” user.

I personally use the “postgres” user just to manage global objects (roles, tablespaces, databases) and to perform regular administration duties. Therefore, my favourite way of connecting is:

  • become the “postgres” system user (either via the root user, sudo or through SSH public key authentication)
  • connect to the local server using “psql”

However, a lot of our customers and students love graphical interfaces (especially if you come from databases with advanced tools in this area – I on the other hand am a console guy). These tools need to connect through the network and work as a standard client application.

By default, when you create a PostgreSQL cluster, password authentication for the database superuser (“postgres”) is disabled. The simplest and safest way to add a password to the “postgres” user is to connect to the local server using “psql” (see steps #1 and #2 above), then type the “\password” meta command of psql. You will be asked to enter a password and confirm it.

postgres=# \password
Enter new password:
Enter it again:

This command won’t leave any track of your password anywhere in the system or log. Simple, secure, safe.


  • use the “postgres” database user solely for administration purposes;
  • never use it for your standard/user applications.

PostgreSQL allows you to define groups, roles and users and to associate privileges to each of them in a very flexible and powerful way. Welcome to Postgres!

Share this

Relevant Blogs

pgAdmin with Kerberos and Active Directory

pgAdmin supports Kerberos authentication for user logins as well as connecting to databases. Kerberos is a popular authentication method but many people find it difficult to set up especially with...
March 21, 2023

pgAgent Setup

pgAgent is a job scheduling agent for Postgres databases, capable of running multi-step batch or shell scripts and SQL tasks on complex schedules, which may be managed using pgAdmin. pgAgent...
March 21, 2023

More Blogs