How do I create a Postgres user? By default, the user is ‘Postgres’ and the password is the one which you enter while installing the database. (Version 11,12 I have tested). from cmd in Windows will ask for the password of the User (Logged in) which might not be available.
When setting up Postgres, users are prompted to set up a secure and complex password. Given that the password is intended to secure confidential data, users may sometimes forget their Postgres password. In this article, we will explore some of the tried and tested methods to figure out your Postgres password in case you have forgotten it.
Table of Contents
ToggleIntroduction to Postgres
Postgres is an open source object-relational database management system, similar to MySQL and Microsoft’s SQL Server. It is a powerful platform that can be used for managing relational databases covering a wide range of applications. Postgres is often referred to as the “world’s most advanced open source relational database” and can be used in the cloud, on-premise or even in a hybrid setup.
To secure the users’ private data, Postgres prompts users to set up secure and complex passwords. This is expected to protect and maintain the integrity of the user’s personal information. However, this means that users may forget their Postgres passwords.
How To Recover Your Postgres Password?
If you’ve forgotten your Postgres password, here are a few methods you can use to regain access:
1. Look Up Your Ambient Variable
If you’re running Postgres on Linux, you can look up your password by typing in “env|grep PG” in your terminal. This will take you to your ambient environment variable which contains your Postgres username and password.
You can also look up your ambient variable in Windows by typing “Set PGUSER” and “Set PGPASSWORD’ in your command prompt.
2. Reset Your Password
If you’ve forgotten your Postgres password, you may consider resetting it. To reset your Postgres password, enter ‘password’ in the command line, followed by your username. You will then be prompted to enter a new password.
To successfully reset your password, you need to confirm that you’re an admin user. To confirm this, type in “du” or “g admin” in the command prompt.
3. Check Your pg dump File
You can also check your pgdump file which is a backup file of your entire Postgres database. To locate and access this file, simply type in “w” into the Postgres terminal. This will lead you to the file location of your dump file.
After accessing the dump file, open it with a text editor such as Notepad or Atom. This file contains both your username and password in plain text.
FAQ’s
Q: How do I know my Postgres username?
If you’ve forgotten your username, you can simply look it up in the ambient variable. To do this, type in “env|grep PG” in the terminal for Linux users or use the command prompt “Set PGUSER” and “Set PGPASSWORD” for Windows.
Q: What is the ideal password length for Postgres?
Ideally, your Postgres password should be at least 16 characters long and combine capital and lowercase alphabets with numbers and special characters.
Q: What if I don’t remember the Postgres password, or it is too complex to remember?
If you’re unable to come up with a password that you can remember, try using a password manager program like which lets you securely store complex passwords.
Conclusion
When disabling access to confidential Postgres databases, users are asked to set up complex passwords. However, this makes it difficult for users to remember their Postgres password and they can unintentionally lock themselves out of their databases.
Fortunately, users can look up their ambient variable, reset their password and even check their pgdump file to access their Postgres password. For added convenience and security, users may consider using a trusted password manager like the LogMeOnce program to securely store complex passwords.
Having trouble remembering your Postgres password? Losing your Postgres password can be quite frustrating, especially if you need access to your database in a hurry. Luckily, retrieving a forgotten Postgres password is relatively simple and can be done quickly.
First, you’ll need to log into your server. Depending on your server’s setup you’ll most likely need root access, which means you’ll need to have the proper admin rights to complete the process.
Once you’re logged in to your machine, you’ll need to open the Postgres configuration file. This will be specific to your particular version of Postgres, but for the most part, this can be done by cd-ing into your main data directory and looking for a file labelled “PostgreSQL.conf.”
Once you’re in the Postgres configuration file, search for the “password” field. In the field, you should see the value associated with the Postgres password. You can modify it to a new password or copy it to use in your next login.
If you’re using a hosted Postgres service, such as Heroku, Amazon Web Services, or Google Cloud Platform, you should be able to log into the service itself and reset the password from there.
And that’s it! You’ll now know your Postgres password. Remember to be mindful of the security of your data, and make sure to choose a strong password and store it somewhere secure so you don’t forget it again.

Faye Hira, a distinguished graduate from the University of Okara, has carved a niche for herself in the field of English language education and digital marketing. With a Bachelor of Science in English, she specializes in Teaching English as a Second or Foreign Language (ESL), a skill she has honed with dedication and passion. Her expertise extends beyond the classroom and content writer, as she has also made significant strides in the world of Content and Search Engine Optimization (SEO). As an SEO Executive, Faye combines her linguistic prowess with technical acumen to enhance online visibility and engagement.