今天在redhat6.5虚拟机s上,安装PostgreSQL9.3.6。下面是简单的操作步骤
1. 系统环境
-
[postgres@localhost pg]$ lsb_release -a
-
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
-
Distributor ID: RedHatEnterpriseServer
-
Description: Red Hat Enterprise Linux Server release 6.5 (Santiago)
-
Release: 6.5
-
Codename: Santiago
数据库版本:postgresql-9.3.6
工具: SecureCRT
2. 添加postgres用户
-
#groupadd postgres
-
#useradd postgres -g postgres
-
#passwd postgres
创建数据保存位置
-
#mkdir -p /database/pg
-
#cd /database
-
#chown -R postgres:postgres pg
3.修改postgres环境变量
-
[postgres@localhost ~]$ vi .bash_profile
-
新增
-
export PGPORT=1233
-
export PGHOME=/home/postgres
-
export PGDATA=/database/pg
-
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. 通过yum安装依赖关系包
-
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
5. 上传源码包并解决
-
[postgres@localhost ~]$ tar -zxvf postgresql-9.3.6.tar.gz
-
[postgres@localhost ~]$ cd postgresql-9.3.6
-
[postgres@localhost ~]$ ./configure --prefix=/home/postgres --with-pgport=1233 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety
-
[postgres@localhost ~]$ make && make install
-
[postgres@localhost bin]$ 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数据库的启动和停止
-
启动数据库并指定日志
-
pg_ctl -D $PGDATA -l /home/postgres/pgsql.log start
-
关闭数据库
-
pg_ctl -D $PGDATA stop
7.登录数据库并验证
-
[postgres@localhost bin]$ psql
-
psql (9.3.6)
-
Type "help" for help.
-
-
postgres=# select version();
-
version
-
--------------------------------------------------------------------------------------------------------------
-
PostgreSQL 9.3.6 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27039319/viewspace-1872048/
,如需转载,请注明出处,否则将追究法律责任。