Memperkenalkan sistem cadangan PostgreSQL wal-g

WAL-G adalah alat yang sederhana dan efektif untuk membuat cadangan PostgreSQL ke cloud. Dengan fungsi dasarnya, ini adalah pewaris alat WAL-E yang populer , tetapi ditulis ulang di Go. Tetapi ada satu fitur baru yang penting dalam WAL-G - salinan delta. Delta WAL-G menyalin halaman file yang telah berubah dari versi cadangan sebelumnya. WAL-G mengimplementasikan beberapa teknologi untuk memparalelkan cadangan. WAL-G jauh lebih cepat daripada WAL-E.


Rincian wal-g dapat ditemukan di artikel: Overclocking backup. Kuliah Yandex


Protokol penyimpanan S3 telah menjadi populer untuk penyimpanan data. Salah satu kelebihan S3 adalah kemampuan untuk mengakses melalui API, yang memungkinkan interaksi fleksibel dengan repositori, termasuk akses baca publik, sementara informasi diperbarui dalam repositori hanya oleh orang yang berwenang.


Ada beberapa implementasi penyimpanan terbuka dan pribadi yang beroperasi di bawah protokol S3. Hari ini kita akan melihat solusi populer untuk mengatur penyimpanan kecil - Minio.


Untuk pengujian wal-g, satu server PostgreSQL cocok, dan Minio digunakan sebagai pengganti S3.


Server Minio


Instalasi Minio


yum -y install yum-plugin-copr
yum copr enable -y lkiesow/minio
yum install -y minio mc

Edit AccessKey dan SecretKey di /etc/minio/minio.conf


vi /etc/minio/minio.conf

Jika Anda tidak akan menggunakan nginx sebelum Minio, maka Anda perlu mengubahnya


--address 127.0.0.1:9000

--address 0.0.0.0:9000

Hasilkan dan tambahkan ke MINIO_ACCESS_KEY dan MINIO_SECRET_KEY di /etc/minio/minio.conf


# Custom username or access key of minimum 3 characters in length.
#MINIO_ACCESS_KEY=

# Custom password or secret key of minimum 8 characters in length.
#MINIO_SECRET_KEY=

Luncurkan Minio


systemctl start minio

web- Minio http://ip---minio:9000 (, pg-backups).



WAL-G rpm ( ). Github, Fedora COPR.


RPM-based .


wal-g rpm , /etc/wal-g.d/server-s3.conf.


backup-fetch.sh
backup-list.sh
backup-push.sh
wal-fetch.sh
wal-g-run.sh
wal-push.sh

wal-g.


yum -y install yum-plugin-copr
yum copr enable -y antonpatsev/wal-g
yum install -y wal-g

wal-g.


wal-g --version
wal-g version v0.2.14

/etc/wal-g.d/server-s3.conf .


, , , PGDATA


#!/bin/bash

export PG_VER="9.6"

export WALE_S3_PREFIX="s3://pg-backups" # ,     S3
export AWS_ACCESS_KEY_ID="xxxx" # AccessKey  /etc/minio/minio.conf 
export AWS_ENDPOINT="http://ip---minio:9000"
export AWS_S3_FORCE_PATH_STYLE="true"
export AWS_SECRET_ACCESS_KEY="yyyy" # SecretKey  /etc/minio/minio.conf

export PGDATA=/var/lib/pgsql/$PG_VER/data/
export PGHOST=/var/run/postgresql/.s.PGSQL.5432 #     PostgreSQL

export WALG_UPLOAD_CONCURRENCY=2 # -    
export WALG_DOWNLOAD_CONCURRENCY=2 # -   
export WALG_UPLOAD_DISK_CONCURRENCY=2 # -     
export WALG_DELTA_MAX_STEPS=7
export WALG_COMPRESSION_METHOD=brotli #    .

WAL-G WALG_DELTA_MAX_STEPS β€” , base- -, -. , . , , .


.


yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql96 postgresql96-server mc

.


/usr/pgsql-9.6/bin/postgresql96-setup initdb
Initializing database ... OK

1 , wal_level archive PostgreSQL 10 , replica PostgreSQL 10 .


wal_level = archive

WAL 60 PostgreSQL. archive_timeout.


archive_mode = on
archive_command = '/usr/local/bin/wal-push.sh %p'
archive_timeout = 60 #  60     archive_command.

PostgreSQL


systemctl start postgresql-9.6

PostgreSQL : (postgresql-Wed.log ).


