Where PostgreSQL stores your login credentials
Your PostgreSQL username and password live in three places depending on how you set up the database: the initial installation record (if you wrote it down), your system's password manager or configuration file, or the PostgreSQL server itself if you have administrator access.
The most common scenario is that you created the username and password during installation and either saved them somewhere or forgot them. If you installed PostgreSQL yourself on your own computer or server, you have options to recover or reset them. If someone else set it up for you, you will need to ask them or contact your hosting provider.
The method you use depends on whether you still have access to the machine where PostgreSQL runs, whether you have system administrator rights, and whether you remember any credentials at all.
Key Takeaways
- The default PostgreSQL user is called postgres, and on Linux systems you can often reset its password by logging in as the system root user and using the psql command.
- On Windows, you set a password for the postgres user during installation; if you lost it, you must reinstall PostgreSQL or reset it through the Services panel with administrator rights.
- If you created additional database users beyond postgres, their credentials are stored only in the PostgreSQL server itself, not in any file you can read without logging in first.
- The pg_hba.conf file controls how PostgreSQL accepts connections and can show you which authentication method is in use, but it does not contain passwords.
- Hosting providers and managed database services (like AWS RDS or DigitalOcean) send credentials by email at setup and store them in your account dashboard, not on the server itself.
Recovering the postgres user password on Linux
On Linux systems, the postgres user (the default administrator account) can be reset without knowing the old password if you have root access to the machine. Log in as root or use sudo, then run:
sudo -u postgres psql
This command switches to the postgres system user and opens the PostgreSQL command line without requiring a password. Once inside, you can set a new password with:
\password postgres
PostgreSQL will prompt you to enter a new password twice. After you exit (type \q), the new password is active. This works because Linux trusts the system root user to manage all accounts on the machine.
Recovering the postgres user password on Windows
Windows does not use the same trust model as Linux, so resetting the postgres password is more involved. During installation, you set a password for the postgres user; if you lost it, you have two main paths.
The first is to reinstall PostgreSQL. Uninstall the current version completely, then run the installer again and set a new password for the postgres user during setup. This is the most reliable method.
The second is to reset the password through the Windows Services panel if you have administrator rights. Open Services (services.msc), find the PostgreSQL service, stop it, then restart it with a different user account temporarily. This is complex and error-prone; reinstalling is usually faster.
Finding credentials you created for other database users
If you created a user account in PostgreSQL beyond the default postgres account, that username and password exist only inside the PostgreSQL server. There is no file on disk where you can read them back out.
Your options are to log in as the postgres user (using the method above) and reset the password for the other user, or to check any notes, password managers, or configuration files where you may have written the credentials down when you first created the account.
If you use a password manager like Bitwarden, 1Password, or KeePass, search for "postgres" or the database name. If you stored credentials in a text file, check your Documents folder or any project directories where you keep setup notes.
Checking PostgreSQL configuration files for connection hints
The pg_hba.conf file controls how PostgreSQL accepts connections, but it does not store passwords. You can find it in the PostgreSQL data directory (usually /var/lib/postgresql/[version]/main/ on Linux or C:\Program Files\PostgreSQL\[version]\data\ on Windows) and it will show you which authentication method is in use.
If the file shows trust authentication for local connections, it means PostgreSQL accepts connections from that user without a password. If it shows md5 or scram-sha-256, a password is required. This tells you whether a password exists, but not what it is.
The postgresql.conf file in the same directory contains server settings but also does not contain user passwords. These files are useful for understanding your setup, but password recovery requires either logging in as an existing user or reinstalling.
Getting credentials from your hosting provider
If PostgreSQL runs on a hosting provider like AWS RDS, DigitalOcean, Heroku, or Azure Database, the credentials were sent to you by email when you created the database. Check your email inbox and spam folder for messages from the provider with the subject line mentioning "database" or "credentials".
If you cannot find the email, log into your hosting provider's dashboard or control panel. Most providers display the database username and connection details in the database management section. The password is usually shown only once at creation; if you lost it, the provider will have a "reset password" button in that same section.
Write down the username, password, host address, and port number from the dashboard. You will need all four to connect to the database from your process or from the psql command line.
Testing your username and password once you have them
Once you have a username and password, test the connection from the command line to make sure they work. On any system with psql installed, run:
psql -U [username] -h localhost -d postgres
Replace [username] with the actual username. PostgreSQL will prompt you for the password. If the connection succeeds, you will see the postgres=# prompt. If it fails, you will see an error message like "password authentication failed" or "role does not exist".
If you are connecting to a remote database (on a hosting provider), replace localhost with the host address from your provider's dashboard. If the connection times out, the host address may be wrong, or the provider's firewall may be blocking your IP address.
Frequently Asked Questions
What is the default PostgreSQL username?
The default user created during installation is postgres. This is the superuser account with full permissions. You set its password during installation on Windows; on Linux, it often has no password initially and uses system trust authentication.
Can I see PostgreSQL passwords stored on my computer?
No. PostgreSQL stores passwords in a hashed form inside the server database, not in plain text anywhere on disk. You cannot read them back. If you lose a password, you must reset it by logging in as a user who already has access, or reinstall PostgreSQL.
What if I do not have root or administrator access to the machine?
You cannot reset the postgres password without system-level access. Contact the person who manages the server or your hosting provider's support team. They can reset it for you or provide you with a working set of credentials.
Where do I find the password if I used a hosting provider like AWS or DigitalOcean?
Log into your hosting provider's dashboard, navigate to the database section, and look for connection details or credentials. Most providers display the username and let you reset the password from there. Check your email for the initial setup message with the password as well.
Can I connect to PostgreSQL without a password?
Only if the pg_hba.conf file is set to trust authentication for your connection type, which is rare in production. Most setups require a password. If you need password-less access for automation, you can use a .pgpass file to store credentials securely instead of typing them each time.