Movatterモバイル変換


[0]ホーム

URL:


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

Commit257dd3a

Browse files
author
Arthur Zakirov
committed
Call pg_switch_wal() for PAGE backup after pg_start_backup()
1 parent7666b59 commit257dd3a

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

‎src/backup.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void backup_files(void *arg);
8080
staticvoiddo_backup_database(parray*backup_list);
8181

8282
staticvoidpg_start_backup(constchar*label,boolsmooth,pgBackup*backup);
83+
staticvoidpg_switch_wal(PGconn*conn);
8384
staticvoidpg_stop_backup(pgBackup*backup);
8485
staticintcheckpoint_timeout(void);
8586

@@ -639,19 +640,53 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
639640

640641
PQclear(res);
641642

643+
if (current.backup_mode==BACKUP_MODE_DIFF_PAGE)
644+
/*
645+
* Switch to a new WAL segment. It is necessary to get archived WAL
646+
* segment, which includes start LSN of current backup.
647+
*/
648+
pg_switch_wal(conn);
649+
642650
if (!stream_wal)
651+
{
643652
/*
644653
* Do not wait start_lsn for stream backup.
645654
* Because WAL streaming will start after pg_start_backup() in stream
646655
* mode.
647656
*/
648-
wait_wal_lsn(backup->start_lsn, true);
657+
/* In PAGE mode wait for current segment... */
658+
if (current.backup_mode==BACKUP_MODE_DIFF_PAGE)
659+
wait_wal_lsn(backup->start_lsn, false);
660+
/* ...for others wait for previous segment */
661+
else
662+
wait_wal_lsn(backup->start_lsn, true);
663+
}
649664

650665
/* Wait for start_lsn to be replayed by replica */
651666
if (from_replica)
652667
wait_replica_wal_lsn(backup->start_lsn, true);
653668
}
654669

670+
/*
671+
* Switch to a new WAL segment. It should be called only for master.
672+
*/
673+
staticvoid
674+
pg_switch_wal(PGconn*conn)
675+
{
676+
PGresult*res;
677+
678+
/* Remove annoying NOTICE messages generated by backend */
679+
res=pgut_execute(conn,"SET client_min_messages = warning;",0,NULL);
680+
PQclear(res);
681+
682+
if (server_version >=100000)
683+
res=pgut_execute(conn,"SELECT * FROM pg_switch_wal()",0,NULL);
684+
else
685+
res=pgut_execute(conn,"SELECT * FROM pg_switch_xlog()",0,NULL);
686+
687+
PQclear(res);
688+
}
689+
655690
/*
656691
* Check if the instance supports ptrack
657692
* TODO Maybe we should rather check ptrack_version()?
@@ -974,7 +1009,7 @@ pg_stop_backup(pgBackup *backup)
9741009
uint32xrecoff;
9751010
XLogRecPtrrestore_lsn=InvalidXLogRecPtr;
9761011
boolsent= false;
977-
intpg_stop_backup_timeout=0;
1012+
intpg_stop_backup_timeout=0;
9781013

9791014
/*
9801015
* We will use this values if there are no transactions between start_lsn
@@ -1050,8 +1085,6 @@ pg_stop_backup(pgBackup *backup)
10501085
* Wait for the result of pg_stop_backup(),
10511086
* but no longer than PG_STOP_BACKUP_TIMEOUT seconds
10521087
*/
1053-
elog(INFO,"wait for pg_stop_backup()");
1054-
10551088
while (1)
10561089
{
10571090
if (!PQconsumeInput(conn)||PQisBusy(conn))
@@ -1064,6 +1097,10 @@ pg_stop_backup(pgBackup *backup)
10641097
pgut_cancel(conn);
10651098
elog(ERROR,"interrupted during waiting for pg_stop_backup");
10661099
}
1100+
1101+
if (pg_stop_backup_timeout==1)
1102+
elog(INFO,"wait for pg_stop_backup()");
1103+
10671104
/*
10681105
* If postgres haven't answered in PG_STOP_BACKUP_TIMEOUT seconds,
10691106
* send an interrupt.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp