Where PostgreSQL stores your username
Your PostgreSQL username is stored in the database server itself, not in a configuration file you can browse. The most direct way to find it is to check what user account you used to connect the last time you logged in, or to look at the connection details your process is using right now.
If you set up PostgreSQL yourself, you created at least one username during installation — usually called postgres (the superuser account) or a custom name you chose. If someone else set it up, you need to ask them or check where your process stores its database connection settings.
Key Takeaways
- The default PostgreSQL superuser is named postgres, created automatically during installation on any operating system.
- Your process's configuration file — often named config.ini, .env, or settings.py — usually contains the username it uses to connect.
- On Windows, check the PostgreSQL installation folder for a file called pg_hba.conf to see which users are allowed to connect.
- On Linux or Mac, you can list all PostgreSQL users by running psql -U postgres -l if you have command-line access and know the superuser password.
- If you cannot remember your username or password, you may need to reset the superuser account through PostgreSQL's recovery mode.
Check your process's database settings
Most applications that use PostgreSQL store the connection details — including username — in a configuration file. Look for files named config.ini, settings.py, database.yml, .env, or connection.conf in your process's main folder or a config subfolder.
Open the file in a text editor and search for lines containing user=, username=, or db_user. The value after the equals sign is the PostgreSQL username your process is using. You may also see host= (the server address) and database= (the database name) nearby, which can help you confirm you are looking at the right connection.
If your process is web-based and hosted on a server you do not control, contact the hosting provider or process administrator — they manage the database credentials.
Find the username through the PostgreSQL command line
If you have access to a terminal or command prompt on the machine where PostgreSQL is installed, you can list all usernames directly. Open a terminal (on Linux or Mac) or Command Prompt (on Windows) and run this command:
psql -U postgres -l
This connects to PostgreSQL using the default superuser account postgres and lists all databases. You will be prompted for the superuser password. If you do not know it, skip to the recovery section below.
Once connected, you can run \du to see a list of all usernames and their permissions. The output shows each username in the first column, with role attributes (like superuser or database creation rights) in the columns to the right.
Check PostgreSQL's user authentication file on Windows
On Windows, PostgreSQL stores user authentication rules in a file called pg_hba.conf. This file does not list all usernames, but it shows which users are allowed to connect and how they authenticate.
Find this file in your PostgreSQL installation folder — usually C:\Program Files\PostgreSQL\[version]\data\pg_hba.conf. Open it in Notepad or another text editor. Look for lines that do not start with # (comments). Each line shows a user, a database, and an authentication method. The username appears in the fourth column of each active line.
This file is most useful if you remember part of your username or want to see which users have permission to connect from your computer.
Check PostgreSQL's user authentication file on Linux or Mac
On Linux and Mac, the pg_hba.conf file is usually in /etc/postgresql/[version]/main/pg_hba.conf or /usr/local/var/postgres/pg_hba.conf, depending on how PostgreSQL was installed.
You will need superuser (root) access to read this file. Open a terminal and run:
sudo cat /etc/postgresql/*/main/pg_hba.conf
This displays the authentication rules. Look for lines without a # at the start — the username is usually in the fourth column. If PostgreSQL was installed with Homebrew on Mac, try /usr/local/var/postgres/pg_hba.conf instead.
Reset the superuser password if you cannot remember it
If you cannot find your username or password and cannot connect to PostgreSQL, you can reset the superuser account. The process differs by operating system.
On Windows: Stop the PostgreSQL service (open Services and find PostgreSQL), then restart it in single-user mode. Open Command Prompt as administrator, navigate to the PostgreSQL bin folder (usually C:\Program Files\PostgreSQL\[version]\bin), and run postgres --single -D "C:\Program Files\PostgreSQL\[version]\data". Once in single-user mode, you can reset the superuser password without authentication.
On Linux or Mac: Stop PostgreSQL with sudo systemctl stop postgresql (or brew services stop postgresql on Mac). Then restart it in single-user mode with sudo -u postgres postgres --single -D /var/lib/postgresql/[version]/main. You will have a prompt where you can run SQL commands to reset the password.
If you are not comfortable with these steps, contact your system administrator or PostgreSQL support — they can help you regain access without data loss.
Frequently Asked Questions
What is the default PostgreSQL username?
The default superuser username is postgres, created automatically when you install PostgreSQL on any operating system. This account has full permissions to create databases, users, and modify any data. You may have created additional usernames during setup or process configuration.
Can I see all PostgreSQL usernames without connecting to the database?
Not directly from outside the database. You can view the pg_hba.conf authentication file to see which users are allowed to connect, but the complete list of all usernames lives only in the PostgreSQL system tables. You need to connect with a superuser account or have file system access to the server.
Where do I find my username if I use a managed PostgreSQL service like AWS RDS or Heroku?
Check your service's dashboard or control panel — it usually displays the database connection details, including username, when you view the database settings. For AWS RDS, open the RDS console and select your database instance; the username appears under "Configuration". For Heroku, run heroku config in your terminal to see the database URL, which includes the username.
What if my process uses a different username than the superuser?
Applications often create their own limited-permission usernames for security. Check your process's configuration file first — that username is what you need to know. The superuser account is separate and is used only for administrative tasks like creating databases or resetting passwords.