PostgreSQL 是一个开源的对象关系型、高度可扩展、兼容 SQL 的数据库管理系统。本文将帮助您在 CentOS 5/6 和 RHEL 5/6 上安装 PostgreSQL 9.1。
第1步:添加 PostgreSQL Yum 存储库
第一步是在您的系统中安装 postgres 存储库,根据您的系统架构和操作系统使用以下命令之一。
CentOS/RHEL 5, 32-Bit:
# rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm
CentOS/RHEL 6, 32-Bit:
# rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpm
CentOS/RHEL 5, 64-Bit:
# rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-5.0-x86_64//pgdg-centos91-9.1-4.noarch.rpm
CentOS/RHEL 6, 64-Bit:
# rpm -Uvh http://yum.postgresql.org/9.1/redhat/rhel-6.3-x86_64/pgdg-centos91-9.1-4.noarch.rpm
步骤2:使用Yum安装PostgreSQL Server 9.1。
以下命令将在您的系统上安装 PostgreSQL 9.1。
# yum install postgresql91-server
样本输出
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* epel: mirror.yourconnect.com
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql91-server.i686 0:9.1.9-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql91 = 9.1.9-1PGDG.rhel6 for package: postgresql91-server-9.1.9-1PGDG.rhel6.i686
--> Processing Dependency: libpq.so.5 for package: postgresql91-server-9.1.9-1PGDG.rhel6.i686
--> Running transaction check
---> Package postgresql91.i686 0:9.1.9-1PGDG.rhel6 will be installed
---> Package postgresql91-libs.i686 0:9.1.9-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================
Package Arch Version Repository Size
====================================================================================================
Installing:
postgresql91-server i686 9.1.9-1PGDG.rhel6 pgdg91 3.6 M
Installing for dependencies:
postgresql91 i686 9.1.9-1PGDG.rhel6 pgdg91 973 k
postgresql91-libs i686 9.1.9-1PGDG.rhel6 pgdg91 192 k
Transaction Summary
====================================================================================================
Install 3 Package(s)
Total download size: 4.7 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql91-9.1.9-1PGDG.rhel6.i686.rpm | 973 kB 00:02
(2/3): postgresql91-libs-9.1.9-1PGDG.rhel6.i686.rpm | 192 kB 00:02
(3/3): postgresql91-server-9.1.9-1PGDG.rhel6.i686.rpm | 3.6 MB 00:07
----------------------------------------------------------------------------------------------------
Total 321 kB/s | 4.7 MB 00:15
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : postgresql91-libs-9.1.9-1PGDG.rhel6.i686 1/3
Installing : postgresql91-9.1.9-1PGDG.rhel6.i686 2/3
Installing : postgresql91-server-9.1.9-1PGDG.rhel6.i686 3/3
Installed:
postgresql91-server.i686 0:9.1.9-1PGDG.rhel6
Dependency Installed:
postgresql91.i686 0:9.1.9-1PGDG.rhel6 postgresql91-libs.i686 0:9.1.9-1PGDG.rhel6
Complete!
步骤3:安装后首次初始化PGDATA
安装PostgreSQL服务器后,首次使用前需要对其进行初始化。要初始化数据库,请使用以下命令。
# /etc/init.d/postgresql-9.1 initdb
上面的命令第一次初始化 postgres 需要一些时间。 PGDATA 环境变量包含数据目录的路径。
PostgreSQL 数据目录路径
/var/lib/pgsql/9.1/data/
旧版本(PostgreSQL 7 或 8)默认使用以下路径作为数据目录。
/var/lib/pgsql/data/
步骤 4:启动 PostgreSQL 服务器
使用以下命令启动 postgresql 服务。
# service postgresql-9.1 start
设置 PostgreSQL 服务在系统启动时自动启动。
# chkconfig postgresql-9.1 on
第 5 步:访问 PostgreSQL 管理命令提示符。
要以管理员用户身份访问 postgres,首先切换到 postgres 系统帐户。
# su - postgres
使用 psql 命令以管理员权限访问 postgres 提示符。
$ psql
示例输出:
psql (9.1.9)
Type "help" for help.
postgres=#
阅读下面的文章了解如何安装 phpPgAdmin。
>>如何使用 Yum 在 CentOS 上安装 phpPgAdmin
感谢您使用本教程在 CentOS 5/6 和 RHEL 5/6 系统上安装 PostgreSQL 9.1。