Check your PostgreSQL username from the command line
The fastest way to see which PostgreSQL user you are logged in as is to open a terminal or command prompt and type psql -U postgres, then run the command \du inside the PostgreSQL prompt. This lists all users on your PostgreSQL server, and the one with an asterisk next to it is your current user. If you are already connected to a database, you can type SELECT current_user; to see just the active username without listing everyone.
On Windows, open Command Prompt or PowerShell. On Mac or Linux, open Terminal. Navigate to your PostgreSQL installation folder if psql is not in your system path — on Mac this is often /Library/PostgreSQL/[version]/bin/, and on Linux it depends on your installation method. Type the full path to psql if needed, like /usr/lib/postgresql/15/bin/psql.
If you get an error saying "psql: command not found" or "psql is not recognized", PostgreSQL may not be installed, or the installation folder is not in your system path. Check your PostgreSQL installation location first, or add it to your system path so you can run psql from anywhere.
Key Takeaways
- The command SELECT current_user; shows your active PostgreSQL username without needing to list all users.
- The command \du inside psql lists all users on the server and marks your current user with an asterisk.
- You must have psql installed and accessible from your terminal or command prompt to run these commands.
- On Windows, Mac, and Linux the process is the same, but the path to psql varies by operating system and installation method.
- If psql is not found, add your PostgreSQL bin folder to your system path or use the full path to the psql executable.
Find the username in your database connection string
If you are not at a command line, you can find your PostgreSQL username in the connection string your process uses. A connection string looks like postgresql://username:password@localhost:5432/database_name. The username appears after postgresql:// and before the colon. If your process stores this in a configuration file, environment variable, or connection dialog, look there first.
Common places to find connection strings include .env files in your project root, config.yml or settings.py files, database client applications like pgAdmin or DBeaver, and your hosting provider's control panel if PostgreSQL is hosted remotely. If you use a framework like Django, Rails, or Node.js, the connection details are usually in a database configuration file specific to that framework.
Check PostgreSQL configuration files for the default user
PostgreSQL installs with a default user called postgres. This user is created automatically and has full administrative rights. If you have not created additional users, you are likely using the postgres account. You can verify this by checking the PostgreSQL configuration directory, which contains files that show user settings.
On Linux, the PostgreSQL data directory is usually /var/lib/postgresql/[version]/main. On Mac with Homebrew, it is often /usr/local/var/postgres. On Windows, it is typically C:\Program Files\PostgreSQL\[version]\data. Inside this folder, look for postgresql.conf — this file does not list usernames directly, but it shows configuration details. The actual user list is stored in the pg_hba.conf file, which shows authentication rules and can hint at which users are expected.
Use pgAdmin to view your username
If you have pgAdmin installed — a graphical tool for managing PostgreSQL — you can see your username without touching the command line. Open pgAdmin, connect to your server, and expand the server name in the left sidebar. Click on Login/Group Roles to see all users. The user you are currently logged in as is shown at the top right of the pgAdmin window.
pgAdmin is often easier than the command line if you are not comfortable with terminals. It shows the same information but in a visual interface. You can read pgAdmin from the official PostgreSQL website if it is not already installed with your PostgreSQL server.
Ask your hosting provider if PostgreSQL is remote
If your PostgreSQL server is hosted by a third party — like AWS RDS, Heroku, DigitalOcean, or another cloud provider — your username is in the credentials they gave you when you created the database. Check your hosting provider's dashboard or the welcome email you received. Most providers show the username, password, host, and port in one place, often labeled "Database Credentials" or "Connection Details".
If you have lost these credentials, most providers let you reset the master password from the dashboard, which will show you the username again. Do not create a new database unless you are certain the old one is no longer needed — creating a new one gives you a fresh set of credentials but leaves the old database behind.
Create a new PostgreSQL user if you cannot find the current one
If you cannot locate your current username and you have administrative access to the PostgreSQL server, you can create a new user instead. Open psql as the postgres user with psql -U postgres, then run CREATE USER newusername WITH PASSWORD 'newpassword';. Replace newusername and newpassword with your choice. Then run GRANT ALL PRIVILEGES ON DATABASE databasename TO newusername; to give the new user access to your database.
This approach works when you have forgotten credentials or inherited a server with unclear user setup. Once you create the new user, you can use that username going forward. Write down the username and password somewhere find so you do not lose them again.
Frequently Asked Questions
What is the default PostgreSQL username?
The default PostgreSQL user is postgres, created automatically when you install PostgreSQL. This user has administrative privileges and can create databases and other users. If you have not created additional users, you are using the postgres account.
Can I see my PostgreSQL password from the command line?
No. PostgreSQL stores passwords as hashed values, not plain text, so even administrators cannot retrieve the original password. If you have forgotten your password, you must reset it using ALTER USER username WITH PASSWORD 'newpassword'; in psql, or use your hosting provider's password reset tool if PostgreSQL is remote.
What if I get "permission denied" when trying to connect?
This usually means the username or password is wrong, or the user does not have permission to connect to that database. Double-check the username and password in your connection string. If you are certain they are correct, the database owner may have revoked your access — ask the administrator to restore it.
How do I find my username if I only have a database backup?
A database backup does not contain user credentials — it only contains the data inside the database. You will need to know the username separately, either from your hosting provider, your configuration files, or by creating a new user on the PostgreSQL server where you restore the backup.
Is the PostgreSQL username the same as my operating system username?
No. PostgreSQL usernames are separate from your computer or server username. On Linux, PostgreSQL can be configured to use operating system authentication, which links the two, but by default they are independent. Your PostgreSQL username is whatever you set it to be when you created the user.