SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / server / Questions / 110154
Accepted
Thierry Lam
Thierry Lam
Asked: 2010-02-06 20:54:20 +0800 CST2010-02-06 20:54:20 +0800 CST 2010-02-06 20:54:20 +0800 CST

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

  • 772

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?

user-management postgresql
  • 5 5 Answers
  • 1138706 Views

5 Answers

  • Voted
  1. Best Answer
    user716468
    2011-10-28T22:25:11+08:002011-10-28T22:25:11+08: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 to PostgreSQL server:

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

    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.

    • 617
  2. dcrawkstar
    2011-03-17T07:39:09+08:002011-03-17T07:39:09+08:00

    Enter on the command line:

    $ sudo -u postgres psql postgres
    postgres=# \password postgres
    

    You'll see:

    Enter new password: 
    Enter it again:
    
    • 190
  3. David Mackintosh
    2010-02-06T21:02:50+08:002010-02-06T21:02:50+08:00

    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;
    
    • 69
  4. M.S. Dousti
    2014-11-19T11:25:16+08:002014-11-19T11:25:16+08:00

    In Windows, do the following (IMPORTANT: Use a Windows administrator account):

    1. After installation, open <PostgreSQL PATH>\data\pg_hba.conf.

    2. Modify these two lines, and change "md5" to "trust":

      host all all 127.0.0.1/32 md5

      host all all ::1/128 md5

    3. Restart the PostgreSQL service (might not be necessary).

    4. (Optional) Open a command prompt, and change code page to 1252:

      cmd.exe /c chcp 1252

    5. Log in to PostgreSQL. Non password will be needed (notice the uppercase -U parameter):

      psql -U postgres

    6. (Optional, recommended for security reasons) Change the postgres user's password:

      \password postgres

      and change "trust" back to "md5" in pg_hba.conf.

    • 24
  5. Marcio Mazzucato
    2014-03-08T05:44:18+08:002014-03-08T05:44:18+08:00

    If you are trying to access the PostgreSQL shell, you can type:

    psql -U postgres my_database

    Where my_database is your database name.

    • 6

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    Ping a Specific Port

    • 18 Answers
  • Marko Smith

    How do I tell Git for Windows where to find my private RSA key?

    • 30 Answers
  • Marko Smith

    How do you restart php-fpm?

    • 18 Answers
  • Marko Smith

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

    • 5 Answers
  • Marko Smith

    What port does SFTP use?

    • 6 Answers
  • Marko Smith

    Resolve host name from IP address

    • 8 Answers
  • Marko Smith

    How can I sort du -h output by size

    • 30 Answers
  • Marko Smith

    Command line to list users in a Windows Active Directory group?

    • 9 Answers
  • Marko Smith

    What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

    • 3 Answers
  • Marko Smith

    How to determine if a bash variable is empty?

    • 15 Answers
  • Martin Hope
    Davie Ping a Specific Port 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    binaryorganic How do I tell Git for Windows where to find my private RSA key? 2010-10-26 08:45:39 +0800 CST
  • Martin Hope
    tobym What exactly do the colors in htop status bars mean? 2010-09-14 12:22:43 +0800 CST
  • Martin Hope
    MikeN In Nginx, how can I rewrite all http requests to https while maintaining sub-domain? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner How can I sort du -h output by size 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 What is the difference between double and single square brackets in bash? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt How does IPv4 Subnetting Work? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent How to determine if a bash variable is empty? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus How do you find what process is holding a file open in Windows? 2009-05-01 16:47:16 +0800 CST

Related Questions

Trending Tags

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve