FATAL: Peer authentication failed for user "postgres" 解决方法

   使用如下命令创建数据库mydb时,会抛出错误:

[root@April ~]# createdb mydb 
createdb: could not connect to database template1: FATAL:  role "root" does not exist

    mydb是待创建的数据库名称,root是用户名。由于在postgreSQL数据库中没有名为root的role,所以需要用参数 -U postgres来指定一个存在的role。

[root@April ~]# createdb mydb -U postgres
createdb: could not connect to database template1: FATAL:  Peer authentication failed for user "postgres"

    此时抛出了认证的错误Peer authentication failed for user "postgres",解决方法如下:

1.编辑pg_hba.conf文件

vim /var/lib/pgsql/9.2/data/pg_hba.conf

2.将其中的配置

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     peer

    修改为

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     trust

3.重启系统

[root@April etc]# reboot

4.重新创建数据库

[root@April ~]# createdb mydb -U postgres

    此时,数据库mydb创建成功。

猜你喜欢

转载自blog.csdn.net/liyazhen2011/article/details/88977424