Skip to content

Commit fd2019b

Browse files
committed
fix incorrect pg_ptrack_clean() call
1 parent 315cf3b commit fd2019b

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/backup.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ do_backup_instance(void)
753753
int
754754
do_backup(void)
755755
{
756+
bool is_ptrack_support;
757+
756758
/* PGDATA and BACKUP_MODE are always required */
757759
if (pgdata == NULL)
758760
elog(ERROR, "required parameter not specified: PGDATA "
@@ -779,19 +781,15 @@ do_backup(void)
779781
current.checksum_version = get_data_checksum_version(true);
780782
current.stream = stream_wal;
781783

782-
/* ptrack backup checks */
783-
if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK)
784-
{
785-
bool is_ptrack_support = pg_ptrack_support();
784+
is_ptrack_support = pg_ptrack_support();
786785

787-
if (!is_ptrack_support)
788-
elog(ERROR, "This PostgreSQL instance does not support ptrack");
789-
else
790-
{
791-
is_ptrack_enable = pg_ptrack_enable();
792-
if(!is_ptrack_enable)
793-
elog(ERROR, "Ptrack is disabled");
794-
}
786+
if (!is_ptrack_support)
787+
elog(ERROR, "This PostgreSQL instance does not support ptrack");
788+
else
789+
{
790+
is_ptrack_enable = pg_ptrack_enable();
791+
if(!is_ptrack_enable)
792+
elog(ERROR, "Ptrack is disabled");
795793
}
796794

797795
/* archiving check */
@@ -1147,7 +1145,6 @@ pg_ptrack_clear(void)
11471145

11481146
params[0] = palloc(64);
11491147
params[1] = palloc(64);
1150-
11511148
res_db = pgut_execute(backup_conn, "SELECT datname, oid, dattablespace FROM pg_database",
11521149
0, NULL);
11531150

@@ -1156,7 +1153,7 @@ pg_ptrack_clear(void)
11561153
PGconn *tmp_conn;
11571154

11581155
dbname = PQgetvalue(res_db, i, 0);
1159-
if (!strcmp(dbname, "template0"))
1156+
if (strcmp(dbname, "template0") == 0)
11601157
continue;
11611158

11621159
dbOid = atoi(PQgetvalue(res_db, i, 1));
@@ -1167,7 +1164,7 @@ pg_ptrack_clear(void)
11671164

11681165
sprintf(params[0], "%i", dbOid);
11691166
sprintf(params[1], "%i", tblspcOid);
1170-
res = pgut_execute(tmp_conn, "SELECT pg_drop_ptrack_init_file($1, $2)",
1167+
res = pgut_execute(tmp_conn, "SELECT pg_ptrack_get_and_clear_db($1, $2)",
11711168
2, (const char **)params);
11721169
PQclear(res);
11731170

@@ -2076,12 +2073,6 @@ parse_backup_filelist_filenames(parray *files, const char *root)
20762073
}
20772074
}
20782075
}
2079-
2080-
if (strcmp(filename, "pg_internal.init") == 0)
2081-
{
2082-
elog(INFO, "filename %s, path %s, dbOid %u, tblspcOid %u is_datafile %s",
2083-
filename, file->path, file->dbOid, file->tblspcOid, file->is_datafile?"true":"false");
2084-
}
20852076
}
20862077
}
20872078

@@ -2444,12 +2435,16 @@ get_last_ptrack_lsn(void)
24442435

24452436
{
24462437
PGresult *res;
2438+
uint32 xlogid;
2439+
uint32 xrecoff;
24472440
XLogRecPtr lsn;
24482441

24492442
res = pgut_execute(backup_conn, "select pg_ptrack_control_lsn()", 0, NULL);
24502443

2451-
lsn = atoi(PQgetvalue(res, 0, 0));
2452-
elog(INFO, "get_last_ptrack_lsn(): lsn %lu", lsn);
2444+
/* Extract timeline and LSN from results of pg_start_backup() */
2445+
XLogDataFromLSN(PQgetvalue(res, 0, 0), &xlogid, &xrecoff);
2446+
/* Calculate LSN */
2447+
lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
24532448

24542449
PQclear(res);
24552450
return lsn;

0 commit comments

Comments
 (0)