Where PostgreSQL stores your username
Your PostgreSQL username is stored in the server's user authentication system, not in a single file you can open. The most direct way to find it is to check the connection you're already using — if you can log in, you already know your username. If you've forgotten it, you'll need to either check your connection settings, ask your database administrator, or look at the system where PostgreSQL is running.
PostgreSQL usernames are separate from your operating system login. You might be "james" on your computer but "app_user" in PostgreSQL. The server keeps track of which usernames exist and what they're allowed to do, but that information lives in PostgreSQL's internal tables, not in a text file on your hard drive.
Key Takeaways
- Your current PostgreSQL username appears in connection strings, environment variables, or the command you used to log in — check these first before digging deeper.
- If you're already connected to PostgreSQL, the command SELECT current_user; will show your username when ready.
- On Linux or Mac, check your .pgpass file or shell history to see what username you used the last time you connected.
- On Windows, PostgreSQL stores connection history in pgAdmin or in your command prompt history if you logged in from there.
- If you've lost access entirely, contact your database administrator or the person who set up PostgreSQL on your system.
Check your current connection with a SQL command
If you're already logged into PostgreSQL, the fastest way to see your username is to run a single command. Open your PostgreSQL client (psql, pgAdmin, or whatever tool you use) and type:
SELECT current_user;
PostgreSQL will return your username when ready. This works whether you're using the default "postgres" account or a custom username you created. If you're connected, this command always works.
Look in your connection settings and history
PostgreSQL connection information often lives in places you've already set up. Check these locations based on how you usually connect:
If you use a connection string (a line that looks like postgresql://username@localhost/dbname), the username is the part between :// and @. Check your process's configuration files, environment variables, or database connection dialogs for this string.
On Linux and Mac, open your terminal and check the .pgpass file in your home directory. This file stores PostgreSQL login credentials in the format hostname:port:database:username:password. Type cat ~/.pgpass to see it. On Windows, pgAdmin stores connection details in its own settings — open pgAdmin, right-click a saved server connection, and select Properties to see the username field.
If you've logged in from the command line before, your shell history may show the command. On Linux or Mac, type history | grep psql to search for past login attempts. On Windows, press the up arrow in Command Prompt or PowerShell to scroll through recent commands.
Ask your database administrator
If you can't find your username through any of these methods, the person who set up PostgreSQL on your system has a record of it. This is usually your database administrator, your IT department, or the developer who configured your process's database connection.
When you contact them, tell them you need to know your PostgreSQL username for your specific database or server. They can look it up in their setup notes or check the server's user list directly. If you're the administrator and you've forgotten your own username, you can log in as the default "postgres" user (if you still have that password) and check the list of all usernames with the command \du in psql.
Find all usernames on the server if you're the administrator
If you have administrator access to PostgreSQL, you can see every username on the server. Log in as the "postgres" user or any other administrator account, then type:
\du
This displays a table of all PostgreSQL users, their roles, and what permissions they have. If you're looking for a specific username you created or used before, it will appear in this list. You can also run the SQL command SELECT usename FROM pg_user; to get just the usernames without the extra details.
Recover access if you've lost your password
If you know your username but can't log in because you've forgotten the password, you'll need to reset it. On the server where PostgreSQL is running, you can log in as the operating system user who owns the PostgreSQL process (usually called "postgres" on Linux) and reset the password without needing the old one.
On Linux or Mac, open a terminal on the server itself and type sudo -u postgres psql. This logs you into PostgreSQL as the postgres administrator. Then type ALTER USER your_username WITH PASSWORD 'new_password';, replacing "your_username" with the account you need to fix and "new_password" with something you'll remember. On Windows, use pgAdmin to right-click the username under Login/Group Roles, select Properties, and change the password in the Definition tab.
Check your process's database configuration
If PostgreSQL is running as part of an process (a website, a data tool, or a business system), the username is usually stored in a configuration file. Look for files named database.yml, .env, config.json, settings.py, or connection.conf in your process's folder.
These files often contain a line like DB_USER=myusername or username: myusername. The exact format depends on what programming language the process uses. If you're not sure which file to check, search your process's documentation or ask the developer who built it.
Frequently Asked Questions
Is my PostgreSQL username the same as my computer login?
No. PostgreSQL usernames are completely separate from your operating system login. You might be "alice" on your computer but "db_alice" in PostgreSQL. They don't have to match, and usually they don't.
What if I see "postgres" as the username — is that everyone's username?
"postgres" is the default administrator account that PostgreSQL creates when you first install it. Other usernames are custom accounts created later. If you see only "postgres" in the user list, no other accounts have been created yet.
Can I change my PostgreSQL username?
Yes, but it's complicated. You need administrator access and must use the command ALTER USER old_name RENAME TO new_name; in psql. Any applications or scripts using the old username will break until you update them, so change it only if you have a good reason.
What if the .pgpass file doesn't exist?
It only exists if you've created it or if PostgreSQL tools created it for you. If it's not there, check your connection history, your process's config files, or ask your administrator instead.
Can someone else see my PostgreSQL username?
Yes. Any administrator on the PostgreSQL server can see all usernames with the \du command. Your username is not secret — your password is. Never share your password, but your username is part of the normal server information.