Mempertahankan Slot Replikasi di Seluruh Versi Utama Postgres

winrate777 slot

red casino 32

casino cash

online mobile casino

Fitur Baru PostgreSQL 17: Mempertahankan Slot Replikasi Logis saat Upgrade

PostgreSQL 17 adalah rilis utama yang sangat kuat dari komunitas PG. Dengan rilis ini, fokus komunitas terus pada peningkatan performa, skalabilitas, keamanan, dan kelayakan perusahaan. PostgreSQL 17 juga meningkatkan pengalaman pengembang dengan menambahkan fitur-fitur baru untuk kompatibilitas, serta membuat fitur yang ada menjadi lebih kuat dan tangguh.

Fitur ini juga membantu produk-produk yang menyediakan PostgreSQL terdistribusi untuk meningkatkan ketersediaan tinggi (HA) mereka, terutama terkait upgrade sistem antar versi utama. Fitur ini memungkinkan upgrade dengan waktu henti yang hampir nol.

Evolusi fitur replikasi logis di PostgreSQL dimulai dari PostgreSQL 9.4 ketika blok bangunan untuk replikasi logis pertama kali ditambahkan, namun fitur replikasi logis itu sendiri baru hadir di PostgreSQL 10. Sejak itu, berbagai perbaikan penting telah dilakukan pada replikasi logis.

Kembali ke topik, fitur baru ini memungkinkan mempertahankan slot replikasi saat melakukan upgrade antar versi utama Postgres, sehingga menghilangkan kebutuhan untuk menyinkronkan ulang data antara dua node yang sebelumnya menggunakan replikasi logis. Perhatikan bahwa fitur ini hanya tersedia saat melakukan upgrade dari PostgreSQL 17 ke versi utama yang lebih baru. Upgrade dari versi sebelum PostgreSQL 17 masih perlu mengikuti proses pembuatan ulang slot replikasi dan membuat subscriber yang melakukan rsync data antara node yang mereplikasi.

Patch ini dibuat oleh Hayato Kuroda dan Hou Zhijie serta dikomit oleh Amit Kapila. Berikut adalah entri log commit PostgreSQL untuk fitur ini:

commit 29d0a77fa6606f9c01ba17311fc452dabd3f793d
Author: Amit Kapila <akapila@postgresql>
Date: Thu Oct 26 06:54:16 2023 +0530

Migrasikan slot logis ke node baru selama upgrade. Saat membaca informasi dari cluster lama, daftar slot logis diambil. Di bagian akhir upgrade, pg_upgrade mengunjungi kembali daftar tersebut dan mengembalikan slot dengan menjalankan pg_create_logical_replication_slot() di cluster baru. Migrasi slot replikasi logis hanya didukung jika cluster lama adalah versi 17.0 atau lebih baru. Jika node lama memiliki slot yang tidak valid atau slot dengan catatan WAL yang belum dikonsumsi, pg_upgrade gagal. Pemeriksaan ini diperlukan untuk mencegah kehilangan data. Keuntungan signifikan dari commit ini adalah memudahkan melanjutkan replikasi logis bahkan setelah upgrade node publisher. Sebelumnya, pg_upgrade mengizinkan menyalin publikasi ke node baru. Dengan patch ini, menyesuaikan string koneksi ke publisher baru akan menyebabkan worker apply pada subscriber terhubung ke publisher baru secara otomatis. Ini memungkinkan kelanjutan replikasi logis yang mulus, bahkan setelah upgrade.

Contoh Skrip

Sekarang mari kita tulis skrip kecil untuk menguji fitur ini; seperti yang disebutkan sebelumnya, ini hanya berfungsi saat Anda melakukan upgrade dari PostgreSQL 17 ke rilis utama mendatang. Slot replikasi apa pun di cluster lama yang tidak valid atau memiliki WAL yang belum dikonsumsi harus diperbaiki sebelum upgrade, atau upgrade akan gagal.

Perhatikan bahwa skrip di bawah menggunakan PostgreSQL 17.2 untuk cluster lama dan baru untuk mendemonstrasikan fungsionalitas; kita harus menunggu hingga versi utama lainnya tersedia sebelum dapat menunjukkan fungsionalitas dengan maksimal. Hasil dari skrip juga tercantum di bawah, menunjukkan bahwa slot replikasi yang dibuat di cluster lama telah disalin ke cluster baru.

