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

Commit2bdaaf0

Browse files
committed
Add pg_switch_wal(). It is used for page backup
1 parente9e25d9 commit2bdaaf0

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

‎backup.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static void backup_files(void *arg);
5959
staticvoiddo_backup_database(parray*backup_list);
6060

6161
staticvoidpg_start_backup(constchar*label,boolsmooth,pgBackup*backup);
62+
staticvoidpg_switch_wal(void);
6263
staticvoidpg_stop_backup(pgBackup*backup);
6364

6465
staticvoidadd_pgdata_files(parray*files,constchar*root);
@@ -214,6 +215,16 @@ do_backup_database(parray *backup_list)
214215
*/
215216
if (current.backup_mode==BACKUP_MODE_DIFF_PAGE)
216217
{
218+
/*
219+
* Switch to a new WAL segment. It is necessary to get archived WAL
220+
* segment, which includes start LSN of current backup.
221+
*
222+
* Do not switch for standby node and if backup is stream.
223+
*/
224+
if (!from_replica&& !stream_wal)
225+
pg_switch_wal();
226+
if (!stream_wal)
227+
wait_archive_lsn(current.start_lsn, false);
217228
/*
218229
* Build the page map. Obtain information about changed pages
219230
* reading WAL segments present in archives up to the point
@@ -581,14 +592,29 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup)
581592
/* Calculate LSN */
582593
backup->start_lsn= (XLogRecPtr) ((uint64)xlogid <<32) |xrecoff;
583594

584-
if (!stream_wal)
585-
wait_archive_lsn(backup->start_lsn,
586-
/*
587-
* For backup from master wait for previous segment.
588-
* For backup from replica wait for current segment.
589-
*/
590-
!from_replica);
595+
PQclear(res);
596+
}
597+
598+
/*
599+
* Switch to a new WAL segment. It should be called only for master.
600+
*/
601+
staticvoid
602+
pg_switch_wal(void)
603+
{
604+
PGresult*res;
605+
606+
/* Remove annoying NOTICE messages generated by backend */
607+
res=pgut_execute(backup_conn,"SET client_min_messages = warning;",0,
608+
NULL);
609+
PQclear(res);
591610

611+
#ifPG_VERSION_NUM >=100000
612+
res=pgut_execute(backup_conn,"SELECT * FROM pg_switch_wal()",0,
613+
NULL);
614+
#else
615+
res=pgut_execute(backup_conn,"SELECT * FROM pg_switch_xlog()",0,
616+
NULL);
617+
#endif
592618
PQclear(res);
593619
}
594620

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp