下面主要是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'
---rz命令上传,最好是在postgres用户下
---解压
#tar xvf postgresql-9.1.3
---配置编译与安装
需要的安装包参考:
http://my.oschina.net/Kenyon/blog/83601 ,主要是
yum install -y perl-ExtUtils-Embed readline-devel zlib-develpam-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)
原文链接:https://www.f2er.com/postgresql/194883.html