1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-11-28 09:33:54 +02:00

Add automatic detect of replica and remove same option.

This commit is contained in:
stalkerg 2016-10-25 14:38:51 +03:00
parent f0703e527c
commit af0e674cbb
4 changed files with 22 additions and 6 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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

View File

@ -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"));