• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Never Give Up
天才在于勤奋,知识在于积累
博客园    首页    新随笔    联系   管理    订阅  订阅

解决createdb: could not connect to database postgres: FATAL: Peer authentication failed for user "postgres"

解决createdb: could not connect to database postgres: FATAL: Peer authentication failed for user "postgres"

操作系统: Ubuntu

 

运行下面的命令创建名为mydb的数据库

createdb mydb 

得到一个错误:psql: FATAL: role "terry" does not exist, terry是我的机器名, 在postgresql数据库中没有名为terry的role, 所以会报出这个错误, 只要加上-U参数来指定一个存在的role就可以了,所以我将上面的命令改为:

createdb mydb -U postgres

又得到一个错误:psql: FATAL:  Peer authentication failed for user "postgres", 解决办法如下:

1. 运行下面的命令编辑pg_hba.conf文件

sudo gedit /etc/postgresql/9.1/main/pg_hba.conf

2. 将

# Database administrative login by Unix domain socket
local   all             postgres                                peer

改为

# Database administrative login by Unix domain socket
local   all             postgres                                trust

3. 保存后执行下面的命令重新加载配置文件:

sudo /etc/init.d/postgresql reload

再执行 createdb mydb1 -U postgres , 已经成功的创建了mydb1数据库.

posted @ 2012-11-30 16:41  Terry Sun  阅读(23317)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3