[go: up one dir, main page]

0% found this document useful (0 votes)
22 views7 pages

Upgrade Postgresql 11 To 12

Uploaded by

Fadi Dib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Upgrade Postgresql 11 To 12

Uploaded by

Fadi Dib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

1-Install postgresql12 with packages as follows.

yum install postgresql12-contrib postgresql12-server

2-Sample initdb script

/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12

vi /var/lib/pgsql/12/data/postgresql.conf
port = 5433
systemctl start postgresql-12
systemctl status postgresql-12
systemctl stop postgresql-12
vi /var/lib/pgsql/12/data/postgresql.conf
data_directory = '/home/pgsql/12/data'
vi /lib/systemd/system/postgresql-12.service
Environment=PGDATA=/home/pgsql/12/data/
systemctl daemon-reload
yum install rsync
rsync -avz /var/lib/pgsql/12 /home/pgsql

systemctl start postgresql-12

systemctl status postgresql-12

3-Upgrade PostgreSQL 11 to 12

systemctl stop postgresql-11


systemctl stop postgresql-12

update pg_hba.conf postgresql-11 to connect to database without password

vi /home/pgsql/11/data/pg_hba.conf

# TYPE DATABASE USER ADDRESS METHOD


host all all 0.0.0.0/0 trust
# "local" is for Unix domain socket connections only
local all all trust

3.1 Upgrade Performing Consistency Checks

su postgres
/usr/pgsql-12/bin/pg_upgrade \ --old-datadir=/home/pgsql/11/data \ --new-
datadir=/home/pgsql/12/data \ --old-bindir=/usr/pgsql-11/bin \
--new-bindir=/usr/pgsql-12/bin \ --old-options '-c
config_file=/home/pgsql/11/data/postgresql.conf' \ --new-options '-c
config_file=/home/pgsql/12/data/postgresql.conf' \ -U postgres --old-port=5432 --
new-port=5433 -c --check

Performing Consistency Checks


-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for tables WITH OIDS ok
Checking for invalid "sql_identifier" user columns ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok

*Clusters are compatible*

Upgrade
/usr/pgsql-12/bin/pg_upgrade \ --old-datadir=/home/pgsql/11/data \ --new-
datadir=/home/pgsql/12/data \ --old-bindir=/usr/pgsql-11/bin \
--new-bindir=/usr/pgsql-12/bin \ --old-options '-c
config_file=/home/pgsql/11/data/postgresql.conf' \ --new-options '-c
config_file=/home/pgsql/12/data/postgresql.conf' \ -U postgres --old-port=5432 --
new-port=5433

Performing Consistency Checks


-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for system-defined composite types in user tables ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for tables WITH OIDS ok
Checking for invalid "sql_identifier" user columns ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok
Checking for new cluster tablespace directories ok

If pg_upgrade fails after this point, you must re-initdb the


new cluster before continuing.

Performing Upgrade
------------------
Analyzing all rows in the new cluster ok
Freezing all rows in the new cluster ok
Deleting files from new pg_xact ok
Copying old pg_xact to new server ok
Setting oldest XID for new cluster ok
Setting next transaction ID and epoch for new cluster ok
Deleting files from new pg_multixact/offsets ok
Copying old pg_multixact/offsets to new server ok
Deleting files from new pg_multixact/members ok
Copying old pg_multixact/members to new server ok
Setting next multixact ID and offset for new cluster ok
Resetting WAL archives ok
Setting frozenxid and minmxid counters in new cluster ok
Restoring global objects in the new cluster ok
Restoring database schemas in the new cluster
ok
Copying user relation files
ok
Setting next OID for new cluster ok
Sync data directory to disk ok
Creating script to analyze new cluster ok
Creating script to delete old cluster ok
Checking for extension updates ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
./analyze_new_cluster.sh

Running this script will delete the old cluster's data files:
./delete_old_cluster.sh

systemctl start postgresql-12

systemctl status postgresql-12

[postgres@srv1 ~]$ ./analyze_new_cluster.sh


This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy. When it is done, your system will
have the default level of optimizer statistics.

If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation.

If you would like default statistics as quickly as possible, cancel


this script and run:
"/usr/pgsql-12/bin/vacuumdb" --all --analyze-only

vacuumdb: error: could not connect to database template1: could not connect to
server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Done
vi /home/pgsql/12/data/pg_hba.conf

# TYPE DATABASE USER ADDRESS METHOD


host all all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5

vi /home/pgsql/12/data/postgresql.conf
port = 5432

systemctl restart postgresql-12


./analyze_new_cluster.sh

[postgres@srv1 ~]$ ./analyze_new_cluster.sh


This script will generate minimal optimizer statistics rapidly
so your system is usable, and then gather statistics twice more
with increasing accuracy. When it is done, your system will
have the default level of optimizer statistics.

If you have used ALTER TABLE to modify the statistics target for
any tables, you might want to remove them and restore them after
running this script because they will delay fast statistics generation.

If you would like default statistics as quickly as possible, cancel


this script and run:
"/usr/pgsql-12/bin/vacuumdb" --all --analyze-only

