Where PostgreSQL stores your login information
PostgreSQL does not display your password anywhere after you set it — by design. The database stores only an encrypted version, so even a system administrator cannot retrieve your original password. What you can do instead is reset it, view the username associated with your account, or check which authentication method your connection uses.
The username is stored in the system catalog, a set of internal tables that PostgreSQL maintains. You can view it by connecting to the database and running a query. The password itself cannot be recovered, but you can change it to something new if you have the right permissions.
Key Takeaways
- PostgreSQL usernames are visible in the system catalog, but passwords are encrypted and cannot be viewed or recovered.
- You can see your own username by connecting to PostgreSQL and running SELECT current_user;
- To reset a password you have forgotten, use the ALTER USER command if you have superuser access, or ask your database administrator.
- Connection information (host, port, database name) is usually stored in a .pgpass file on your computer, not in PostgreSQL itself.
- If you cannot connect at all, check your pg_hba.conf file to confirm the authentication method your server expects.
Viewing your current username in PostgreSQL
The simplest way to confirm which user you are logged in as is to run a query after you connect. Open your PostgreSQL client — this might be psql (the command-line tool), pgAdmin (the graphical interface), or another tool your hosting provider gives you.
Type or paste this command and press Enter:
SELECT current_user;
PostgreSQL will return the username associated with your current connection. This is the account you are using right now. If you are connected as a superuser (the most powerful account type), you will see a name like postgres or the custom superuser name your administrator created.
You can also see all usernames on the server by running:
SELECT usename FROM pg_user;
This shows every user account that exists on this PostgreSQL installation. You will only see this list if your current user has permission to view the system catalog — most regular users can see it, but some restrictive setups may block it.
Resetting a password you have forgotten
If you know your username but have forgotten the password, you have two paths depending on your access level.
If you have superuser access: Connect to PostgreSQL using any account that has superuser privileges (often the postgres account). Then run:
ALTER USER your_username WITH PASSWORD 'new_password';
Replace your_username with the actual username and new_password with whatever you want the new password to be. Use single quotes around the password. After you press Enter, the password is changed when ready.
If you do not have superuser access: Contact your database administrator or hosting provider. They can reset the password for you. Do not ask them for the old password — they cannot retrieve it. They can only set a new one.
Finding connection details in your .pgpass file
PostgreSQL can store connection information (hostname, port, database name, username, and password) in a file called .pgpass on your computer. This file lets you connect without typing credentials each time. It is not part of PostgreSQL itself — it lives on your machine.
On Mac or Linux, look for this file in your home directory:
~/.pgpass
On Windows, it is usually here:
%APPDATA%\postgresql\pgpass.conf
Open the file in a text editor. Each line represents one saved connection and follows this format:
hostname:port:database:username:password
For example:
localhost:5432:mydb:myuser:mypassword
If you see your connection details here, you now know the username and password that were saved. If the file does not exist, no credentials have been stored this way.
Checking authentication method in pg_hba.conf
If you cannot connect to PostgreSQL at all, the problem might be the authentication method the server expects. This is set in a file called pg_hba.conf, which lives on the server (not on your computer).
Common authentication methods include md5 (password-based), scram-sha-256 (encrypted password), trust (no password required), and peer (uses your operating system username). If the server is set to peer but you are trying to connect with a password, the connection will fail.
You cannot edit pg_hba.conf unless you have access to the server itself or you are the database administrator. If you are renting PostgreSQL from a hosting provider, they control this file. If you installed PostgreSQL on your own machine, you can find and edit it yourself.
On Mac or Linux, it is usually in:
/etc/postgresql/[version]/main/pg_hba.conf
On Windows, it is usually in the PostgreSQL installation folder, in a subfolder called data. After you change pg_hba.conf, you must restart the PostgreSQL service for the change to take effect.
What to do if you are locked out completely
If you cannot connect as any user and you installed PostgreSQL on your own machine, you can reset the superuser password by stopping the server and restarting it in single-user mode. This is a recovery procedure and varies by operating system.
On Linux, stop PostgreSQL, then start it with the -s flag. On Windows, you may need to reinstall PostgreSQL or use the recovery mode built into the installer. On Mac, the process is similar to Linux.
If PostgreSQL is hosted by a provider (AWS, Heroku, DigitalOcean, or similar), you cannot access single-user mode. Contact their support team. They can reset the superuser password or help you regain access.
Frequently Asked Questions
Can I see my password if I am logged into PostgreSQL?
No. PostgreSQL encrypts passwords and stores only the encrypted version. Even superusers cannot retrieve the original password. You can only change it to something new using the ALTER USER command.
What is the default PostgreSQL username and password?
The default superuser is named postgres, and it has no default password. During installation, you set the password yourself. If you forgot it, you must reset it using single-user mode (if you own the server) or contact your administrator.
How do I find the username if I only have the password?
You cannot work backwards from a password to find the username. If you know the password but not the username, try common names like postgres, admin, or the name of your process. If none work, contact your database administrator.
Is my password stored in plain text anywhere?
Only in the .pgpass file on your computer, if you created one. PostgreSQL itself stores only encrypted passwords. If you want to keep your password private, do not create a .pgpass file or restrict its permissions so only you can read it.
What does "peer authentication" mean, and why can't I use a password?
Peer authentication means PostgreSQL trusts your operating system username instead of asking for a password. If the server uses peer authentication, you must connect as the same user you are logged in as on your computer. You cannot use a password. Ask your administrator to change the authentication method to md5 or scram-sha-256 if you need password-based login.