CentOS 6.5系统下安装postgresql数据库+postgis+pgagent+pgadmin工具


CentOS 6.5系统下安装postgresql数据库+postgis+pgagent+pgadmin工具

本文档主要记录在一个全新的centos6.5系统下安装postgresql数据以及其他相关工具的步骤和注意事项。postgresql的其他工具的安装方式也是类似的。
检查是否有pg数据库的源:
命令:
yum list postgres*
如无结果,则说明当前系统未引用pg数据库相关的yum源,需要先安装pg的yum源,安装命令如下:
rpm -Uvh https://yum.postgresql.org/9.5/redhat/rhel-6.5-x86_64/pgdg-centos95-9.5-3.noarch.rpm

下载的是pg9.5版本的源。
再次运行yum list postgres*命令,结果如下:

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
base                                                                                           | 3.7 kB     00:00     
extras                                                                                         | 3.4 kB     00:00     
google-chrome                                                                                  |  951 B     00:00     
pgdg95                                                                                         | 4.1 kB     00:00     
pgdg95/primary_db                                                                              | 176 kB     00:02     
updates                                                                                        | 3.4 kB     00:00     
updates/primary_db                                                                             | 5.4 MB     00:05     
Available Packages
postgresql.i686                                               8.4.20-6.el6                                      base  
postgresql.x86_64                                             8.4.20-6.el6                                      base  
postgresql-contrib.x86_64                                     8.4.20-6.el6                                      base  
postgresql-devel.i686                                         8.4.20-6.el6                                      base  
postgresql-devel.x86_64                                       8.4.20-6.el6                                      base  
postgresql-docs.x86_64                                        8.4.20-6.el6                                      base  
postgresql-jdbc.noarch                                        42.0.0-1.rhel6                                    pgdg95
postgresql-jdbc-javadoc.noarch                                42.0.0-1.rhel6                                    pgdg95
postgresql-libs.i686                                          8.4.20-6.el6                                      base  
postgresql-libs.x86_64                                        8.4.20-6.el6                                      base  
postgresql-odbc.x86_64                                        08.04.0200-1.el6                                  base  
postgresql-plperl.x86_64                                      8.4.20-6.el6                                      base  
postgresql-plpython.x86_64                                    8.4.20-6.el6                                      base  
postgresql-pltcl.x86_64                                       8.4.20-6.el6                                      base  
postgresql-server.x86_64                                      8.4.20-6.el6                                      base  
postgresql-test.x86_64                                        8.4.20-6.el6                                      base  
postgresql-unit95.x86_64                                      1.0-1.rhel6                                       pgdg95
postgresql-unit95-debuginfo.x86_64                            1.0-1.rhel6                                       pgdg95
postgresql94-jdbc.noarch                                      9.4.1207-1.rhel6                                  pgdg95
postgresql94-jdbc-javadoc.noarch                              9.4.1207-1.rhel6                                  pgdg95
postgresql95.x86_64                                           9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-contrib.x86_64                                   9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-debuginfo.x86_64                                 9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-devel.x86_64                                     9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-docs.x86_64                                      9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-libs.x86_64                                      9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-odbc.x86_64                                      09.06.0100-1PGDG.rhel6                            pgdg95
postgresql95-odbc-debuginfo.x86_64                            09.03.0400-1PGDG.rhel6                            pgdg95
postgresql95-plperl.x86_64                                    9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-plpython.x86_64                                  9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-pltcl.x86_64                                     9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-server.x86_64                                    9.5.6-2PGDG.rhel6                                 pgdg95
postgresql95-tcl.x86_64                                       2.0.0-1.rhel6                                     pgdg95
postgresql95-tcl-debuginfo.x86_64                             2.0.0-1.rhel6                                     pgdg95
postgresql95-test.x86_64 

数据库安装

可以看到,现在有若干pg的源可以使用。
运行安装命令:

   yum install postgresql95-devel.x86_64
   yum install postgresql95-server.x86_64
   yum install postgresql95-contrib.x86_64

即可安装64位版pg9.5数据库。PG数据库默认会安装到/usr/pgsql-9.5 目录下,在此目录下手动创建data文件夹,用来作为数据目录。

配置环境变量
在etc目录下,打开profile文件,增加如下内容:

export PGHOME=/usr/pgsql-9.5
export PGDATA=/usr/pgsql-9.5/data
export PATH=$PATH:$PGHOME/bin

保存退出后,运行source profile重新加载环境变量;

创建postgres用户
使用root用户为PG数据库创建管理员用户postgres,并调整PGHOME相关文件夹权限;

useradd postgres
chown -R postgres:postgres /usr/pgsql-9.5

初始化数据库

上述准备工作完成后,在安装目录的/usr/pgsql-9.5/bin目录下执行initdb命令:

./initdb -U postgres -W -D /usr/pgsql-9.5/data/data

根据提示设置postgres用户密码后,即可完成初始化,之后即可启动数据库;

另外
在下载pg数据库yum源的地址时,同时包含了pg其他相关的工具源,如pgagent、postgis等。
执行命令:yum list postgis*可以查看到postgis的可用源,安装方式和pg数据库类似,不再赘述。

同样pgAgent和pgadmin工具安装方式类似,不再赘述;

此次安装最重要的步骤就是安装pg的yum源,之后就可以直接使用yum安装。

转载自:https://blog.csdn.net/arcticJian/article/details/54405776

You may also like...

退出移动版