PostgreSQL sürümünün 10’dan 11’e yükseltilmesi

26 Eki by Engin Yılmaz

PostgreSQL sürümünün 10’dan 11’e yükseltilmesi

merhaba,

Upgrade işlemnde başlamadan önce şu kritik uyarıyı yapamak istiyorum,  postgresql.conf ve pg_hba.conf dosyalarınızın konfiğini tekrar yapmanız gerekecek bu dosyalar eziliyor upgrade sonrasında.

Postgresql 11 aşağıdaki komutlar ile kurulur.

[root@postgres eng]# yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

[root@postgres eng]# yum install postgresql11

[root@postgres eng]# yum install postgresql11-server

Postgresql 11 veritabanında initdb çalıştırılır.

[root@postgres eng]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK

Aşağıdaki komut ile upgrade’in yapılabilirliği check edilir. (postgresql kullanıcısı ile)

-bash-4.2$ /usr/pgsql-1/bin/pg_upgrade --old-bindir=/usr/pgsql-10/bin/ --new-bindir=/usr/pgsql-11/bin/ --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/11/data --check
pgsql-10/ pgsql-11/ 
-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade --old-bindir=/usr/pgsql-10/bin/ --new-bindir=/usr/pgsql-11/bin/ --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/11/data --check
Performing Consistency Checks on Old Live Server
------------------------------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for presence of required libraries ok
Checking database user is the install user ok
Checking for prepared transactions ok

*Clusters are compatible*

Postgresql 10 kapatılmadan upgrade yaparsak aşağıdaki hatayı alırız.

-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade --old-bindir=/usr/pgsql-10/bin/ --new-bindir=/usr/pgsql-11/bin/ --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/11/data

There seems to be a postmaster servicing the old cluster.
Please shutdown that postmaster and try again.
Failure, exiting
-bash-4.2$ logout
[root@postgres eng]# systemctl stop postgresql-10.service

Postgresql 10 veritabanı kapatılır.(root kullanıcısı ile)

[root@postgres eng]# systemctl stop postgresql-10.service

Sonrasında postgresql kullanıcısına geçilir ve upgrade komutumuz çalıştırılır.(postgres kullanıcısı ile)

-bash-4.2$ /usr/pgsql-11/bin/pg_upgrade --old-bindir=/usr/pgsql-10/bin/ --new-bindir=/usr/pgsql-11/bin/ --old-datadir=/var/lib/pgsql/10/data --new-datadir=/var/lib/pgsql/11/data 
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 reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch 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

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 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

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
-bash-4.2$

Bizden istenene komutları çalıştırmadan önce aşağıdaki komutlar çalıştırılır.

[root@postgres eng]# systemctl enable postgresql-11.service 

Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.

[root@postgres eng]# systemctl start postgresql-11.service

Sonrasında bizden istenen komutlar çalıştırılır.

-bash-4.2$ ./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-11/bin/vacuumdb" --all --analyze-only

vacuumdb: processing database "postgres": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target)
vacuumdb: processing database "postgres": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets)
vacuumdb: processing database "postgres": Generating default (full) optimizer statistics
vacuumdb: processing database "template1": Generating default (full) optimizer statistics

Done

-bash-4.2$ ./delete_old_cluster.sh

Postgresql-10 ile alakalı tüm paketler remove edilir. (root kullanıcısı ile)

[root@postgres eng]# rpm -qa | grep postgresql

yum remove postgresql10-10.5-1PGDG.rhel7.x86_64

yum remove  postgresql10-libs-10.5-1PGDG.rhel7.x86_64

Sonrasında Upgrade işlemimiz tamamlanmıştır diye biliriz. Veritabanına bağlanıp 11 sürümünü görebilirisin.

-bash-4.2$ psql

psql (11.0)

Type "help" for help.

postgres=#

Umarım faydalı olmuştur..

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Lütfen captcha kodunu giriniz *

Lütfen Resimdeki Kodu Boşluğa Giriniz.