Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3a5e729

Browse files
authored
Create pg_receivewal@.service
1 parent da619db commit 3a5e729

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎pg_receivewal/pg_receivewal@.service‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[Unit]
2+
Description=PostgreSQL pg_receivewal service
3+
Documentation=https://www.postgresql.org/docs/current/app-pgreceivewal.html
4+
After=postgresql-%i.service
5+
6+
[Service]
7+
Type=simple
8+
User=postgres
9+
Group=postgres
10+
11+
# архивировать WAL файлы будем только с мастера
12+
ExecCondition=echo "pg_receivewal: check if PostgreSQL is primary"
13+
ExecCondition=/bin/bash -c "test f = $(psql --user=bkp_replicator --dbname=postgres --quiet --no-psqlrc --pset=null=¤ --tuples-only --no-align --command='select pg_is_in_recovery()')"
14+
15+
# создаём слот, если его ещё не было (select * from pg_replication_slots;)
16+
ExecStartPre=/usr/pgsql-%i/bin/pg_receivewal --verbose --user=bkp_replicator --slot=pg_receivewal --create-slot --if-not-exists
17+
18+
# архивируем WAL файлы в реальном времени, появится ещё одна асинхронная реплика, которая никогда не догонит мастер (select * from pg_stat_replication;)
19+
ExecStart=/usr/pgsql-%i/bin/pg_receivewal --verbose --user=bkp_replicator --slot=pg_receivewal --directory=/mnt/backup_db/archive_wal --synchronous
20+
21+
# удаляем слот репликации, если он существует и неактивен (не используется); активный слот удалить нельзя, будет ошибка
22+
ExecStopPost=echo "pg_receivewal: drop unused replication slot"
23+
ExecStopPost=psql --user=bkp_replicator --dbname=postgres --quiet --no-psqlrc --pset=null=¤ --tuples-only --no-align \
24+
--command="select pg_drop_replication_slot(slot_name) from pg_replication_slots where slot_name='pg_receivewal' and not active"
25+
26+
[Install]
27+
WantedBy=multi-user.target

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /