Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to create user and database in linux server. I am able to create user with the following code:

su - postgres
# createuser -S -D -R myUser

but when I tried to create database with code :

# createdb -U myUser -p 5432 myDatabase

I get following error:

createdb: could not connect to database postgres: FATAL:  Ident authentication failed for user "myUser"

I am new to linux so I am unable to figure out why I was able to create user but while creating database there is connection error with postgres. And also error for ident authentication for user.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You need to learn more about HBA configuration.

There are some basic authentication methods:

  • trust - every users can connect to database(s) specified at second column where all means just all databases in cluster (yeah, excluding template0, because datallowconn in pg_database system catalog is set to false.. nevermind)
  • ident (prior to PostgreSQL 8.4 ident sameuser) - only actually logged (for example using su in console as your su - postgres) system user (with same name as role name) can connect
  • md5 - every user that knows role (PostgreSQL) password can log to database

Every time you attempting connection to concrete role and database even if do not write is explicitely.

The are generally two types of connection:

  • local - Unix-domain sockets
  • host - using TCP/IP connection

If you don't know which you are using, then it's local. To use TCP/IP connection you need to specify -h option with target IP where postmaster is listening. For example you can add -h localhost or -h 127.0.0.1, but check your listen_adresses (AFAIK default value is localhost, so it's ok) property in postgresql.conf and accepted client IP-address(es) in HBA.

http://www.postgresql.org/docs/9.0/static/auth-pg-hba-conf.html

share|improve this answer
add comment

you must add the auth setting on your

~postgres/VERSION/data/pg_hba.conf

e.g: for localhost
host    all             all             127.0.0.1/32            ident

e.g: full conf:
local   all             all                                     ident
host    all             all             127.0.0.1/32            ident
host    all             myUser          127.0.0.1/32            ident

then reload the postgres

share|improve this answer
    
+1 Was about to post the same answer. –  Eduardo Melo May 12 '11 at 12:48
add comment

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.