diff --git a/backup.c b/backup.c index 16f5a8f3..eb498d7e 100644 --- a/backup.c +++ b/backup.c @@ -66,6 +66,7 @@ static void get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_back static void get_xid(PGresult *res, uint32 *xid); static void pg_ptrack_clear(void); static bool pg_ptrack_support(void); +static bool pg_is_in_recovery(void); static char *pg_ptrack_get_and_clear(Oid tablespace_oid, Oid db_oid, Oid rel_oid, @@ -115,6 +116,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt) pgBackup *prev_backup = NULL; /* Block backup operations on a standby */ + from_replica = pg_is_in_recovery(); if (pg_is_standby() && !from_replica) elog(ERROR, "Backup cannot run on a standby."); @@ -653,9 +655,29 @@ pg_ptrack_support(void) disconnect(); return false; } + PQclear(res_db); + disconnect(); return true; } +static bool +pg_is_in_recovery(void) +{ + PGresult *res_db; + reconnect(); + res_db = execute("SELECT pg_is_in_recovery()", 0, NULL); + + if (PQgetvalue(res_db, 0, 0)[0] == 't') + { + PQclear(res_db); + disconnect(); + return true; + } + PQclear(res_db); + disconnect(); + return false; +} + static void pg_ptrack_clear(void) { diff --git a/doc/pg_arman.md b/doc/pg_arman.md index d0a891ce..0874aba2 100644 --- a/doc/pg_arman.md +++ b/doc/pg_arman.md @@ -246,9 +246,6 @@ absolute paths; relative paths are not allowed. **--stream**: Enable stream replication for save WAL during backup process. -**--from-replica**: - Use non exclusive start backup for replica. Only for 9.6 and higher. - ### RESTORE OPTIONS diff --git a/expected/option.out b/expected/option.out index df838958..0c5be607 100644 --- a/expected/option.out +++ b/expected/option.out @@ -26,7 +26,6 @@ Backup options: --keep-data-generations=N keep GENERATION of full data backup --keep-data-days=DAY keep enough data backup to recover to DAY days age --backup-pg-log start backup pg_log directory - --from-replica use non exclusive start backup for replica Restore options: --recovery-target-time time stamp up to which recovery will proceed diff --git a/pg_arman.c b/pg_arman.c index 3da6c098..e5ef97d4 100644 --- a/pg_arman.c +++ b/pg_arman.c @@ -67,7 +67,6 @@ static pgut_option options[] = { 'b', 10, "backup-pg-log", &backup_logs }, { 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_ENV }, { 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_ENV }, - { 'b', 12, "from-replica", &from_replica }, /* options with only long name (keep-xxx) */ { 'i', 1, "keep-data-generations", &keep_data_generations, SOURCE_ENV }, { 'i', 2, "keep-data-days", &keep_data_days, SOURCE_ENV }, @@ -247,7 +246,6 @@ pgut_help(bool details) 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(_(" --backup-pg-log start backup pg_log directory\n")); - printf(_(" --from-replica use non exclusive start backup for replica\n")); printf(_("\nRestore options:\n")); printf(_(" --recovery-target-time time stamp up to which recovery will proceed\n")); printf(_(" --recovery-target-xid transaction ID up to which recovery will proceed\n"));