在postgres中创build数据库时出错

我想在linux服务器上创build用户和数据库。 我能够用下面的代码创build用户:

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

但是当我试图用代码创build数据库时:

 # createdb -U myUser -p 5432 myDatabase 

我得到以下错误:

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

我是新来的Linux,所以我无法弄清楚为什么我能够创build用户,但创build数据库时,与postgres连接错误。 而且用户的身份validation错误。

您需要了解有关HBAconfiguration的更多信息。

有一些基本的authentication方法:

  • 信任 – 每个用户都可以连接到第二列指定的数据库,其中所有的数据库都是集群中的所有数据库(是的,不包括template0,因为pg_database系统目录中的datallowconn设置为false .. nevermind)
  • ident (在PostgreSQL 8.4 ident相同的用户之前) – 仅实际logging(例如,在控制台中使用su作为su - postgres )系统用户(与angular色名称相同)可以连接
  • md5 – 每个知道angular色(PostgreSQL)密码的用户都可以login数据库

每次你试图连接到具体的angular色数据库,即使不写是明确的。

一般有两种连接types:

  • 本地 – Unix域套接字
  • 主机 – 使用TCP / IP连接

如果你不知道你在用什么,那么它是本地的。 要使用TCP / IP连接,您需要在postmaster正在侦听的目标IP中指定-h选项。 例如,您可以添加-h localhost或-h 127.0.0.1,但请检查postgresql.conf中的listen_adresses(AFAIK默认值是localhost,因此可以)属性,并检查HBA中接受的客户端IP地址。

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

你必须添加auth设置你的

〜postgres的/ VERSION /数据/的pg_hba.conf

 eg: for localhost host all all 127.0.0.1/32 ident eg: full conf: local all all ident host all all 127.0.0.1/32 ident host all myUser 127.0.0.1/32 ident 

然后重新加载postgres