Skip to content

Commit 7e28977

Browse files
committed
check is data_checksums are enabled in postgres instance
1 parent 5b5fe6e commit 7e28977

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

src/backup.c

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static pthread_mutex_t start_stream_mut = PTHREAD_MUTEX_INITIALIZER;
5252
static pthread_t stream_thread;
5353

5454
static int is_ptrack_enable = false;
55+
bool is_checksum_enabled = false;
5556

5657
/* Backup connections */
5758
static PGconn *backup_conn = NULL;
@@ -108,6 +109,7 @@ static void remote_copy_file(PGconn *conn, pgFile* file);
108109
static void pg_ptrack_clear(void);
109110
static bool pg_ptrack_support(void);
110111
static bool pg_ptrack_enable(void);
112+
static bool pg_checksum_enable(void);
111113
static bool pg_is_in_recovery(void);
112114
static bool pg_ptrack_get_and_clear_db(Oid dbOid, Oid tblspcOid);
113115
static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
@@ -772,6 +774,9 @@ do_backup(time_t start_time)
772774
/* TODO fix it for remote backup*/
773775
if (!is_remote_backup)
774776
current.checksum_version = get_data_checksum_version(true);
777+
778+
is_checksum_enabled = pg_checksum_enable();
779+
775780
StrNCpy(current.server_version, server_version_str,
776781
sizeof(current.server_version));
777782
current.stream = stream_wal;
@@ -1094,6 +1099,23 @@ pg_ptrack_enable(void)
10941099
return true;
10951100
}
10961101

1102+
/* Check if ptrack is enabled in target instance */
1103+
static bool
1104+
pg_checksum_enable(void)
1105+
{
1106+
PGresult *res_db;
1107+
1108+
res_db = pgut_execute(backup_conn, "show data_checksums", 0, NULL, true);
1109+
1110+
if (strcmp(PQgetvalue(res_db, 0, 0), "on") != 0)
1111+
{
1112+
PQclear(res_db);
1113+
return false;
1114+
}
1115+
PQclear(res_db);
1116+
return true;
1117+
}
1118+
10971119
/* Check if target instance is replica */
10981120
static bool
10991121
pg_is_in_recovery(void)
@@ -2683,31 +2705,6 @@ pg_ptrack_get_block(Oid dbOid,
26832705
params[2] = palloc(64);
26842706
params[3] = palloc(64);
26852707

2686-
// sprintf(params[0], "%i", dbOid);
2687-
// res_db = pgut_execute(backup_conn,
2688-
// "SELECT datname FROM pg_database WHERE oid=$1",
2689-
// 1, (const char **) params, true);
2690-
// /*
2691-
// * If database is not found, it's not an error.
2692-
// * It could have been deleted.
2693-
// */
2694-
// if (PQntuples(res_db) != 1 || PQnfields(res_db) != 1)
2695-
// {
2696-
// //elog(LOG, "Database with oid %d is not found", dbOid);
2697-
// return NULL;
2698-
// }
2699-
//
2700-
// dbname = PQgetvalue(res_db, 0, 0);
2701-
// if (strcmp(dbname, "template0") == 0)
2702-
// {
2703-
// /*
2704-
// * There is no way to connect to the template0 database.
2705-
// * But it's totally OK, since files there can never be changed.
2706-
// */
2707-
// return NULL;
2708-
// }
2709-
// tmp_conn = pgut_connect(dbname);
2710-
27112708
/*
27122709
* Use backup_conn, cause we can do it from any database.
27132710
*/
@@ -2739,9 +2736,6 @@ pg_ptrack_get_block(Oid dbOid,
27392736
result = (char *) PQunescapeBytea((unsigned char *) PQgetvalue(res, 0, 0),
27402737
result_size);
27412738

2742-
// pgut_disconnect(tmp_conn);
2743-
// PQclear(res_db);
2744-
27452739
PQclear(res);
27462740
pfree(params[0]);
27472741
pfree(params[1]);

src/data.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ read_page_from_file(pgFile *file, BlockNumber blknum,
190190
}
191191

192192
/* Verify checksum */
193-
if(current.checksum_version)
193+
if(current.checksum_version && is_checksum_enabled)
194194
{
195195
/*
196196
* If checksum is wrong, sleep a bit and then try again
@@ -269,8 +269,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
269269
}
270270
}
271271

272-
if ((!page_is_valid)
273-
|| (backup_mode == BACKUP_MODE_DIFF_PTRACK))
272+
if (backup_mode == BACKUP_MODE_DIFF_PTRACK)
274273
{
275274
size_t page_size = 0;
276275
PageHeader phdr = (PageHeader) page;
@@ -298,7 +297,8 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
298297
* We must set checksum here, because it is outdated
299298
* in the block recieved from shared buffers.
300299
*/
301-
((PageHeader) page)->pd_checksum = pg_checksum_page(page, absolute_blknum);
300+
if (is_checksum_enabled)
301+
((PageHeader) page)->pd_checksum = pg_checksum_page(page, absolute_blknum);
302302
}
303303
}
304304

src/pg_probackup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ extern const char *master_port;
283283
extern const char *master_user;
284284
extern uint32 replica_timeout;
285285

286+
extern bool is_checksum_enabled;
287+
286288
/* delete options */
287289
extern bool delete_wal;
288290
extern bool delete_expired;

0 commit comments

Comments
 (0)