Password:
vacuumdb: processing database "ACTIVITI": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "APIGATEWAY": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "CARE": Generating minimal optimizer statistics (1
target)
vacuumdb: processing database "FDB_API": Generating minimal optimizer statistics (1
target)
vacuumdb: processing database "FDB_MEDK": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "KONG_EXT": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "KONG_INT": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "NOTIFICATION": Generating minimal optimizer
statistics (1 target)
vacuumdb: processing database "OCR": Generating minimal optimizer statistics (1
target)
vacuumdb: processing database "PIO": Generating minimal optimizer statistics (1
target)
vacuumdb: processing database "QUEUING": Generating minimal optimizer statistics (1
target)
vacuumdb: processing database "REPORTING": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "USERLOGGING": Generating minimal optimizer
statistics (1 target)
vacuumdb: processing database "WORKFLOW": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "backup_restore": Generating minimal optimizer
statistics (1 target)
vacuumdb: processing database "postgres": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "postgres1": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "postgres2": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics
(1 target)
vacuumdb: processing database "ACTIVITI": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "APIGATEWAY": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "CARE": Generating medium optimizer statistics (10
targets)
vacuumdb: processing database "FDB_API": Generating medium optimizer statistics (10
targets)
vacuumdb: processing database "FDB_MEDK": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "KONG_EXT": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "KONG_INT": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "NOTIFICATION": Generating medium optimizer
statistics (10 targets)
vacuumdb: processing database "OCR": Generating medium optimizer statistics (10
targets)
vacuumdb: processing database "PIO": Generating medium optimizer statistics (10
targets)
vacuumdb: processing database "QUEUING": Generating medium optimizer statistics (10
targets)
vacuumdb: processing database "REPORTING": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "USERLOGGING": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "WORKFLOW": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "backup_restore": Generating medium optimizer
statistics (10 targets)
vacuumdb: processing database "postgres": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "postgres1": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "postgres2": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics
(10 targets)
vacuumdb: processing database "ACTIVITI": Generating default (full) optimizer
statistics
vacuumdb: processing database "APIGATEWAY": Generating default (full) optimizer
statistics
vacuumdb: processing database "CARE": Generating default (full) optimizer
statistics
vacuumdb: processing database "FDB_API": Generating default (full) optimizer
statistics
vacuumdb: processing database "FDB_MEDK": Generating default (full) optimizer
statistics
vacuumdb: processing database "KONG_EXT": Generating default (full) optimizer
statistics
vacuumdb: processing database "KONG_INT": Generating default (full) optimizer
statistics
vacuumdb: processing database "NOTIFICATION": Generating default (full) optimizer
statistics
vacuumdb: processing database "OCR": Generating default (full) optimizer statistics
vacuumdb: processing database "PIO": Generating default (full) optimizer statistics
vacuumdb: processing database "QUEUING": Generating default (full) optimizer
statistics
vacuumdb: processing database "REPORTING": Generating default (full) optimizer
statistics
vacuumdb: processing database "USERLOGGING": Generating default (full) optimizer
statistics
vacuumdb: processing database "WORKFLOW": Generating default (full) optimizer
statistics
vacuumdb: processing database "backup_restore": Generating default (full) optimizer
statistics
vacuumdb: processing database "postgres": Generating default (full) optimizer
statistics
vacuumdb: processing database "postgres1": Generating default (full) optimizer
statistics
vacuumdb: processing database "postgres2": Generating default (full) optimizer
statistics
vacuumdb: processing database "template1": Generating default (full) optimizer
statistics

Done
[postgres@srv1 ~]$

./delete_old_cluster.sh

[postgres@srv1 ~]$ cat delete_old_cluster.sh


#!/bin/sh

rm -rf '/home/pgsql/11/data'
[postgres@srv1 ~]$ ./delete_old_cluster.sh

Check postgres version

[postgres@srv1 pgsql]$ psql -U postgres


Password for user postgres:
psql (12.15)
Type "help" for help.

postgres=# select version();


version
-----------------------------------------------------------------------------------
-----------------------
PostgreSQL 12.15 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red
Hat 4.8.5-44), 64-bit
(1 row)

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype |
Access privileges
----------------+----------------+----------+-------------+-------------
+-----------------------------
ACTIVITI | ACTIVITI | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
APIGATEWAY | APIGATEWAY | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
CARE | CARE | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
FDB_API | FDB_API | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
FDB_MEDK | FDB_MEDK | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
KONG_EXT | KONG_EXT | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
KONG_INT | KONG_INT | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
NOTIFICATION | NOTIFICATION | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
OCR | OCR | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
PIO | PIO | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
QUEUING | QUEUING | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
REPORTING | REPORTING | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
USERLOGGING | USERLOGGING | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
=Tc/USERLOGGING +
| | | | |
USERLOGGING=CTc/USERLOGGING+
| | | | |
argus=c/USERLOGGING +
| | | | |
bi_user=c/USERLOGGING
WORKFLOW | WORKFLOW | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
backup_restore | backup_restore | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres1 | postgres1 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres2 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
=c/postgres +
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres=CTc/postgres +
| | | | |
=c/postgres
(20 rows)

postgres=#

You might also like