Skip to content

Commit 369695e

Browse files
committed
Merge branch 'master' into stable
2 parents 895f96c + c90d578 commit 369695e

25 files changed

+922
-244
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ else
3232
srchome=$(top_srcdir)
3333
endif
3434

35-
ifeq ($(MAJORVERSION),10)
35+
ifeq (,$(filter 9.5 9.6,$(MAJORVERSION)))
3636
OBJS += src/walmethods.o
3737
EXTRA_CLEAN += src/walmethods.c src/walmethods.h
3838
INCLUDES += src/walmethods.h
@@ -64,7 +64,7 @@ src/streamutil.h: $(top_srcdir)/src/bin/pg_basebackup/streamutil.h
6464
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/streamutil.h $@
6565

6666

67-
ifeq ($(MAJORVERSION),10)
67+
ifeq (,$(filter 9.5 9.6,$(MAJORVERSION)))
6868
src/walmethods.c: $(top_srcdir)/src/bin/pg_basebackup/walmethods.c
6969
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/walmethods.c $@
7070
src/walmethods.h: $(top_srcdir)/src/bin/pg_basebackup/walmethods.h

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
`pg_probackup` is a utility to manage backup and recovery of PostgreSQL database clusters. It is designed to perform periodic backups of the PostgreSQL instance that enable you to restore the server in case of a failure.
44

55
The utility is compatible with:
6-
* PostgreSQL 9.5, 9.6, 10;
6+
* PostgreSQL 9.5, 9.6, 10, 11;
77

88
`PTRACK` backup support provided via following options:
99
* vanilla PostgreSQL compiled with ptrack patch. Currently there are patches for [PostgreSQL 9.6](https://gist.githubusercontent.com/gsmol/5b615c971dfd461c76ef41a118ff4d97/raw/e471251983f14e980041f43bea7709b8246f4178/ptrack_9.6.6_v1.5.patch) and [PostgreSQL 10](https://gist.githubusercontent.com/gsmol/be8ee2a132b88463821021fd910d960e/raw/de24f9499f4f314a4a3e5fae5ed4edb945964df8/ptrack_10.1_v1.5.patch)
10-
* Postgres Pro Standard 9.5, 9.6
11-
* Postgres Pro Enterprise
10+
* Postgres Pro Standard 9.5, 9.6, 10
11+
* Postgres Pro Enterprise 9.5, 9.6, 10
1212

1313
As compared to other backup solutions, `pg_probackup` offers the following benefits that can help you implement different backup strategies and deal with large amounts of data:
1414
* Choosing between full and page-level incremental backups to speed up backup and recovery
@@ -97,4 +97,4 @@ Postgres Professional, Moscow, Russia.
9797

9898
## Credits
9999

100-
`pg_probackup` utility is based on `pg_arman`, that was originally written by NTT and then developed and maintained by Michael Paquier.
100+
`pg_probackup` utility is based on `pg_arman`, that was originally written by NTT and then developed and maintained by Michael Paquier.

src/backup.c

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,9 @@ do_backup_instance(void)
650650
* reading WAL segments present in archives up to the point
651651
* where this backup has started.
652652
*/
653-
extractPageMap(arclog_path, prev_backup->start_lsn, current.tli,
654-
current.start_lsn, backup_files_list);
653+
extractPageMap(arclog_path, current.tli, xlog_seg_size,
654+
prev_backup->start_lsn, current.start_lsn,
655+
backup_files_list);
655656
}
656657
else if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK)
657658
{
@@ -827,6 +828,11 @@ do_backup(time_t start_time)
827828

828829
current.primary_conninfo = pgut_get_conninfo_string(backup_conn);
829830

831+
#if PG_VERSION_NUM >= 110000
832+
if (!RetrieveWalSegSize(backup_conn))
833+
elog(ERROR, "Failed to retreive wal_segment_size");
834+
#endif
835+
830836
current.compress_alg = compress_alg;
831837
current.compress_level = compress_level;
832838

@@ -918,8 +924,9 @@ do_backup(time_t start_time)
918924
/* compute size of wal files of this backup stored in the archive */
919925
if (!current.stream)
920926
{
921-
current.wal_bytes = XLOG_SEG_SIZE *
922-
(current.stop_lsn/XLogSegSize - current.start_lsn/XLogSegSize + 1);
927+
current.wal_bytes = xlog_seg_size *
928+
(current.stop_lsn / xlog_seg_size -
929+
current.start_lsn / xlog_seg_size + 1);
923930
}
924931

925932
/* Backup is done. Update backup status */
@@ -1142,10 +1149,11 @@ pg_switch_wal(PGconn *conn)
11421149
res = pgut_execute(conn, "SET client_min_messages = warning;", 0, NULL);
11431150
PQclear(res);
11441151

1145-
if (server_version >= 100000)
1146-
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_wal()", 0, NULL);
1147-
else
1148-
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_xlog()", 0, NULL);
1152+
#if PG_VERSION_NUM >= 100000
1153+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_wal()", 0, NULL);
1154+
#else
1155+
res = pgut_execute(conn, "SELECT * FROM pg_catalog.pg_switch_xlog()", 0, NULL);
1156+
#endif
11491157

11501158
PQclear(res);
11511159
}
@@ -1466,10 +1474,10 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_segment)
14661474
tli = get_current_timeline(false);
14671475

