Reputation: 11082
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
?
Upvotes: 21
Views: 127707
Reputation: 135
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.
Upvotes: 2
Reputation: 11082
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...
Upvotes: 49
Reputation: 1768
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.
Upvotes: 2