共计 3428 个字符,预计需要花费 9 分钟才能阅读完成。
我们知道 pg_upgrade 和 pg_dump/pg_restore 可以实现大版本升级数据库,那么小版本如何升级,比如从 9.6.3 到 9.6.5?
原理:用新版本的软件程序启动,指定老的的数据目录
PostgreSQL 大版本升级 pg_upgrade http://www.linuxidc.com/Linux/2017-11/148184.htm
安装 pgsql9.6.3
mkdir -p /usr/local/pgsql/pgsql9.6.3/{data,arch}
groupadd dba
useradd -g dba -G root postgres -d /usr/local/pgsql
tar xf postgresql-9.6.3.tar.gz
chmod -R 755 /usr/local/pgsql
chown -R postgres:dba /usr/local/pgsql
chmod -R 700 /usr/local/pgsql/pgsql9.6.3/data/
./configure –prefix=/usr/local/pgsql/pgsql9.6.3/
make world && make install-world
cd /usr/local/pgsql/pgsql9.6.3/bin
./initdb -D /usr/local/pgsql/pgsql9.6.3/data -U postgres -E UTF8 -W
vim pg_hba.conf
host all all 0.0.0.0/0 md5
vim postgresql.conf
listen_addresses = ‘*’
wal_level = replica
port = 5432
max_connections = 300
shared_buffers = 128MB
logging_collector = on
log_directory = ‘pg_log’
log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’
archive_mode = on
archive_command = ‘test ! -f /usr/local/pgsql/pgsql9.6.5/arch/%f && cp %p /usr/local/pgsql/pgsql9.6.5/arch/%f’
/usr/local/pgsql/pgsql9.6.3/bin/pg_ctl start -D /usr/local/pgsql/pgsql9.6.3/data
# 生成测试数据
create database testdb1;
\c testdb1;
create table t1(id int primary key, info text);
insert into t1 select generate_series(1,1000000),’helloWorld’;
安装 pgsql9.6.5
mkdir -p /usr/local/pgsql/pgsql9.6.5/{data,arch}
groupadd dba
useradd -g dba -G root postgres -d /usr/local/pgsql
tar xf postgresql-9.6.5.tar.gz
chmod -R 755 /usr/local/pgsql
chown -R postgres:dba /usr/local/pgsql
chmod -R 700 /usr/local/pgsql/pgsql9.6.5/data/
./configure –prefix=/usr/local/pgsql/pgsql9.6.5/
make world && make install-world
cd /usr/local/pgsql/pgsql9.6.5/bin
/usr/local/pgsql/pgsql9.6.5/bin/initdb -D /usr/local/pgsql/pgsql9.6.5/data -U postgres -E UTF8 -W
vim pg_hba.conf
host all all 0.0.0.0/0 md5
vim postgresql.conf
listen_addresses = ‘*’
wal_level = replica
port = 5431
max_connections = 300
shared_buffers = 128MB
logging_collector = on
log_directory = ‘pg_log’
log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log’
archive_mode = on
archive_command = ‘test ! -f /usr/local/pgsql/pgsql9.6.5/arch/%f && cp %p /usr/local/pgsql/pgsql9.6.5/arch/%f’
/usr/local/pgsql/pgsql9.6.5/bin/pg_ctl start -D /usr/local/pgsql/pgsql9.6.5/data
/usr/local/pgsql/pgsql9.6.5/bin/pg_ctl stop -m fast -D /usr/local/pgsql/pgsql9.6.5/data
# 停止老的数据库 9.6.3
/usr/local/pgsql/pgsql9.6.3/bin/pg_ctl stop -m fast -D /usr/local/pgsql/pgsql9.6.3/data
# 用 9.6.5 的软件程序启动,指定 9.6.3 的数据目录
/usr/local/pgsql/pgsql9.6.5/bin/pg_ctl start -D /usr/local/pgsql/pgsql9.6.3/data
postgres=# select version();
version
———————————————————————————————————
PostgreSQL 9.6.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
testdb1=# select count(*) from t1;
count
———
1000000
Ubuntu 16.04 下安装 PostgreSQL 和 phpPgAdmin http://www.linuxidc.com/Linux/2016-08/134260.htm
Linux 下 RPM 包方式安装 PostgreSQL http://www.linuxidc.com/Linux/2016-03/128906.htm
Linux 下安装 PostgreSQL http://www.linuxidc.com/Linux/2016-12/138765.htm
Linux 下 PostgreSQL 安装部署指南 http://www.linuxidc.com/Linux/2016-11/137603.htm
Linux 下安装 PostgreSQL 并设置基本参数 http://www.linuxidc.com/Linux/2016-11/137324.htm
Ubuntu 16.04 下 PostgreSQL 主从复制配置 http://www.linuxidc.com/Linux/2017-08/146190.htm
Fedota 24 将数据库升级到 PostgreSQL 9.5 http://www.linuxidc.com/Linux/2016-11/137374.htm
CentOS7 安装配置 PostgreSQL9.6 http://www.linuxidc.com/Linux/2017-10/147536.htm
CentOS5.8_x64 下离线安装 PostgreSQL 9.1 http://www.linuxidc.com/Linux/2017-10/147822.htm
CentOS 6.5 下 PostgreSQL 服务部署 http://www.linuxidc.com/Linux/2017-01/139144.htm
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-11/148185.htm