14681476
/* Compute the name of the WAL file containig requested LSN */
1469-
XLByteToSeg(lsn, targetSegNo);
1477+
GetXLogSegNo(lsn, targetSegNo, xlog_seg_size);
14701478
if (wait_prev_segment)
14711479
targetSegNo--;
1472-
XLogFileName(wal_segment, tli, targetSegNo);
1480+
GetXLogFileName(wal_segment, tli, targetSegNo, xlog_seg_size);
14731481

14741482
/*
14751483
* In pg_start_backup we wait for 'lsn' in 'pg_wal' directory iff it is
@@ -1535,7 +1543,7 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_segment)
15351543
/*
15361544
* A WAL segment found. Check LSN on it.
15371545
*/
1538-
if (wal_contains_lsn(wal_segment_dir, lsn, tli))
1546+
if (wal_contains_lsn(wal_segment_dir, lsn, tli, xlog_seg_size))
15391547
/* Target LSN was found */
15401548
{
15411549
elog(LOG, "Found LSN: %X/%X", (uint32) (lsn >> 32), (uint32) lsn);
@@ -1584,9 +1592,6 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
15841592

15851593
while (true)
15861594
{
1587-
PGresult *res;
1588-
uint32 lsn_hi;
1589-
uint32 lsn_lo;
15901595
XLogRecPtr replica_lsn;
15911596

15921597
/*
@@ -1595,32 +1600,32 @@ wait_replica_wal_lsn(XLogRecPtr lsn, bool is_start_backup)
15951600
*/
15961601
if (is_start_backup)
15971602
{
1598-
if (server_version >= 100000)
1599-
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_replay_lsn()",
1600-
0, NULL);
1601-
else
1602-
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_replay_location()",
1603-
0, NULL);
1603+
replica_lsn = get_checkpoint_location(backup_conn);
16041604
}
16051605
/*
16061606
* For lsn from pg_stop_backup() we need it only to be received by
16071607
* replica and fsync()'ed on WAL segment.
16081608
*/
16091609
else
16101610
{
1611-
if (server_version >= 100000)
1612-
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_receive_lsn()",
1613-
0, NULL);
1614-
else
1615-
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_receive_location()",
1616-
0, NULL);
1617-
}
1611+
PGresult *res;
1612+
uint32 lsn_hi;
1613+
uint32 lsn_lo;
16181614

1619-
/* Extract timeline and LSN from result */
1620-
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
1621-
/* Calculate LSN */
1622-
replica_lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
1623-
PQclear(res);
1615+
#if PG_VERSION_NUM >= 100000
1616+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_wal_receive_lsn()",
1617+
0, NULL);
1618+
#else
1619+
res = pgut_execute(backup_conn, "SELECT pg_catalog.pg_last_xlog_receive_location()",
1620+
0, NULL);
1621+
#endif
1622+
1623+
/* Extract LSN from result */
1624+
XLogDataFromLSN(PQgetvalue(res, 0, 0), &lsn_hi, &lsn_lo);
1625+
/* Calculate LSN */
1626+
replica_lsn = ((uint64) lsn_hi) << 32 | lsn_lo;
1627+
PQclear(res);
1628+
}
16241629

