手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS 6.2 上 PostgreSQL 9.1 的使用

[日期:2013-01-09] 来源:Linux社区  作者:archimedes_zht [字体:大 中 小]

前一篇文章(http://www.linuxidc.com/Linux/2013-01/77433.htm)在用yum安装好postgresql之后,就可以通过service来管理它了。这个postgresql-9.1 的位置在

/etc/rc.d/init.d/postgresql-9.1

可以看到它里面默认使用了一个名为postgres的OS用户名(从这个脚本可以看到很多yum在安装postgresql后的目录位置、环境变量等)。这个postgres用户名就是(http://www.postgresql.org/docs/9.1/static/database-roles.html)这里提到的

In order to bootstrap the database system, a freshly initialized system always contains one predefined role. This role is always a "superuser", and by default (unless altered when running initdb) it will have the same name as the operating system user that initialized the database cluster. Customarily, this role will be named postgres. In order to create more roles you first have to connect as this initial role.

也就是说,系统会默认创建一个role,而且这个role在不指定(可以通过initdb指定)的情况下,它的name和当前初始化数据库实例的OS用户的name一样的。一般这个name就是postgres。从/etc/rc.d/init.d/postgresql-9.1里面也可以看到,脚本会把很多文件和文件夹的owner设置为postgres。

所以当你刚安装好postgres,迫不及待的想通过psql连接数据库的时候都会遇到(http://www.postgresql.org/docs/9.1/static/tutorial-createdb.html)这里提到的错误。因为psql认为你要使用当前的OS用户的name去连接数据库。错误如下:

createdb: could not connect to database postgres: FATAL:  role "joe" does not exist

当然,如果你自己的OS用户的name就是postgres,那你运气就太好了。:D

所以你需要

su - postgres

来切换到postgres用户下去,然后一个简单的:

psql

就可以顺利的连接到数据库了。

然后\password 可以修改你的密码。

在postgres下面

createuser root

切换到root下面后,就可以

createdb

默认创建名为root的数据库。然后psql命令就可以连接到数据库了。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款