tail -fn100 /var/lib/pgsql/9.6/data/pg_log/postgresql-Wed.log

psql.


su - postgres
psql

psql .


test1.


create database test1;

test.


postgres=# \c test1;

indexing_table.


test1=# CREATE TABLE indexing_table(created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW());

.


. 10-20 .


#!/bin/bash
# postgres
while true; do
psql -U postgres -d test1 -c "INSERT INTO indexing_table(created_at) VALUES (CURRENT_TIMESTAMP);"
sleep 60;
done

test1


select * from indexing_table;
2020-01-29 09:41:25.226198+
2020-01-29 09:42:25.336989+
2020-01-29 09:43:25.356069+
2020-01-29 09:44:25.37381+
2020-01-29 09:45:25.392944+
2020-01-29 09:46:25.412327+
2020-01-29 09:47:25.432564+
2020-01-29 09:48:25.451985+
2020-01-29 09:49:25.472653+
2020-01-29 09:50:25.491974+
2020-01-29 09:51:25.510178+

.


WAL:


select pg_switch_xlog();
 PostgreSQL  10:
select pg_switch_wal();

.


su - postgres
/usr/local/bin/backup-push.sh


/usr/local/bin/backup-list.sh


WAL.


Postgresql.


/var/lib/pgsql/9.6/data.


/usr/local/bin/backup-fetch.sh postgres.


su - postgres
/usr/local/bin/backup-fetch.sh

Backup extraction complete.


recovery.conf /var/lib/pgsql/9.6/data .


restore_command = '/usr/local/bin/wal-fetch.sh "%f" "%p"'

PostgreSQL. PostgreSQL recovery WAL, .


systemctl start postgresql-9.6
tail -fn100 /var/lib/pgsql/9.6/data/pg_log/postgresql-Wed.log

.


, recovery.conf recovery_target_time β€” .


restore_command = '/usr/local/bin/wal-fetch.sh "%f" "%p"'
recovery_target_time = '2020-01-29 09:46:25'

indexing_table


 2020-01-29 09:41:25.226198+00
 2020-01-29 09:42:25.336989+00
 2020-01-29 09:43:25.356069+00
 2020-01-29 09:44:25.37381+00
 2020-01-29 09:45:25.392944+00

PostgreSQL. PostgreSQL recovery WAL, .


systemctl start postgresql-9.6
tail -fn100 /var/lib/pgsql/9.6/data/pg_log/postgresql-Wed.log

PostgreSQL 12 -:


  • restore_command recovery_target_time postgresql.conf
  • $PGDATA/recovery.signal


1GB https://gist.github.com/ololobus/5b25c432f208d7eb31051a5f238dffff


1GB .


postgres=# SELECT pg_size_pretty(pg_database_size('test1'));
pg_size_pretty
----------------
1003 MB

s4cmd adalah alat baris perintah gratis untuk bekerja dengan data yang terletak di penyimpanan Amazon S3. Utilitas ini ditulis dalam bahasa pemrograman python, dan karena ini dapat digunakan pada sistem operasi Windows dan Linux.


Instal s4cmd


pip install s4cmd

Lz4


s4cmd --endpoint-url=http://ip---minio:9000 --access-key=xxxx --secret-key=yyyy du -r s3://pg-backups
840540822       s3://pg-backups/wal_005/
840    lz4  WAL 

   lz4 - 1GB 
time backup_push.sh
real 0m18.582s

 S3    

581480085       s3://pg-backups/basebackups_005/
842374424   s3://pg-backups/wal_005
581    

LZMA


  1 
338413694       s3://pg-backups/wal_005/
338     lzma

   
time backup_push.sh
real    5m25.054s

   S3
270310495       s3://pg-backups/basebackups_005/
433485092   s3://pg-backups/wal_005/

270       lzma

Brotli


  1 
459229886       s3://pg-backups/wal_005/
459     brotli

   
real    0m23.408s

   S3
312960942       s3://pg-backups/basebackups_005/
459309262   s3://pg-backups/wal_005/

312       brotli

Perbandingan hasil pada grafik.



Seperti yang Anda lihat, ukuran Brotli sebanding dengan LZMA, tetapi cadangan dilakukan selama LZ4.


Obrolan komunitas berbahasa Rusia PostgreSQL: https://t.me/pgsql


Harap beri bintang pada Github jika Anda menggunakan wal-g

Source: https://habr.com/ru/post/undefined/


All Articles