安装介质下载:
http://www.postgresql.org/ftp/source/
安装操作系统包
[root@pgsql1 ~]# mkdir /media/rhel
[root@pgsql1 ~]# mount /dev/cdrom /media/rhel
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@pgsql1 ~]# vi /etc/yum.repos.d/rhel6.repo
[Server]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
baseurl=file:///media/rhel
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@pgsql1 ~]# yum clean all
[root@pgsql1 ~]# yum list
[root@pgsql1 ~]# yum install *readline* *zlib* gcc -y
其中readline包的作用是在psql中使用上下键翻查历史记录;zlib包的作用是支持安装时数据库的压缩功能;gcc包的作用是后面gmake会用到。
解压
[root@pgsql1 opt]# tar -zxvf postgresql-9.2.10.tar.gz
创建安装目录
[root@pgsql1 opt]# mkdir pgsql9210
编译安装第一步
[root@pgsql1 postgresql-9.2.10]# ./configure --prefix=/opt/pgsql9210/
编译安装第二步
[root@pgsql1 postgresql-9.2.10]# gmake world
PostgreSQL, contrib, and documentation successfully made. Ready to install.
编译安装第三步
[root@pgsql1 postgresql-9.2.10]# gmake install-world
PostgreSQL, contrib, and documentation installation complete.
创建用户postgres
[root@pgsql1 postgresql-9.2.10]# useradd postgres
配置用户的环境变量
[root@pgsql1 postgresql-9.2.10]# vi /home/postgres/.bash_profile
export PGBASE=/opt/pgsql9210
export PGUSER=postgres
export PGPORT=5432
export PGDATA=/opt/pgsql9210/data
export PATH=$PGBASE/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGBASE/lib:$LD_LIBRARY_PATH
创建数据库的数据目录
[root@pgsql1 pgsql9210]# mkdir data
[root@pgsql1 pgsql9210]# chown postgres:postgres data/
创建数据库簇:
[root@pgsql1 pgsql9210]# su - postgres
[postgres@pgsql1 ~]$ initdb --locale=C --encoding=UTF8
启动数据库
[postgres@pgsql1 data]$ pg_ctl start
查看数据库
[postgres@pgsql1 data]$ psql
psql (9.2.10)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)