CentOS下PostregSQL 9.2和pg安装小记

1) 先介绍环境

uname -a 查看如下
Linux srv13.madeforchina.com 2.6.18-128.2.1.el5 #1 SMP Tue Jul 14 06:36:37 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

vim /etc/redhat-release
CentOS release 5.3 (Final) Tikanga

2)yum

默认的yum源只会安装8.1版本。去这个地方http://www.pgrpms.org/reporpms/repoview/letter_p.group.html 找相应的9.2版本,下载,然后rpm -ivh pgdg-centos92-9.2-6.noarch.rpm。
现在yum list |grep postgresql 应该能看到一堆postgresql92开头的包。

然后安装
yum install postgresql92 postgresql92-server postgresql92-libs postgresql92-contrib postgresql92-devel

3)database和服务配置

su root
service postgresql-9.2 initdb  #初始化数据库
service postgresql-9.2 start   #启动服务,可以start|stop|restart|status|initdb
chkconfig --list    #查看所有后台服务
chkconfig postgresql-9.2 on   #打开postgresql服务

默认的数据库文件在/var/lib/pgsql/9.2/data。

连接服务器:

su postgres
psql -p 5432 #5432是默认端口
CREATE role regina LOGIN PASSWORD 'whateveryouwant' SUPERUSER; #不知道干嘛

如果需要自定义配置,可以新建配置文件/etc/sysconfig/pgsql/postgresql-9.2

PGPORT=5433  #自定义端口号
PGDATA=/data/pgdata92  #自定义数据文件路径

(以上可以参考http://www.postgresonline.com/journal/archives/203-An-almost-idiots-guide-to-Install-PostgreSQL-9.0-with-Yum.html)

4) pg

gem install pg -- --with-pg=/usr/pgsql-9.2 (postgresql默认安装目录)

如果是利用capistrano部署,修改deploy.rb(如果是multistage,也可以修改deploy下的 staging.rb或者production.rb ),添加如下代码

before "bundle:install" do
  run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg=/usr/pgsql-9.2"
end

posted @ 2012-10-12 17:43  我的白日梦  阅读(1297)  评论(0编辑  收藏  举报