Skip to content

Commit e6ec0f2

Browse files
committed
Check if archiving is enabled during archive backup
1 parent 9f9c95c commit e6ec0f2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

backup.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void pg_ptrack_clear(void);
7373
static bool pg_ptrack_support(void);
7474
static bool pg_ptrack_enable(void);
7575
static bool pg_is_in_recovery(void);
76+
static bool pg_archive_enabled(void);
7677
static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
7778
Oid db_oid,
7879
Oid rel_oid,
@@ -410,6 +411,10 @@ do_backup(void)
410411
elog(ERROR, "Ptrack is disabled");
411412
}
412413

414+
/* archiving check */
415+
if (!current.stream && !pg_archive_enabled())
416+
elog(ERROR, "Archiving must be enabled for archive backup");
417+
413418
/* Get exclusive lock of backup catalog */
414419
catalog_lock();
415420

@@ -676,6 +681,25 @@ pg_is_in_recovery(void)
676681
return false;
677682
}
678683

684+
/*
685+
* Check if archiving is enabled
686+
*/
687+
static bool
688+
pg_archive_enabled(void)
689+
{
690+
PGresult *res_db;
691+
692+
res_db = pgut_execute(backup_conn, "show archive_mode", 0, NULL);
693+
694+
if (strcmp(PQgetvalue(res_db, 0, 0), "off") == 0)
695+
{
696+
PQclear(res_db);
697+
return false;
698+
}
699+
PQclear(res_db);
700+
return true;
701+
}
702+
679703
/* Clear ptrack files in all databases of the instance we connected to */
680704
static void
681705
pg_ptrack_clear(void)

0 commit comments

Comments
 (0)