1. Home
  2. Cloud & Servers
  3. Managed Cloud Application Hosting
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Multi-Cloud Managed Services
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Multi-Cloud Professional Services
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed AWS Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Azure Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Buzinessware Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Digital Ocean
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Google Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Hosting & Servers
  3. Dedicated Server
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Hosting & Servers
  3. Virtual Private Server [VPS]
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Cloud Application Hosting
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Multi-Cloud Managed Services
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Multi-Cloud Professional Services
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed AWS Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Azure Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Buzinessware Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Digital Ocean
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Cloud & Servers
  3. Managed Google Cloud
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Hosting & Servers
  3. Dedicated Server
  4. Change a Password for PostgreSQL on Linux via Command Line
  1. Home
  2. Hosting & Servers
  3. Virtual Private Server [VPS]
  4. Change a Password for PostgreSQL on Linux via Command Line

Change a Password for PostgreSQL on Linux via Command Line

PostgreSQL supports many client authentication methods, but in this case we’re only going to concern ourselves with two: password and md5.

Note: The default authentication method for PostgreSQL is ident. If you’d like to change the PostgreSQL authentication method from ident to md5, then visit the linked tutorial!

  • Pre-Flight Check
  • These instructions are intended specifically for changing a password in PostgreSQL.
  • I’ll be working from a iaas Core Managed CentOS 7 server, and I’ll be logged in as root.
  • PostgreSQL is installed per our tutorial on: How to Install and Connect to PostgreSQL on CentOS 7.


Step #1: Switch to the PostgreSQL User: postgres
If you’re working from a default PostgreSQL installation, then PostgreSQL will be configured with the user postgres.

Since we’re logged in as root, and we’re assuming that root doesn’t have a user for PostgreSQL, switch to the default PostgreSQL user: postgres:

su – postgres

… then attempt a connection to PostgreSQL:

psql

… enter your password at the prompt:

Password:

… the correct, valid response will be similar to:

psql (9.3.9)
Type “help” for help.

postgres=#

Step #2: Add/Change the Password for the PostgreSQL User: postgres
Use the following command to change the password for your current user, which is now postgres:

\password

Enter your new password, and then enter it again to confirm it:

Enter new password:
Enter it again:

Now quit the PostgreSQL interface:

\q

Bonus Information!
You can do all of step one in exactly one command:

su -c "psql" - postgres

Updated on November 26, 2022

Was this article helpful?