21

In the short version of postgres' installing it tell me to do the following

./configure
gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

Now I created the postgres user, but it sometimes asks for my credentials for that user. Is there a default password for the postgres user? Why do I even need to make another user?

1
  • I see a close, should I migrate this to sever fault or super user? Commented Mar 23, 2012 at 6:14

3 Answers 3

49

What's the default superuser username/password for postgres after a new install?:

CAUTION The answer about changing the UNIX password for "postgres" through "$ sudo passwd postgres" is not preferred, and can even be DANGEROUS!

This is why: By default, the UNIX account "postgres" is locked, which means it cannot be logged in using a password. If you use "sudo passwd postgres", the account is immediately unlocked. Worse, if you set the password to something weak, like "postgres", then you are exposed to a great security danger. For example, there are a number of bots out there trying the username/password combo "postgres/postgres" to log into your UNIX system.

What you should do is follow Chris James's answer:

sudo -u postgres psql postgres

# \password postgres

Enter new password: 

To explain it a little bit...

Sign up to request clarification or add additional context in comments.

6 Comments

tl;dr sudo passwd postgres to set the password
By all means read the linked answer, sudo passwd postgres should not be used, instead run sudo -u postgres psql postgres and enter \password postgres.
not working for me... I get this: "postgres is not in the sudoers file. This incident will be reported."
Question: what's wrong with sudo passwd postgres?
@rikkitikkitumbo ran into same issue just now. Enter exit to switch from postgres to root user.
|
2

Set the default password in the .pgpass file. If the server does not save the password, it is because it is not set in the .pgpass file, or the permissions are open and the file is therefore ignored.

Read more about the password file here.

Also, be sure to check the permissions: on *nix systems the permissions on .pgpass must disallow any access to world or group; achieve this by the command chmod 0600 ~/.pgpass. If the permissions are less strict than this, the file will be ignored.

Have you tried logging-in using PGAdmin? You can save the password there, and modify the pgpass file.

1 Comment

@juvchan, I hadn't tried it on Windows 8.1. Glad it worked for you!
2

Sudoers Error

This answer addresses how to actually change the password. If you followed the directions and received the following confusing error:

postgres is not in the sudoers file. This incident will be reported.

Then you are very likely not at root level. I received this error and was really confused. Turns out I was logged into postgres rather than the root user. What solved that problem for me was using the following command to log out:

exit

You will then be back at the root where you can do sudo-level actions again. Keep in mind this same solution also works for other common issues that arise when you don't know the postgres password.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.