PostgreSQL 的 rpm(yum) 安装方法

1 minute read

背景

一般情况下, 我们安装PostgreSQL都是通过源码编译安装的, 如果你的场景中不允许使用make或gcc的话, 可以选择下载rpm包安装或下载EDB提供的bin文件安装.

EDB :

http://www.enterprisedb.com/products-services-training/pgdownload

rpm :

http://yum.postgresql.org/

当然, 你也可以自己创建属于自己的rpm

http://www.rpm.org/max-rpm-snapshot/rpmbuild.8.html

使用rpm安装的例子

我这个例子在docker环境中安装测试 :

首先至少要下载以下4个rpm包.

PostgreSQL Database Server 9.3 PGDG

postgresql93 - PostgreSQL client programs and libraries  
  
postgresql93-contrib - Contributed source and binaries distributed with PostgreSQL  
  
postgresql93-libs - The shared libraries required for any PostgreSQL clients  
  
postgresql93-server - The programs needed to create and run a PostgreSQL server  

到这里下载 :

http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/

地址(如果你需要其他的插件,下载即可,比如plpython,下载相应的RPM安装之) :

http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-server-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-contrib-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-libs-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-pltcl-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-plperl-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-plpython-9.3.5-1PGDG.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgfincore93-1.1.1-1.rhel6.x86_64.rpm
http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/postgresql93-devel-9.3.5-1PGDG.rhel6.x86_64.rpm

下载好后, 启动一个docker, 把包拷贝到container环境中, 直接安装.

如果你不是在docker中安装,请忽略。

注意contrib, 以及几个函数语言包可能需要依赖一些包, 如果在docker image中么有的话, 建议使用yum安装, 自动安装依赖的包.

从centos 6 x64的镜像启动container :

[root@150 ~]# docker run -t -i --rm --net="host" centos:centos6 /bin/bash  
  
bash-4.1# rpm -ivh postgresql93-libs-9.3.5-1PGDG.rhel6.x86_64.rpm  
bash-4.1# rpm -ivh postgresql93-9.3.5-1PGDG.rhel6.x86_64.rpm  
bash-4.1# rpm -ivh postgresql93-server-9.3.5-1PGDG.rhel6.x86_64.rpm  
bash-4.1# yum install -y postgresql93-contrib-9.3.5-1PGDG.rhel6.x86_64.rpm  
bash-4.1# yum install -y postgresql93-plperl-9.3.5-1PGDG.rhel6.x86_64.rpm postgresql93-plpython-9.3.5-1PGDG.rhel6.x86_64.rpm postgresql93-pltcl-9.3.5-1PGDG.rhel6.x86_64.rpm  
bash-4.1# yum install -y postgresql93-devel-9.3.5-1PGDG.rhel6.x86_64.rpm pgfincore93-1.1.1-1.rhel6.x86_64.rpm  

安装好后, 使用rpm -ql检查一下安装到哪里去了,因为我们需要编写环境变量.

bash-4.1# rpm -ql postgresql93-server  
/etc/pam.d/postgresql93  
/etc/rc.d/init.d/postgresql-9.3  
/etc/sysconfig/pgsql  
/usr/pgsql-9.3/bin/initdb  
/usr/pgsql-9.3/bin/pg_controldata  
/usr/pgsql-9.3/bin/pg_ctl  
/usr/pgsql-9.3/bin/pg_resetxlog  
/usr/pgsql-9.3/bin/postgres  
/usr/pgsql-9.3/bin/postmaster  
...  

大部分文件在/usr/pgsql-9.3, 作为$PGHOME

到postgres用户下, 修改.bash_profile

bash-4.1# su - postgres  
  
-bash-4.1$ vi .bash_profile   
  
[ -f /etc/profile ] && source /etc/profile  
PGDATA=/var/lib/pgsql/9.3/data  
export PGDATA  
  
export PGHOME=/usr/pgsql-9.3  
export PATH=$PGHOME/bin:$PATH  
export MANPATH=$PGHOME/share/man:$MANPATH  
alias rm='rm -i'  
alias ll='ls -la'  

查看一下postgresql rpm包的编译参数 :

-bash-4.1$ pg_config  
  
BINDIR = /usr/pgsql-9.3/bin  
DOCDIR = /usr/share/doc/pgsql  
HTMLDIR = /usr/share/doc/pgsql  
INCLUDEDIR = /usr/pgsql-9.3/include  
PKGINCLUDEDIR = /usr/pgsql-9.3/include  
INCLUDEDIR-SERVER = /usr/pgsql-9.3/include/server  
LIBDIR = /usr/pgsql-9.3/lib  
PKGLIBDIR = /usr/pgsql-9.3/lib  
LOCALEDIR = /usr/pgsql-9.3/share/locale  
MANDIR = /usr/pgsql-9.3/share/man  
SHAREDIR = /usr/pgsql-9.3/share  
SYSCONFDIR = /etc/sysconfig/pgsql  
PGXS = /usr/pgsql-9.3/lib/pgxs/src/makefiles/pgxs.mk  
CONFIGURE = '--disable-rpath' '--prefix=/usr/pgsql-9.3' '--includedir=/usr/pgsql-9.3/include' '--mandir=/usr/pgsql-9.3/share/man' '--datadir=/usr/pgsql-9.3/share' '--with-perl' '--with-python' '--with-tcl' '--with-tclconfig=/usr/lib64' '--with-openssl' '--with-pam' '--with-krb5' '--with-gssapi' '--with-includes=/usr/include' '--with-libraries=/usr/lib64' '--enable-nls' '--with-ossp-uuid' '--with-libxml' '--with-libxslt' '--with-ldap' '--with-system-tzdata=/usr/share/zoneinfo' '--sysconfdir=/etc/sysconfig/pgsql' '--docdir=/usr/share/doc' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et' 'CPPFLAGS= -I/usr/include/et'  
CC = gcc  
CPPFLAGS = -I/usr/include/et -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include  
CFLAGS = -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/include/et -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv  
CFLAGS_SL = -fpic  
LDFLAGS = -L../../../src/common -L/usr/lib64 -Wl,--as-needed  
LDFLAGS_EX =   
LDFLAGS_SL =   
LIBS = -lpgport -lpgcommon -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lcrypt -ldl -lm   
VERSION = PostgreSQL 9.3.5  

初始化一个数据库集群

bash-4.1# su - postgres  
-bash-4.1$ initdb -D ./pg_root -E UTF8 --locale=C -U postgres -W  

打包 docker 镜像 :

[root@150 ~]# docker commit -a "digoal" -m "postgres9.3.5 install by rpm on Centos6 x64" -p 57da29cec89e 172.16.3.221:5000/postgres:9.3.5_rpm  
59d6cd3a518139fb28d2f6cef228cafeb1d3582a29851b19d4f1e03b0175e45d  
  
[root@150 ~]# docker push 172.16.3.221:5000/postgres:9.3.5_rpm  

[参考]
1. http://yum.postgresql.org/

2. http://yum.postgresql.org/files/PostgreSQL-RPM-Installation-PGDG.pdf

3. http://www.postgresql.org/download/linux/redhat/

4. http://www.postgresql.org/download/linux/redhat/#yum

5. http://yum.postgresql.org/9.3/redhat/rhel-6.5-x86_64/

6. https://wiki.postgresql.org/wiki/YUM_Installation

Flag Counter

digoal’s 大量PostgreSQL文章入口