Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

1.3. PostgreSQL 官方 YUM 源安装

CentOS 6.4 环境 YUM 地址 http://yum.postgresql.org/

1.3.1. 9.2

# yum install http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
# yum list postgres*

# yum install postgresql92-server postgresql92

chkconfig postgresql-9.2 on
service postgresql-9.2 initdb
service postgresql-9.2 start
			

配置文件的位置

# ls /var/lib/pgsql/9.2/data/*.conf
/var/lib/pgsql/9.2/data/pg_hba.conf  /var/lib/pgsql/9.2/data/pg_ident.conf  /var/lib/pgsql/9.2/data/postgresql.conf
			

1.3.2. 9.3

# yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
# yum install postgresql93-server postgresql93
			
# chkconfig postgresql-9.3 on
# service postgresql-9.3 initdb
# service postgresql-9.3 start			
			

9.2 升级到 9.3

备份数据库

# su - postgres
$ pg_dump -f wechat.sql wechat
			

升级数据库

关闭9.2,启动9。3

# chkconfig postgresql-9.2 off
# service postgresql-9.2 stop

# service postgresql-9.3 start
			

回复数据库

# su - postgres
$ createuser -r -s -P dba
$ createuser -P wechat
$ createdb -E UTF8 -O wechat wechat
$ cat wechat.sql | psql wechat
			

合并配置文件

$ cp 9.3/data/postgresql.conf{,.original}
$ cp 9.3/data/pg_hba.conf{,.original}
$ vimdiff 9.2/data/postgresql.conf 9.3/data/postgresql.conf
$ vimdiff 9.2/data/pg_hba.conf 9.3/data/pg_hba.conf
			

注意 vimdiff 命令是文件对比于合并工具,建议你选择你比较熟悉的工具。

# service postgresql-9.3 restart
			

1.3.3. 9.4

CentOS 6

https://github.com/oscm/shell/blob/master/database/postgresql/postgresql93-centos6.sh

CentOS 7

https://github.com/oscm/shell/blob/master/database/postgresql/postgresql93-centos7.sh

			
#!/bin/bash

# CentOS 7
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install -y postgresql96-server postgresql96-contrib

systemctl initdb postgresql-9.6
chkconfig postgresql-9.6 on

cp /var/lib/pgsql/9.6/data/postgresql.conf{,.original}
cp /var/lib/pgsql/9.6/data/pg_hba.conf{,.original}
cp /var/lib/pgsql/9.6/data/pg_ident.conf{,.original}

sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" /var/lib/pgsql/9.6/data/postgresql.conf

systemctl start postgresql-9.6

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
systemctl save iptables			
			
			

一键安装

			
curl -s https://raw.githubusercontent.com/oscm/shell/master/database/postgresql/postgresql93-centos7.sh | bash
			
			

1.3.4. 9.6

https://github.com/oscm/shell/blob/master/database/postgresql/postgresql96-centos7.sh

一键安装

			
curl -s https://raw.githubusercontent.com/oscm/shell/master/database/postgresql/postgresql96-centos7.sh | bash
			
			

1.3.5. 10

一键安装 PostgreSQL 10

			
curl -s https://raw.githubusercontent.com/oscm/shell/master/database/postgresql/10/repository.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/database/postgresql/10/postgresql-server.sh | bash