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?

link|improve this question

feedback

6 Answers

up vote 6 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.

link|improve this answer
feedback

on the command line

$ sudo -u postgres psql postgres

# \password postgres

Enter new password:

link|improve this answer
1  
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
feedback

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

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

What you should have done is following Chris James's answer. To explain it a little bit: There are usually two default ways to login PostgreSQL: By running "psql" command as a UNIX user (so-called IDENT/PEER authentication), or by TCP/IP connection using PostgreSQL's own managed username/password (so-called TCP authentication). Therefore to use PostgreSQL as the power user "postgres", you either use "psql" command as "postgres" UNIX user (e.g., through "sudo -u postgres psql"), or you use TCP/IP connection and use "postgres" username and the password that PostgreSQL manages (i.e., NOT UNIX password). So the question is you do not know the default PostgreSQL password for "postgres" username. That is why you want to reset the password using "sudo -u postgres psql". But you NEVER want to set the passwrod for UNIX account "postgres".

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. That would be beyond the scope of this question.

link|improve this answer
feedback

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 mydb to someuser;
link|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
feedback

For windows users, type

net user accountname newpassword

to change your password

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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