#!/bin/bash
# Bagian deklarasi
OLD_BIN=/home/user/pg17/bin
NEW_BIN=/home/user/pg17/bin
# Bersihkan hasil sebelumnya
pg_ctl stop -D data_new 2>/dev/null; pg_ctl stop -D data_old 2>/dev/null
rm -rf data_* *log
# Inisialisasi node lama
initdb -D data_old -U user
cat << EOF >> data_old/postgresql
wal_level=logical
EOF
pg_ctl start -D data_old -l old
# Tentukan slot replikasi logis
psql -U user -d postgres -c "SELECT * FROM pg_create_logical_replication_slot('test', 'test_decoding');"
# Hentikan node lama untuk menjalankan pg_upgrade
pg_ctl stop -D data_old
# Inisialisasi node baru
initdb -D data_new -U user
cat << EOF >> data_new/postgresql
wal_level=logical
EOF
# Jalankan perintah pg_upgrade. Jika node lama adalah PG17+, slot replikasi logis akan disalin
pg_upgrade -b $OLD_BIN -B $NEW_BIN -d data_old -D data_new -U user
# Mari konfirmasi keberadaan slot
pg_ctl start -D data_new -l new
psql -U user -d postgres -c "SELECT * FROM pg_replication_slots;"
pg_ctl stop -D data_new

Hasil Menjalankan Skrip

./17_upgrade.sql
pg_ctl: PID file "data_new/postmaster" does not exist
Is server running?
pg_ctl: PID file "data_old/postmaster" does not exist
Is server running?
The files belonging to this database system will be owned by user "user".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory data_old ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Asia/Karachi
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D data_old -l logfile start
waiting for server to start.... done
server started
slot_name | lsn
-----------+-----------
test | 0/14D6490
(1 row)
waiting for server to shut down.... done
server stopped
The files belonging to this database system will be owned by user "user".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory data_new ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Asia/Karachi
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D data_new -l logfile start
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 contrib/isn with bigint-passing mismatch ok
Checking for valid logical replication slots ok
Checking for subscription state ok
Checking data type usage 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
Checking for new cluster logical replication slots ok
If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.
Performing Upgrade
------------------
Setting locale and encoding for new cluster ok
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
Restoring logical replication slots in the new cluster. ok
Sync data directory to disk ok
Creating script to delete old cluster ok
Checking for extension updates ok
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
/home/user/pg17/bin/vacuumdb -U user --all --analyze-in-stages
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
waiting for server to start.... done
server started
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn | wal_status | safe_wal_size | two_phase | inactive_since | conflicting | invalidation_reason | failover | synced
-----------+-----------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------+------------+--------------+-----------+-------------------------------+-------------+---------------------+----------+--------
test | test_decoding | logical | 5 | postgres | f | f | | | 760 | 0/80000D8 | 0/8000110 | reserved | | f | 2025-01-23 18:13:59.623016+05 | f | | f | f
(1 row)
waiting for server to shut down.... done
server stopped

Hasil di atas mengonfirmasi bahwa slot replikasi 'test' dari cluster lama berhasil dipulihkan di cluster baru.

Kesimpulan

Dapat dikatakan bahwa replikasi logis telah matang dan stabil selama bertahun-tahun. Namun, untuk menyediakan kemampuan multi-master yang sesungguhnya dengan replikasi logis diperlukan fungsionalitas yang lebih luas, termasuk manajemen konflik, DDL otomatis, dan sebagainya. Kemampuan penanganan konflik dalam cluster PostgreSQL terdistribusi yang canggih memungkinkan pengelolaan konflik secara otomatis pada operasi INSERT, UPDATE, dan DELETE. Kemampuan ini merupakan persyaratan untuk pengaturan multi-master yang sesungguhnya, di mana aplikasi dapat mengirimkan tulisan ke beberapa node cluster secara paralel.

postgres create replication slot

▲ Kembali ke atas

Platform Lainnya

samurai388 slot

nct dream arcade lyrics

baccarat casino odds

slot gacor depo receh

Berita Piala Dunia

hujantoto slot login

RTP UDINTOGEL

slot car sets australia

boy138 slot

Jika Anda memiliki pertanyaan, silakan kirim email ke [email protected]

▲ Kembali ke atas