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

[Issue #134] PostgreSQL 12 support

This commit is contained in:
Grigory Smolkin 2019-10-18 12:36:42 +03:00
parent 8ce5b7a241
commit 19ad13d777
4 changed files with 134 additions and 6 deletions

View File

@ -57,8 +57,6 @@ src/datapagemap.c: $(top_srcdir)/src/bin/pg_rewind/datapagemap.c
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_rewind/datapagemap.c $@
src/datapagemap.h: $(top_srcdir)/src/bin/pg_rewind/datapagemap.h
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_rewind/datapagemap.h $@
src/logging.h: $(top_srcdir)/src/bin/pg_rewind/logging.h
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_rewind/logging.h $@
src/pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
rm -f $@ && $(LN_S) $(srchome)/src/backend/utils/hash/pg_crc.c $@
src/receivelog.c: $(top_srcdir)/src/bin/pg_basebackup/receivelog.c
@ -72,6 +70,14 @@ src/streamutil.h: $(top_srcdir)/src/bin/pg_basebackup/streamutil.h
src/xlogreader.c: $(top_srcdir)/src/backend/access/transam/xlogreader.c
rm -f $@ && $(LN_S) $(srchome)/src/backend/access/transam/xlogreader.c $@
ifeq (12,$(MAJORVERSION))
src/logging.h: $(top_srcdir)/src/include/common/logging.h
rm -f $@ && $(LN_S) $(srchome)/src/include/common/logging.h $@
else
src/logging.h: $(top_srcdir)/src/bin/pg_rewind/logging.h
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_rewind/logging.h $@
endif
ifeq (,$(filter 9.5 9.6,$(MAJORVERSION)))
src/walmethods.c: $(top_srcdir)/src/bin/pg_basebackup/walmethods.c
rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/walmethods.c $@

View File

@ -111,7 +111,12 @@ do_decompress(void* dst, size_t dst_size, void const* src, size_t src_size,
}
#endif
case PGLZ_COMPRESS:
#if PG_VERSION_NUM >= 120000
return pglz_decompress(src, src_size, dst, dst_size, true);
#else
return pglz_decompress(src, src_size, dst, dst_size);
#endif
}
return -1;

View File

@ -79,6 +79,7 @@ static char *pgdata_exclude_files[] =
"recovery.conf",
"postmaster.pid",
"postmaster.opts",
"probackup_recovery.conf",
NULL
};

View File

@ -44,6 +44,7 @@ static void create_recovery_conf(time_t backup_id,
pgRestoreParams *params);
static void *restore_files(void *arg);
static void set_orphan_status(parray *backups, pgBackup *parent_backup);
static void create_pg12_recovery_config(pgBackup *backup, bool add_include);
/*
* Iterate over backup list to find all ancestors of the broken parent_backup
@ -866,24 +867,43 @@ create_recovery_conf(time_t backup_id,
/* No need to generate recovery.conf at all. */
if (!(need_restore_conf || params->restore_as_replica))
{
#if PG_VERSION_NUM >= 120000
/*
* Restoring STREAM backup without PITR and not as replica,
* recovery.signal and standby.signal are not needed
*/
create_pg12_recovery_config(backup, false);
#endif
return;
}
elog(LOG, "----------------------------------------");
#if PG_VERSION_NUM >= 120000
elog(LOG, "creating probackup_recovery.conf");
create_pg12_recovery_config(backup, true);
snprintf(path, lengthof(path), "%s/probackup_recovery.conf", instance_config.pgdata);
#else
elog(LOG, "creating recovery.conf");
snprintf(path, lengthof(path), "%s/recovery.conf", instance_config.pgdata);
#endif
fp = fio_fopen(path, "w", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot open recovery.conf \"%s\": %s", path,
elog(ERROR, "cannot open file \"%s\": %s", path,
strerror(errno));
#if PG_VERSION_NUM >= 120000
fio_fprintf(fp, "# probackup_recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
#else
fio_fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
PROGRAM_VERSION);
#endif
/* construct restore_command */
if (need_restore_conf)
{
char restore_command_guc[16384];
/* If restore_command is provided, use it */
@ -957,7 +977,10 @@ create_recovery_conf(time_t backup_id,
if (params->restore_as_replica)
{
/* standby_mode was removed in PG12 */
#if PG_VERSION_NUM < 120000
fio_fprintf(fp, "standby_mode = 'on'\n");
#endif
if (backup->primary_conninfo)
fio_fprintf(fp, "primary_conninfo = '%s'\n", backup->primary_conninfo);
@ -965,7 +988,100 @@ create_recovery_conf(time_t backup_id,
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write recovery.conf \"%s\": %s", path,
elog(ERROR, "cannot write file \"%s\": %s", path,
strerror(errno));
#if PG_VERSION_NUM >= 120000
if (need_restore_conf)
{
elog(LOG, "creating recovery.signal file");
snprintf(path, lengthof(path), "%s/recovery.signal", instance_config.pgdata);
fp = fio_fopen(path, "w", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot open file \"%s\": %s", path,
strerror(errno));
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write file \"%s\": %s", path,
strerror(errno));
}
if (params->restore_as_replica)
{
elog(LOG, "creating standby.signal file");
snprintf(path, lengthof(path), "%s/standby.signal", instance_config.pgdata);
fp = fio_fopen(path, "w", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot open file \"%s\": %s", path,
strerror(errno));
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write file \"%s\": %s", path,
strerror(errno));
}
#endif
}
/*
* Create empty probackup_recovery.conf in PGDATA and
* add include directive to postgresql.auto.conf
* When restoring PG12 we always(!) must do this, even
* when restoring STREAM backup without PITR options
* because restored instance may have been backed up
* and restored again and user didn`t cleaned up postgresql.auto.conf.
* So for recovery to work regardless of all this factors
* we must always create empty probackup_recovery.conf file.
*/
static void
create_pg12_recovery_config(pgBackup *backup, bool add_include)
{
char probackup_recovery_path[MAXPGPATH];
char postgres_auto_path[MAXPGPATH];
FILE *fp;
if (add_include)
{
time_t current_time;
char current_time_str[100];
current_time = time(NULL);
time2iso(current_time_str, lengthof(current_time_str), current_time);
snprintf(postgres_auto_path, lengthof(postgres_auto_path),
"%s/postgresql.auto.conf", instance_config.pgdata);
fp = fio_fopen(postgres_auto_path, "a", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot write to file \"%s\": %s", postgres_auto_path,
strerror(errno));
fio_fprintf(fp, "\n# created by pg_probackup restore of backup %s at '%s'\n",
base36enc(backup->start_time), current_time_str);
fio_fprintf(fp, "include '%s'\n", "probackup_recovery.conf");
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write to file \"%s\": %s", postgres_auto_path,
strerror(errno));
}
/* Create empty probackup_recovery.conf */
snprintf(probackup_recovery_path, lengthof(probackup_recovery_path),
"%s/probackup_recovery.conf", instance_config.pgdata);
fp = fio_fopen(probackup_recovery_path, "w", FIO_DB_HOST);
if (fp == NULL)
elog(ERROR, "cannot open file \"%s\": %s", probackup_recovery_path,
strerror(errno));
if (fio_fflush(fp) != 0 ||
fio_fclose(fp))
elog(ERROR, "cannot write to file \"%s\": %s", probackup_recovery_path,
strerror(errno));
}