@@ -52,6 +52,7 @@ static pthread_mutex_t start_stream_mut = PTHREAD_MUTEX_INITIALIZER;
52
52
static pthread_t stream_thread ;
53
53
54
54
static int is_ptrack_enable = false;
55
+ bool is_checksum_enabled = false;
55
56
56
57
/* Backup connections */
57
58
static PGconn * backup_conn = NULL ;
@@ -108,6 +109,7 @@ static void remote_copy_file(PGconn *conn, pgFile* file);
108
109
static void pg_ptrack_clear (void );
109
110
static bool pg_ptrack_support (void );
110
111
static bool pg_ptrack_enable (void );
112
+ static bool pg_checksum_enable (void );
111
113
static bool pg_is_in_recovery (void );
112
114
static bool pg_ptrack_get_and_clear_db (Oid dbOid , Oid tblspcOid );
113
115
static char * pg_ptrack_get_and_clear (Oid tablespace_oid ,
@@ -772,6 +774,9 @@ do_backup(time_t start_time)
772
774
/* TODO fix it for remote backup*/
773
775
if (!is_remote_backup )
774
776
current .checksum_version = get_data_checksum_version (true);
777
+
778
+ is_checksum_enabled = pg_checksum_enable ();
779
+
775
780
StrNCpy (current .server_version , server_version_str ,
776
781
sizeof (current .server_version ));
777
782
current .stream = stream_wal ;
@@ -1094,6 +1099,23 @@ pg_ptrack_enable(void)
1094
1099
return true;
1095
1100
}
1096
1101
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
+
1097
1119
/* Check if target instance is replica */
1098
1120
static bool
1099
1121
pg_is_in_recovery (void )
@@ -2683,31 +2705,6 @@ pg_ptrack_get_block(Oid dbOid,
2683
2705
params [2 ] = palloc (64 );
2684
2706
params [3 ] = palloc (64 );
2685
2707
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
-
2711
2708
/*
2712
2709
* Use backup_conn, cause we can do it from any database.
2713
2710
*/
@@ -2739,9 +2736,6 @@ pg_ptrack_get_block(Oid dbOid,
2739
2736
result = (char * ) PQunescapeBytea ((unsigned char * ) PQgetvalue (res , 0 , 0 ),
2740
2737
result_size );
2741
2738
2742
- // pgut_disconnect(tmp_conn);
2743
- // PQclear(res_db);
2744
-
2745
2739
PQclear (res );
2746
2740
pfree (params [0 ]);
2747
2741
pfree (params [1 ]);
0 commit comments