@@ -783,13 +783,16 @@ do_backup(void)
783
783
784
784
is_ptrack_support = pg_ptrack_support ();
785
785
786
- if (!is_ptrack_support )
787
- elog (ERROR ,"This PostgreSQL instance does not support ptrack" );
788
- else
786
+ if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK )
789
787
{
790
- is_ptrack_enable = pg_ptrack_enable ();
791
- if (!is_ptrack_enable )
792
- elog (ERROR ,"Ptrack is disabled" );
788
+ if (!is_ptrack_support )
789
+ elog (ERROR ,"This PostgreSQL instance does not support ptrack" );
790
+ else
791
+ {
792
+ is_ptrack_enable = pg_ptrack_enable ();
793
+ if (!is_ptrack_enable )
794
+ elog (ERROR ,"Ptrack is disabled" );
795
+ }
793
796
}
794
797
795
798
/* archiving check */
@@ -1180,12 +1183,34 @@ static bool
1180
1183
pg_ptrack_get_and_clear_db (Oid dbOid ,Oid tblspcOid )
1181
1184
{
1182
1185
char * params [2 ];
1186
+ PGresult * res_db ;
1183
1187
PGresult * res ;
1184
1188
char * result ;
1185
1189
1186
1190
params [0 ]= palloc (64 );
1187
1191
params [1 ]= palloc (64 );
1188
1192
1193
+ sprintf (params [0 ],"%i" ,dbOid );
1194
+ res_db = pgut_execute (backup_conn ,
1195
+ "SELECT datname FROM pg_database WHERE oid=$1" ,
1196
+ 1 , (const char * * )params );
1197
+ /*
1198
+ * If database is not found, it's not an error.
1199
+ * It could have been deleted since previous backup.
1200
+ */
1201
+ if (PQntuples (res_db )!= 1 || PQnfields (res_db )!= 1 )
1202
+ return false;
1203
+
1204
+ dbname = pstrdup (PQgetvalue (res_db ,0 ,0 ));
1205
+ PQclear (res_db );
1206
+
1207
+ /* Always backup all files from template0 database */
1208
+ if (strcmp (dbname ,"template0" )== 0 )
1209
+ {
1210
+ pfree (dbname );
1211
+ return true;
1212
+ }
1213
+
1189
1214
sprintf (params [0 ],"%i" ,dbOid );
1190
1215
sprintf (params [1 ],"%i" ,tblspcOid );
1191
1216
res = pgut_execute (backup_conn ,"SELECT pg_ptrack_get_and_clear_db($1, $2)" ,
@@ -2178,7 +2203,6 @@ make_pagemap_from_ptrack(parray *files)
2178
2203
Oid dbOid_with_ptrack_init = 0 ;
2179
2204
Oid tblspcOid_with_ptrack_init = 0 ;
2180
2205
bool ignore_ptrack_for_db = false;
2181
- bool is_template = false;
2182
2206
2183
2207
for (i = 0 ;i < parray_num (files );i ++ )
2184
2208
{
@@ -2195,24 +2219,17 @@ make_pagemap_from_ptrack(parray *files)
2195
2219
{
2196
2220
char * filename = strrchr (file -> path ,'/' );
2197
2221
ignore_ptrack_for_db = false;
2198
- is_template = false;
2199
2222
2200
2223
Assert (filename != NULL );
2201
2224
filename ++ ;
2202
2225
2203
- /* Always backup all files from template0, template1 databases */
2204
- if ((file -> dbOid == 1 )|| //dbOid of template1 daatbase
2205
- (file -> dbOid == 12442 ))//dbOid of template0 daatbase
2206
- {
2207
- is_template = true;
2208
- }
2209
2226
/*
2210
2227
* The function pg_ptrack_get_and_clear_db returns true
2211
2228
* if there was a ptrack_init file.
2212
2229
* Also ignore ptrack files for global tablespace,
2213
2230
* to avoid any possible specific errors.
2214
2231
*/
2215
- else if ((file -> tblspcOid == GLOBALTABLESPACE_OID )||
2232
+ if ((file -> tblspcOid == GLOBALTABLESPACE_OID )||
2216
2233
pg_ptrack_get_and_clear_db (file -> dbOid ,file -> tblspcOid ))
2217
2234
{
2218
2235
ignore_ptrack_for_db = true;
@@ -2221,7 +2238,7 @@ make_pagemap_from_ptrack(parray *files)
2221
2238
}
2222
2239
}
2223
2240
2224
- if (file -> is_datafile && ! is_template )
2241
+ if (file -> is_datafile )
2225
2242
{
2226
2243
/* get ptrack bitmap once for all segments of the file */
2227
2244
if (file -> segno == 0 )