diff --git a/backup.c b/backup.c index 1df507f7..16f5a8f3 100644 --- a/backup.c +++ b/backup.c @@ -65,6 +65,7 @@ static bool pg_is_standby(void); static void get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_backup); static void get_xid(PGresult *res, uint32 *xid); static void pg_ptrack_clear(void); +static bool pg_ptrack_support(void); static char *pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid, @@ -106,6 +107,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt) pthread_t backup_threads[num_threads]; pthread_t stream_thread; backup_files_args *backup_threads_args[num_threads]; + bool is_ptrack_support; /* repack the options */ @@ -131,6 +133,10 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt) */ current.tli = get_current_timeline(false); + is_ptrack_support = pg_ptrack_support(); + if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK && !is_ptrack_support) + elog(ERROR, "Current Postgres instance is not support ptrack"); + /* * In differential backup mode, check if there is an already-validated * full backup on current timeline. @@ -148,7 +154,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt) } /* clear ptrack files for FULL and DIFF backup */ - if (current.backup_mode != BACKUP_MODE_DIFF_PTRACK && !disable_ptrack_clear) + if (current.backup_mode != BACKUP_MODE_DIFF_PTRACK && is_ptrack_support) pg_ptrack_clear(); /* notify start of backup to PostgreSQL server */ @@ -635,6 +641,21 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup) PQclear(res); } +static bool +pg_ptrack_support(void) +{ + PGresult *res_db; + reconnect(); + res_db = execute("SELECT proname FROM pg_proc WHERE proname='pg_ptrack_clear'", 0, NULL); + if (PQntuples(res_db) == 0) + { + PQclear(res_db); + disconnect(); + return false; + } + return true; +} + static void pg_ptrack_clear(void) { diff --git a/expected/option.out b/expected/option.out index 5f8ed6c3..45bda554 100644 --- a/expected/option.out +++ b/expected/option.out @@ -26,7 +26,6 @@ Backup options: --validate validate backup after taking it --keep-data-generations=N keep GENERATION of full data backup --keep-data-days=DAY keep enough data backup to recover to DAY days age - --disable-ptrack-clear disable clear ptrack for postgres without ptrack --backup-pg-log start backup pg_log directory --from-replica use non exclusive start backup for replica diff --git a/pg_arman.c b/pg_arman.c index 19a2f177..4b2e0e05 100644 --- a/pg_arman.c +++ b/pg_arman.c @@ -37,7 +37,6 @@ static int keep_data_days = KEEP_INFINITE; int num_threads = 1; bool stream_wal = false; bool from_replica = false; -bool disable_ptrack_clear = false; static bool backup_logs = false; static bool backup_validate = false; bool progress = false; @@ -66,7 +65,6 @@ static pgut_option options[] = { 'b', 8, "stream", &stream_wal }, { 'b', 11, "progress", &progress }, /* backup options */ - { 'b', 9, "disable-ptrack-clear", &disable_ptrack_clear }, { 'b', 10, "backup-pg-log", &backup_logs }, { 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_ENV }, { 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_ENV }, @@ -255,7 +253,6 @@ pgut_help(bool details) printf(_(" --validate validate backup after taking it\n")); printf(_(" --keep-data-generations=N keep GENERATION of full data backup\n")); printf(_(" --keep-data-days=DAY keep enough data backup to recover to DAY days age\n")); - printf(_(" --disable-ptrack-clear disable clear ptrack for postgres without ptrack\n")); printf(_(" --backup-pg-log start backup pg_log directory\n")); printf(_(" --from-replica use non exclusive start backup for replica\n")); printf(_("\nRestore options:\n")); diff --git a/pg_arman.h b/pg_arman.h index 5a997e2d..f6ccd9e0 100644 --- a/pg_arman.h +++ b/pg_arman.h @@ -213,7 +213,6 @@ extern parray *backup_files_list; extern int num_threads; extern bool stream_wal; extern bool from_replica; -extern bool disable_ptrack_clear; extern bool progress; /* in backup.c */