From 527668717a660e67c2a6cfd4e85f7a513f99f6f2 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 13 Dec 2012 14:59:13 +0200 Subject: [PATCH] Make xlog_internal.h includable in frontend context. This makes unnecessary the ugly hack used to #include postgres.h in pg_basebackup. Based on Alvaro Herrera's patch --- src/backend/access/rmgrdesc/xlogdesc.c | 1 + src/backend/access/transam/xlogarchive.c | 1 + src/backend/access/transam/xlogfuncs.c | 1 + src/backend/postmaster/bgwriter.c | 1 + src/backend/postmaster/checkpointer.c | 1 + src/backend/postmaster/pgarch.c | 1 + src/bin/pg_basebackup/pg_basebackup.c | 8 +---- src/bin/pg_basebackup/pg_receivexlog.c | 8 +---- src/bin/pg_basebackup/receivelog.c | 11 +------ src/bin/pg_basebackup/streamutil.c | 8 +---- src/include/access/xlog_fn.h | 35 ++++++++++++++++++++++ src/include/access/xlog_internal.h | 38 ++++++++---------------- 12 files changed, 58 insertions(+), 56 deletions(-) create mode 100644 src/include/access/xlog_fn.h diff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c index 862e3fa754..c958a4ff53 100644 --- a/src/backend/access/rmgrdesc/xlogdesc.c +++ b/src/backend/access/rmgrdesc/xlogdesc.c @@ -14,6 +14,7 @@ */ #include "postgres.h" +#include "access/xlog.h" #include "access/xlog_internal.h" #include "catalog/pg_control.h" #include "utils/guc.h" diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c index 9bd6b8e3a2..0ef53e7cbf 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -20,6 +20,7 @@ #include #include +#include "access/xlog.h" #include "access/xlog_internal.h" #include "miscadmin.h" #include "postmaster/startup.h" diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index d345761598..40c0bd67b5 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -18,6 +18,7 @@ #include "access/htup_details.h" #include "access/xlog.h" +#include "access/xlog_fn.h" #include "access/xlog_internal.h" #include "access/xlogutils.h" #include "catalog/catalog.h" diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 709ccf1f25..ff0a9cb560 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -39,6 +39,7 @@ #include #include +#include "access/xlog.h" #include "access/xlog_internal.h" #include "libpq/pqsignal.h" #include "miscadmin.h" diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 18e6a4e8c4..c8a68a1b22 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -41,6 +41,7 @@ #include #include +#include "access/xlog.h" #include "access/xlog_internal.h" #include "libpq/pqsignal.h" #include "miscadmin.h" diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index a6c0aea3d6..b075231ed3 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -32,6 +32,7 @@ #include #include +#include "access/xlog.h" #include "access/xlog_internal.h" #include "libpq/pqsignal.h" #include "miscadmin.h" diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 4f22116c3e..4249c0417d 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -11,13 +11,7 @@ *------------------------------------------------------------------------- */ -/* - * We have to use postgres.h not postgres_fe.h here, because there's so much - * backend-only stuff in the XLOG include files we need. But we need a - * frontend-ish environment otherwise. Hence this ugly hack. - */ -#define FRONTEND 1 -#include "postgres.h" +#include "postgres_fe.h" #include "libpq-fe.h" #include diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c index 54524834f7..7f6121a945 100644 --- a/src/bin/pg_basebackup/pg_receivexlog.c +++ b/src/bin/pg_basebackup/pg_receivexlog.c @@ -12,13 +12,7 @@ *------------------------------------------------------------------------- */ -/* - * We have to use postgres.h not postgres_fe.h here, because there's so much - * backend-only stuff in the XLOG include files we need. But we need a - * frontend-ish environment otherwise. Hence this ugly hack. - */ -#define FRONTEND 1 -#include "postgres.h" +#include "postgres_fe.h" #include "libpq-fe.h" #include "libpq/pqsignal.h" #include "access/xlog_internal.h" diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index de82ff54d8..8502d56067 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -11,14 +11,7 @@ * src/bin/pg_basebackup/receivelog.c *------------------------------------------------------------------------- */ - -/* - * We have to use postgres.h not postgres_fe.h here, because there's so much - * backend-only stuff in the XLOG include files we need. But we need a - * frontend-ish environment otherwise. Hence this ugly hack. - */ -#define FRONTEND 1 -#include "postgres.h" +#include "postgres_fe.h" #include #include @@ -30,8 +23,6 @@ #include "libpq-fe.h" #include "access/xlog_internal.h" -#include "utils/datetime.h" -#include "utils/timestamp.h" #include "receivelog.h" #include "streamutil.h" diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 22f4128180..2ab0d8a4e8 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -11,13 +11,7 @@ *------------------------------------------------------------------------- */ -/* - * We have to use postgres.h not postgres_fe.h here, because there's so much - * backend-only stuff in the XLOG include files we need. But we need a - * frontend-ish environment otherwise. Hence this ugly hack. - */ -#define FRONTEND 1 -#include "postgres.h" +#include "postgres_fe.h" #include "streamutil.h" #include diff --git a/src/include/access/xlog_fn.h b/src/include/access/xlog_fn.h new file mode 100644 index 0000000000..65376fe509 --- /dev/null +++ b/src/include/access/xlog_fn.h @@ -0,0 +1,35 @@ +/* + * xlog_fn.h + * + * PostgreSQL transaction log SQL-callable function declarations + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlog_fn.h + */ +#ifndef XLOG_FN_H +#define XLOG_FN_H + +#include "fmgr.h" + +extern Datum pg_start_backup(PG_FUNCTION_ARGS); +extern Datum pg_stop_backup(PG_FUNCTION_ARGS); +extern Datum pg_switch_xlog(PG_FUNCTION_ARGS); +extern Datum pg_create_restore_point(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS); +extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS); +extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS); +extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS); +extern Datum pg_is_in_backup(PG_FUNCTION_ARGS); +extern Datum pg_backup_start_time(PG_FUNCTION_ARGS); + +#endif /* XLOG_FN_H */ diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index 89252d0230..0acebd4e28 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -8,6 +8,9 @@ * needed by rmgr routines (redo support for individual record types). * So the XLogRecord typedef and associated stuff appear in xlog.h. * + * Note: This file must be includable in both frontend and backend contexts, + * to allow stand-alone tools like pg_receivexlog to deal with WAL files. + * * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * @@ -16,8 +19,9 @@ #ifndef XLOG_INTERNAL_H #define XLOG_INTERNAL_H -#include "access/xlog.h" -#include "fmgr.h" +#include "access/xlogdefs.h" +#include "datatype/timestamp.h" +#include "lib/stringinfo.h" #include "pgtime.h" #include "storage/block.h" #include "storage/relfilenode.h" @@ -225,6 +229,12 @@ typedef struct xl_restore_point } xl_restore_point; +/* + * XLogRecord is defined in xlog.h, but we avoid #including that to keep + * this file includable in stand-alone programs. + */ +struct XLogRecord; + /* * Method table for resource managers. * @@ -233,7 +243,7 @@ typedef struct xl_restore_point typedef struct RmgrData { const char *rm_name; - void (*rm_redo) (XLogRecPtr lsn, XLogRecord *rptr); + void (*rm_redo) (XLogRecPtr lsn, struct XLogRecord *rptr); void (*rm_desc) (StringInfo buf, uint8 xl_info, char *rec); void (*rm_startup) (void); void (*rm_cleanup) (void); @@ -272,26 +282,4 @@ extern bool XLogArchiveCheckDone(const char *xlog); extern bool XLogArchiveIsBusy(const char *xlog); extern void XLogArchiveCleanup(const char *xlog); -/* - * These aren't in xlog.h because I'd rather not include fmgr.h there. - */ -extern Datum pg_start_backup(PG_FUNCTION_ARGS); -extern Datum pg_stop_backup(PG_FUNCTION_ARGS); -extern Datum pg_switch_xlog(PG_FUNCTION_ARGS); -extern Datum pg_create_restore_point(PG_FUNCTION_ARGS); -extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS); -extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS); -extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS); -extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS); -extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS); -extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS); -extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS); -extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS); -extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS); -extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS); -extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS); -extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS); -extern Datum pg_is_in_backup(PG_FUNCTION_ARGS); -extern Datum pg_backup_start_time(PG_FUNCTION_ARGS); - #endif /* XLOG_INTERNAL_H */ -- 2.40.0