Where PostgreSQL stores your login credentials

PostgreSQL stores usernames and passwords in two places: the server itself keeps the actual credentials, and your local machine may have a .pgpass file that caches them for convenience. If you set up PostgreSQL yourself, you created the initial username and password during installation. If someone else set it up, or if you inherited a database, you will need to either recover the credentials or reset them — which are two different tasks.

The username is almost always postgres (the default superuser account) unless you created additional users. The password is what you chose during setup, or what the person who set it up chose. If you have forgotten it, you cannot retrieve it from the server — PostgreSQL does not store passwords in a readable form — but you can reset it if you have access to the machine where PostgreSQL is running.

Key Takeaways

  • The default PostgreSQL username is postgres, and the password is whatever you entered during installation or what an administrator set.
  • PostgreSQL does not display stored passwords, but you can reset the password for any user if you can log into the server machine as root or the postgres system user.
  • A .pgpass file on your local machine stores cached credentials in plain text, so check there first if you are trying to find a password you have used before.
  • If PostgreSQL is running on a remote server, you will need SSH access to that machine to reset a forgotten password.
  • The pg_hba.conf file controls how PostgreSQL authenticates users, and checking it tells you whether a password is even required for your connection.

Finding cached credentials in .pgpass

If you have connected to this PostgreSQL database before from your current machine, your credentials may be stored in a .pgpass file. This file lives in your home directory and contains hostname, port, database name, username, and password in plain text — one entry per line, separated by colons.

On Linux or macOS, open a terminal and type:

cat ~/.pgpass

On Windows, the file is usually at C:\Users\[YourUsername]\AppData\Roaming\postgresql\pgpass.conf. Open it with Notepad or any text editor. If the file does not exist, you have never cached credentials on this machine, so you will need to recover or reset the password through the server.

If you do find an entry, the format is hostname:port:database:username:password. The port is usually 5432. Copy the password and test it by connecting to the database using a PostgreSQL client like psql or a graphical tool such as pgAdmin.

Resetting a forgotten password on the local machine

If PostgreSQL is running on your own computer and you have forgotten the password, you can reset it without knowing the old one. The process depends on your operating system and how PostgreSQL is configured.

On Linux: Stop the PostgreSQL service, edit the pg_hba.conf file to allow passwordless local connections, restart the service, connect as the postgres user, and change the password. Then revert the pg_hba.conf file. This requires root or sudo access.

On macOS: The process is similar. Stop PostgreSQL (usually via Homebrew: brew services stop postgresql), edit pg_hba.conf to allow local connections without a password, restart, connect, reset the password, and revert the config file.

On Windows: Stop the PostgreSQL service via Services (services.msc), edit pg_hba.conf in the PostgreSQL data directory, restart the service, open Command Prompt as Administrator, and use psql to connect and reset the password.

Finding pg_hba.conf to understand authentication rules

The pg_hba.conf file tells PostgreSQL how to authenticate users. If you are unsure whether a password is even required, this file will tell you. It also shows you which users can connect from which machines and what authentication method is used.

The file location varies by installation. Common paths are:

  • Linux: /etc/postgresql/[version]/main/pg_hba.conf or /var/lib/pgsql/data/pg_hba.conf
  • macOS (Homebrew): /usr/local/var/postgres/pg_hba.conf
  • Windows: C:\Program Files\PostgreSQL\[version]\data\pg_hba.conf

Open the file with a text editor. Look for lines that start with local or host. The last column shows the authentication method — trust means no password required, md5 or scram-sha-256 means a password is required. If you see trust for local connections, you can connect without a password by typing psql -U postgres in a terminal on that machine.

Resetting the password if you have server access

If you can log into the machine where PostgreSQL is running (either locally or via SSH), you can reset any user's password. First, connect to PostgreSQL as a superuser. If the postgres user has no password set, you may be able to connect directly:

sudo -u postgres psql

Once you are in the psql prompt (you will see postgres=#), reset the password for any user with the ALTER USER command:

ALTER USER postgres WITH PASSWORD 'newpassword';

Replace postgres with the actual username and newpassword with your new password. Then type \q to exit. The password is now changed. Test it by disconnecting and reconnecting with the new password.

Finding credentials on a remote server

If PostgreSQL is running on a server you do not have direct access to, you will need to contact the server administrator or the person who set up the database. They can reset the password for you, or they can tell you what the username and password are.

If you have SSH access to the remote server, you can follow the same steps as the local machine: log in via SSH, connect to PostgreSQL as a superuser, and reset the password. This requires that you have SSH credentials and that the PostgreSQL service is running on that machine.

If you do not have SSH access and the administrator is unavailable, you have no way to recover the credentials. This is by design — PostgreSQL does not allow password recovery without server-level access, which is a security feature.

Using pgAdmin to find or reset credentials

pgAdmin is a graphical tool for managing PostgreSQL databases. If you have already connected to a server through pgAdmin, it may have stored the credentials. Open pgAdmin, look at the Servers list on the left, right-click on the server you want, and select Properties. The Connection tab shows the hostname, port, and username. The password is not displayed for security reasons, but you can change it here.

To reset a password in pgAdmin, right-click the server, select Properties, go to the Connection tab, and enter a new password. Then click Save. pgAdmin will use the new password for future connections. This only works if you are already logged in to pgAdmin with an account that has permission to change passwords on that server.

Frequently Asked Questions

Can I see the password for a PostgreSQL user that is already set?

No. PostgreSQL stores passwords as hashes, not as readable text. Even the database administrator cannot see the original password. If you need to know the password, you must reset it to a new one that you choose.

What is the default PostgreSQL username and password?

The default username is postgres. There is no default password — you set one during installation. If you did not set one, the account may allow passwordless local connections depending on the pg_hba.conf settings.

How do I reset the postgres password if I have no access to the server?

You cannot reset it without access to the machine where PostgreSQL is running. Contact your hosting provider, system administrator, or the person who set up the database. They can reset it for you or provide you with the credentials.

Where is the PostgreSQL password stored on my computer?

If you have saved it, it is in the .pgpass file in your home directory (Linux/macOS) or in AppData\Roaming\postgresql\pgpass.conf (Windows). The actual server password is stored in the PostgreSQL data directory on the server machine, not on your local computer.

Can I connect to PostgreSQL without a password?

Yes, if the pg_hba.conf file is set to trust authentication for your connection type. This is common for local connections on development machines. Check the pg_hba.conf file to see whether a password is required for your specific connection.