16251630
/* target lsn was replicated */
16261631
if (replica_lsn >= lsn)
@@ -1948,7 +1953,7 @@ pg_stop_backup(pgBackup *backup)
19481953

19491954
elog(LOG, "Getting the Recovery Time from WAL");
19501955

1951-
if (!read_recovery_info(xlog_path, backup->tli,
1956+
if (!read_recovery_info(xlog_path, backup->tli, xlog_seg_size,
19521957
backup->start_lsn, backup->stop_lsn,
19531958
&backup->recovery_time, &backup->recovery_xid))
19541959
{
@@ -2201,7 +2206,8 @@ parse_backup_filelist_filenames(parray *files, const char *root)
22012206

22022207
/* Yes, it is */
22032208
if (sscanf_result == 2 &&
2204-
strcmp(tmp_rel_path, TABLESPACE_VERSION_DIRECTORY) == 0)
2209+
strncmp(tmp_rel_path, TABLESPACE_VERSION_DIRECTORY,
2210+
strlen(TABLESPACE_VERSION_DIRECTORY)) == 0)
22052211
set_cfs_datafiles(files, root, relative, i);
22062212
}
22072213
}
@@ -2555,7 +2561,7 @@ StreamLog(void *arg)
25552561
/*
25562562
* Always start streaming at the beginning of a segment
25572563
*/
2558-
startpos -= startpos % XLOG_SEG_SIZE;
2564+
startpos -= startpos % xlog_seg_size;
25592565

25602566
/* Initialize timeout */
25612567
stream_stop_timeout = 0;

src/catalog.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,23 +572,23 @@ readBackupControlFile(const char *path)
572572
pgBackupInit(backup);
573573
if (access(path, F_OK) != 0)
574574
{
575-
elog(WARNING, "control file \"%s\" doesn't exist", path);
575+
elog(WARNING, "Control file \"%s\" doesn't exist", path);
576576
pgBackupFree(backup);
577577
return NULL;
578578
}
579579

580-
parsed_options = pgut_readopt(path, options, WARNING);
580+
parsed_options = pgut_readopt(path, options, WARNING, true);
581581

582582
if (parsed_options == 0)
583583
{
584-
elog(WARNING, "control file \"%s\" is empty", path);
584+
elog(WARNING, "Control file \"%s\" is empty", path);
585585
pgBackupFree(backup);
586586
return NULL;
587587
}
588588

589589
if (backup->start_time == 0)
590590
{
591-
elog(WARNING, "invalid ID/start-time, control file \"%s\" is corrupted", path);
591+
elog(WARNING, "Invalid ID/start-time, control file \"%s\" is corrupted", path);
592592
pgBackupFree(backup);
593593
return NULL;
594594
}
@@ -607,7 +607,7 @@ readBackupControlFile(const char *path)
607607
if (sscanf(start_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
608608
backup->start_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
609609
else
610-
elog(WARNING, "invalid START_LSN \"%s\"", start_lsn);
610+
elog(WARNING, "Invalid START_LSN \"%s\"", start_lsn);
611611
free(start_lsn);
612612
}
613613

@@ -619,7 +619,7 @@ readBackupControlFile(const char *path)
619619
if (sscanf(stop_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
620620
backup->stop_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
621621
else
622-
elog(WARNING, "invalid STOP_LSN \"%s\"", stop_lsn);
622+
elog(WARNING, "Invalid STOP_LSN \"%s\"", stop_lsn);
623623
free(stop_lsn);
624624
}
625625

@@ -644,7 +644,7 @@ readBackupControlFile(const char *path)
644644
else if (strcmp(status, "CORRUPT") == 0)
645645
backup->status = BACKUP_STATUS_CORRUPT;
646646
else
647-
elog(WARNING, "invalid STATUS \"%s\"", status);
647+
elog(WARNING, "Invalid STATUS \"%s\"", status);
648648
free(status);
649649
}
650650

0 commit comments

Comments
 (0)