pgsql安装

 

废话不多说,直接开始,
1、登陆Centos使用root用户登陆
下载postgresql   
#:wget http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.gz
解压:
#tar zxvf postgresql-9.2.4.tar.gz
进入解压后的目录
#cd postgresql-9.2.4
开始编译
#./configure
   -----------------------以下是我编译时遇到的错误----------------------
第一个问题:
    configure:error: in'/root/postgresql-9.2.4':
    configure:error: no acceptable C compiler foundin $PATH
原因是没有GCC安装即可
    #yum -y install gcc
第二问题:
    configure: error: readline library not found
少readline库,安装即可
    #yum -y install readline-devel 
第三个问题:
    configure: error: zlib library not found
安装zlib
    #yum -y install zlib-devel
也许每个人的问题都不一样,编译的时候找到错误提示,百度一下,应该可以有答案的,我遇到的也就是这三个
-----------------------------------------------------------------------
顺利能过以后:
#gmake
#gmake install 
到这里就完成安装,接下来就是配置了
2、环境变量(这里我使用VIM 文本编辑器,如果不会的使用其它的编辑器也可以的)
#vim .bash_profile
把:PATH=$PATH:$HOME/bin
改为:PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
保存退出,
让环境变量生效:
#. .bash_profile
 
3、建立数据库用户
#useradd postgres
更改用户目录(这一步可选)
#vim /etc/passwd
把
postgres:x:500:500::/home/postgres:/bin/bash
改为
postgres:x:500:500::/usr/local/pgsql:/bin/bash
删除用户目录:
rm -r /home/postgres
 
4、初始化数据库
新建数据目录:
#mkdir /usr/local/pgsql/data
更改权限:
#chown postgres:postgres /usr/local/pgsql/data
切换到刚刚建立的用户
#su postgres
$cd /usr/local/pgsql
$initdb -D data/
到这里数据的初始化就完成了。
5、接下来是系统服务了:
 回到root用户:
$exit
复制安装目录下的linux文件到/etc/init.d/
进入postgresql的安装目录,(即刚刚使用tar命令解压的目录)
#cd /root/postgresql-9.2.4
#cp contrib/start-scripts/linux /etc/init.d/postgresql
添加执行权限:
#chmod +x /etc/init.d/postgresql
启动数据库
#service postgresql start
Starting PostgreSQL: ok     大功告成了。
别激动还有一步呢,让数据库开机启动,
#chkconfig --add postgresql
#chkconfig postgresql on
等等好像还少一个东西:
数据库操作的历史记录文件
#touch /usr/local/pgsql/.psql_history
#chown postgres:postgres /usr/local/pgsql/.psql_history
测试一下:
#su postgres
$cd
$createdb test
$psql test
test=#create table test(id int);
CREATE TABLE
看来是完美完成了。
每个人的环境不一样,有错的地方请多指教。有问题可以留言,很乐意帮忙解决你的问题。
本文出自 “田尘殇SeanSnow” 博客,请务必保留此出处http://seansnow.blog.51cto.com/5656820/1198859

 

猜你喜欢

转载自lyjilu.iteye.com/blog/2212379