我们知道pg_upgrade和pg_dump/pg_restore可以实现大版本升级数据库,那么小版本如何升级,比如从9.6.3到9.6.5?
原理:用新版本的软件程序启动,指定老的的数据目录
安装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