Where PostgreSQL stores your login credentials
Your PostgreSQL username and password live in three places depending on how you set up the database: the system where PostgreSQL is installed, a configuration file on your computer, or a password file that PostgreSQL created during installation. The fastest way to recover them is to check where you first installed PostgreSQL and look for setup notes you may have saved.
If you installed PostgreSQL yourself on Windows or Mac, the installer asked you to create a password for the postgres user (the default administrator account). If you chose to save that password or write it down, check your email, Documents folder, or any setup confirmation files. If you installed it on a Linux server through a package manager, the system may have generated a random password automatically.
If you are trying to log in to a database someone else set up, or you are connecting to a hosted PostgreSQL service like AWS RDS or Heroku, the credentials are stored differently — usually in your hosting provider's dashboard or in a connection string file your team shared with you.
Key Takeaways
- The default PostgreSQL user is called postgres, and its password was set during installation — check your setup emails or installer logs first.
- On Windows and Mac, PostgreSQL stores connection details in a hidden folder called .pgpass in your home directory if you saved your password there.
- On Linux servers, check the PostgreSQL data directory (usually /var/lib/postgresql) and the pg_hba.conf file to see how authentication is configured.
- If you are using a hosted PostgreSQL service, your username and password are in your hosting provider's dashboard, not on your local computer.
- If you have lost the password entirely, you can reset it by connecting as the system administrator or by editing PostgreSQL's authentication configuration file.
Checking your Windows installation folder for setup notes
When you install PostgreSQL on Windows, the installer creates a folder and may leave a setup log or README file inside it. Open File Explorer and navigate to C:\Program Files\PostgreSQL (or C:\Program Files (x86)\PostgreSQL if you installed the 32-bit version). Look for a folder with a version number like 15 or 16.
Inside that folder, check for files named README.txt, INSTALL.txt, or release_notes.txt. Open them with Notepad to see if the installer recorded the password you entered. If you see a file called pgAdmin4 or a shortcut to pgAdmin, that is PostgreSQL's built-in database management tool — you can use it to reset the password if you have lost it.
If you do not find any notes, check your Downloads folder or Desktop for an installer log file. Windows sometimes saves installer output as PostgreSQL-installer.log or similar. Search your entire computer for files containing "postgres" and "password" using Windows Search.
Finding the .pgpass password file on Mac and Linux
PostgreSQL can store your username and password in a hidden file called .pgpass in your home directory. This file only exists if you chose to save your password when you first connected to the database. To find it, open Terminal and type the following command:
cat ~/.pgpass
If the file exists, Terminal will display its contents in the format hostname:port:database:username:password. Each line is one saved connection. If you see nothing or an error saying the file does not exist, the password was never saved to this file.
If the file exists but you cannot read it, you may need to change its permissions. Type chmod 600 ~/.pgpass and try again. If you want to add a new connection or edit an existing one, open the file with a text editor like nano: nano ~/.pgpass. Add a line in the format above, press Ctrl+O to save, then Ctrl+X to exit.
Checking PostgreSQL configuration files on Linux servers
On a Linux server, PostgreSQL configuration files are usually in /etc/postgresql or /var/lib/postgresql. The most important file is pg_hba.conf, which controls how users connect and whether passwords are required. To view it, open Terminal and type:
sudo cat /etc/postgresql/[version]/main/pg_hba.conf
Replace [version] with your PostgreSQL version number, like 15 or 16. This file shows which users can connect and what authentication method is used. If you see trust in the authentication column, it means no password is required for local connections. If you see md5 or scram-sha-256, a password is required.
The actual usernames are stored in the PostgreSQL system itself, not in a file you can read directly. To see all users and their roles, you must connect to PostgreSQL as an administrator and run a command inside the database. If you can connect without a password (because authentication is set to trust), type sudo -u postgres psql to open the PostgreSQL prompt, then type \du to list all users.
Resetting the password if you have lost it
If you cannot find your password anywhere, you can reset it. On Windows, open pgAdmin (the graphical tool that came with PostgreSQL). Right-click the server name in the left panel, select Properties, and go to the Connection tab. Click the password field and enter a new password, then click Save.
On Mac and Linux, you can reset the password from the command line. First, stop the PostgreSQL service by typing sudo systemctl stop postgresql. Then edit the pg_hba.conf file and change the authentication method from md5 or scram-sha-256 to trust temporarily. Restart PostgreSQL with sudo systemctl start postgresql. Now you can connect without a password: sudo -u postgres psql. Inside the PostgreSQL prompt, type ALTER USER postgres WITH PASSWORD 'newpassword'; (replace newpassword with your new password). Then change pg_hba.conf back to md5 or scram-sha-256 and restart PostgreSQL again.
Getting credentials from a hosted PostgreSQL service
If you are using PostgreSQL through a hosting provider like AWS RDS, Azure Database, Google Cloud SQL, or Heroku, your username and password are not on your computer — they are in your provider's dashboard. Log in to your hosting account and look for a section called Databases, Instances, or Credentials.
AWS RDS shows the username and a button to reset the password in the database instance details page. Azure displays the username and lets you reset the password in the Connection Security section. Heroku stores the credentials in a connection string that looks like postgres://username:password@host:port/database — you can view it in your app settings under Config Vars or Reveal Config Vars.
If your team shared a connection string with you but you cannot see the password, ask them to provide it again or to reset it in the hosting dashboard. Never store passwords in plain text in your code or in shared documents — use environment variables or a secrets manager instead.
Frequently Asked Questions
What is the default PostgreSQL username?
The default username is postgres. This is the superuser account created during installation. You can create additional users with different permissions, but postgres is the one that exists from the start and has full administrative access to all databases.
Can I see the password if it is stored in a connection string?
Yes, if you have the connection string. It usually looks like postgres://username:password@hostname:port/database. The password is the part between the colon and the @ symbol. If the string is in a file or environment variable, you can view it with a text editor or by typing echo $DATABASE_URL in Terminal (on Mac and Linux).
What if PostgreSQL is installed but I never set a password?
On some Linux systems, PostgreSQL is installed with authentication set to trust, which means no password is required for local connections. You can connect by typing sudo -u postgres psql without entering a password. If you want to add a password later, use the ALTER USER command described above.
Where do I enter the username and password to connect?
You enter them in your database client tool (like pgAdmin, DBeaver, or psql) when you create a new connection. You will see fields for Host, Port, Database, Username, and Password. The host is usually localhost if PostgreSQL is on your computer, or a server address if it is hosted elsewhere. The port is usually 5432 unless you changed it during installation.
Is it safe to save my password in the .pgpass file?
The .pgpass file is safer than storing passwords in plain text in your code, but it is not encrypted. Only you should have access to it — PostgreSQL enforces this by requiring the file to have permissions 600 (readable only by you). For production databases, use a secrets manager or environment variables instead of .pgpass.