14

I have installed PostgreSQL server 8.4 on my CentOS server sucessfully. After that, I login to CentOS server by using 'postgres' user, but I can not run any command, the error occur:

password authentication failed for user "postgres"

Here is some configurations in pg_hba.conf and postgresql.conf:

--------------------configuration in postgresql.conf-----------
listen_addresses = '*'

--------------------configuration in pg_hba.conf---------------
local   all         all                               md5  
local   all         postgres                          md5 
host    all         all         127.0.0.1/32          md5  
host    all         all         ::1/128               md5
Grzegorz Szpetkowski
  • 35,042
  • 4
  • 82
  • 127
Chan Pye
  • 1,301
  • 7
  • 17
  • 31

3 Answers3

15

I tend to use the following in pg_hba.conf:

# Database administrative login by UNIX sockets
local   all         postgres                          ident

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
local   all         all                               md5
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5

That means that once you're "postgres", you don't need a password, but you need sudo rights to become postgres, so that's pretty darn secure. Any other user can login using simple md5 authentication, which means you don't have to sudo all over the place. This works well for me.

Berry Langerak
  • 17,465
  • 2
  • 39
  • 53
11

Ensure you use the password of the postgres PostgreSQL account, not the postgres system account. Try "trust" instead of "md5" in the pg_hba.conf to connect to the db an change your pass.

Daniel
  • 25,883
  • 17
  • 87
  • 130
  • what's the difference between postgres system account and postgres PostgreSQL account? and how can I check whether i'm using postgres PostgreSQL account or not? – Chan Pye Aug 15 '11 at 02:07
  • I have used password for PostgreSQL account. – Chan Pye Aug 16 '11 at 09:02
  • Are you sure? How do you run any command?Do you get a shell using psql? – Daniel Aug 16 '11 at 09:59
  • I'm sure for that. I remote Linux server from XP desktop by using Putty. I use PostgresSQL account(postgres) to login, move to /opt/postgres/8.4/bin, run command .createdb abc, and error occur. Note that, I uninstalled PostgreSQL 9.0 before install PostgreSQL 8.4. Is that a reason? – Chan Pye Aug 17 '11 at 09:03
  • 2
    No, you never use the PostgreSQL account to login with putty, you use the system account (possibly named postgres). Then you enter "psql" at the command line, and use a PostgreSQL account to log into PostgreSQL, maybe without giving a password when using "ident" or "trust" in your pg_hba conf file. – Daniel Aug 17 '11 at 11:04
7

I met a similar problem (the same error message). Like Daniel answer, it's because that I confuse between :

"postgres PostgreSQL account, not the postgres system account."

To be sure about the postgres password, just change it to '123456' (or any other password)

# su postgres
# psql -d template1
template1=# ALTER USER postgres WITH PASSWORD '123456';
Hoàng Long
  • 10,221
  • 17
  • 71
  • 114