Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have just installed postgres 8.4 on Ubuntu 9.10 and it has never asked me to create a superuser. Is there a default superuser and its password? If not, how do I create a new one?

share|improve this question

6 Answers

up vote 4 down vote accepted

I'm not a postgres user (I use the other one) but to reset the (Ubuntu 9.10) password for postgres, how about

$ sudo passwd postgres

and give it a new password.

share|improve this answer
8  
It is not the right way. user postgres is authenticated by "indent", so he does not need a password at all. sudo -u postgres psql and you are good to go. – Tyler Long Oct 8 '12 at 3:22
1  
This answer is dangerous and should be removed, or at least have its acceptance as "best answer" revoked in favour of user716468's answer below. – Joe Carroll Mar 30 at 11:00

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. There are usually two default ways to login PostgreSQL:

  1. By running the "psql" command as a UNIX user (so-called IDENT/PEER authentication), e.g.: sudo -u postgres psql.

  2. by TCP/IP connection using PostgreSQL's own managed username/password (so-called TCP authentication) (i.e., NOT the UNIX password).

So you never want to set the password for UNIX account "postgres". Leave it locked as it is by default.

Of course things can change if you configure it differently from the default setting. For example, one could sync the PostgreSQL password with UNIX password and only allow local logins. That would be beyond the scope of this question.

share|improve this answer
so, how do you lock user postgres back? – ultrajohn Jul 4 '12 at 4:30
1  
@ultrajohn - depends on distribution you use, but you can edit /etc/passwd and put * instead of the password – lzap Sep 12 '12 at 9:50
1  
/etc/shadow is where the password is kept @lzap. – Gringo Suave Sep 20 '12 at 18:56
1  
Right, you can either set /sbin/nologin in /etc/passwd or put * instead of the password in /etc/shadow. – lzap Sep 21 '12 at 9:37

on the command line

$ sudo -u postgres psql postgres

# \password postgres

Enter new password:

share|improve this answer
2  
This is what's needed to use a tool like pgadminIII (when setting up a server profile) immediately after Postgres itself is installed. Thanks! – limist Jul 10 '11 at 16:55

You manipulate postgres through the user postgres, as so:

# su - postgres
$ createdb mydb
$ psql -s mydb
# create user someuser password 'somepassword';
# GRANT ALL PRIVILEGES ON DATABASE mydb TO someuser;
share|improve this answer
When I su to postgres, it's asking for a password. I don't recall inputting one before. Is there a way to reset that password for postgres? – Thierry Lam Feb 6 '10 at 5:15

For windows users, type

net user accountname newpassword

to change your password

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.