下面主要是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 python
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' linux
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) c++