PostgreSQL在CentOS下的源码安装

下面主要是PostgreSQL在CentOS下的安装步骤,和Linux步骤基本类似。

1.环境:
操作系统:CentOS-6.2-x86_64
虚拟机:Vmware-workstation 6.5
数据库:postgresql-9.1.3
工具: SecureCRT 5.1.2

2.加用户和组(root下操作)
#groupadd postgres
#useradd postgres -g postgres
#passwd  postgres

--root下创建数据库数据存放文件
#mkdir -p /database/pgdata
#cd /database
#chown -R postgres:postgres  ./pgdata
 

3.修改环境变量
[postgres@localhost ~]$ vi .bash_profile
新增
export PGPORT=1233
export PGHOME=/home/postgres
export PGDATA=/database/pgdata
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.utf8
export DATE=`date +"%Y-%m-%d %H:%M:%S"`
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

alias pg_stop='pg_ctl -D $PGDATA stop -m fast'
alias pg_start='pg_ctl -D $PGDATA start'
alias pg_reload='pg_ctl -D $PGDATA reload'

4.上传数据库安装包,并解压安装
---rz命令上传,最好是在postgres用户下
---解压
#tar xvf  postgresql-9.1.3
---配置编译与安装

需要的安装包参考:
http://my.oschina.net/Kenyon/blog/83601  ,主要是 
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++      openssl-devel cmake   

#cd postgresql-9.1.3 
# ./configure --prefix=/home/postgres --with-pgport=1233  --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety 
---具体的configure 可以用configure --help来查看 
---编译 
#gmake world 
---建议用gmake而不是make来做,完成后,最后会显示信息: 
gmake -C config all 
gmake[1]: Entering directory `/home/postgres/postgresql-9.1.3/config' 
gmake[1]: Nothing to be done for `all'. 
gmake[1]: Leaving directory `/home/postgres/postgresql-9.1.3/config' 
All of PostgreSQL successfully made. Ready to install.

---安装,带world参数可以安装PG的附属信息,如文档,帮助等 
#gmake install-world 
---成功安装后显示: 
gmake[1]: Leaving directory `/home/postgres/postgresql-9.1.3/config'
PostgreSQL installation complete.
gmake: Leaving directory `/home/postgres/postgresql-9.1.3'

5.创建初始数据库
[root@localhost /]# su - postgres
[postgres@localhost ~]$ initdb -D /database/pgdata -E UTF8 --locale=C -U postgres -W
完成后可以看到提示:
Success. You can now start the database server using:
    postgres -D /database/pgdata
or
    pg_ctl -D /database/pgdata -l logfile start


6.启动与关闭数据库
启动,指定日志:
pg_ctl -D $PGDATA -l /home/postgres/pgsql.log start
关闭:
pg_ctl -D $PGDATA stop

7.登陆数据库
[postgres@localhost ~]$ psql
psql (8.4.9, server 9.1.3)
WARNING: psql version 8.4, server version 9.1.
         Some psql features might not work.
Type "help" for help.

postgres=# select version();
                                                   version                                                    
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.1.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 64-bit
(1 row)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值