Skip to content

Commit 5276687

Browse files
committed
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
1 parent 6264cd3 commit 5276687

File tree

12 files changed

+58
-56
lines changed

12 files changed

+58
-56
lines changed

src/backend/access/rmgrdesc/xlogdesc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
#include "postgres.h"
1616

17+
#include "access/xlog.h"
1718
#include "access/xlog_internal.h"
1819
#include "catalog/pg_control.h"
1920
#include "utils/guc.h"

src/backend/access/transam/xlogarchive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <signal.h>
2121
#include <unistd.h>
2222

23+
#include "access/xlog.h"
2324
#include "access/xlog_internal.h"
2425
#include "miscadmin.h"
2526
#include "postmaster/startup.h"

src/backend/access/transam/xlogfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "access/htup_details.h"
2020
#include "access/xlog.h"
21+
#include "access/xlog_fn.h"
2122
#include "access/xlog_internal.h"
2223
#include "access/xlogutils.h"
2324
#include "catalog/catalog.h"

src/backend/postmaster/bgwriter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <time.h>
4040
#include <unistd.h>
4141

42+
#include "access/xlog.h"
4243
#include "access/xlog_internal.h"
4344
#include "libpq/pqsignal.h"
4445
#include "miscadmin.h"

src/backend/postmaster/checkpointer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <time.h>
4242
#include <unistd.h>
4343

44+
#include "access/xlog.h"
4445
#include "access/xlog_internal.h"
4546
#include "libpq/pqsignal.h"
4647
#include "miscadmin.h"

src/backend/postmaster/pgarch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <sys/wait.h>
3333
#include <unistd.h>
3434

35+
#include "access/xlog.h"
3536
#include "access/xlog_internal.h"
3637
#include "libpq/pqsignal.h"
3738
#include "miscadmin.h"

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
*-------------------------------------------------------------------------
1212
*/
1313

14-
/*
15-
* We have to use postgres.h not postgres_fe.h here, because there's so much
16-
* backend-only stuff in the XLOG include files we need. But we need a
17-
* frontend-ish environment otherwise. Hence this ugly hack.
18-
*/
19-
#define FRONTEND 1
20-
#include "postgres.h"
14+
#include "postgres_fe.h"
2115
#include "libpq-fe.h"
2216

2317
#include <unistd.h>

src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
*-------------------------------------------------------------------------
1313
*/
1414

15-
/*
16-
* We have to use postgres.h not postgres_fe.h here, because there's so much
17-
* backend-only stuff in the XLOG include files we need. But we need a
18-
* frontend-ish environment otherwise. Hence this ugly hack.
19-
*/
20-
#define FRONTEND 1
21-
#include "postgres.h"
15+
#include "postgres_fe.h"
2216
#include "libpq-fe.h"
2317
#include "libpq/pqsignal.h"
2418
#include "access/xlog_internal.h"

src/bin/pg_basebackup/receivelog.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
* src/bin/pg_basebackup/receivelog.c
1212
*-------------------------------------------------------------------------
1313
*/
14-
15-
/*
16-
* We have to use postgres.h not postgres_fe.h here, because there's so much
17-
* backend-only stuff in the XLOG include files we need. But we need a
18-
* frontend-ish environment otherwise. Hence this ugly hack.
19-
*/
20-
#define FRONTEND 1
21-
#include "postgres.h"
14+
#include "postgres_fe.h"
2215

2316
#include <sys/stat.h>
2417
#include <sys/time.h>
@@ -30,8 +23,6 @@
3023

3124
#include "libpq-fe.h"
3225
#include "access/xlog_internal.h"
33-
#include "utils/datetime.h"
34-
#include "utils/timestamp.h"
3526

3627
#include "receivelog.h"
3728
#include "streamutil.h"

src/bin/pg_basebackup/streamutil.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
*-------------------------------------------------------------------------
1212
*/
1313

14-
/*
15-
* We have to use postgres.h not postgres_fe.h here, because there's so much
16-
* backend-only stuff in the XLOG include files we need. But we need a
17-
* frontend-ish environment otherwise. Hence this ugly hack.
18-
*/
19-
#define FRONTEND 1
20-
#include "postgres.h"
14+
#include "postgres_fe.h"
2115
#include "streamutil.h"
2216

2317
#include <stdio.h>

src/include/access/xlog_fn.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* xlog_fn.h
3+
*
4+
* PostgreSQL transaction log SQL-callable function declarations
5+
*
6+
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* src/include/access/xlog_fn.h
10+
*/
11+
#ifndef XLOG_FN_H
12+
#define XLOG_FN_H
13+
14+
#include "fmgr.h"
15+
16+
extern Datum pg_start_backup(PG_FUNCTION_ARGS);
17+
extern Datum pg_stop_backup(PG_FUNCTION_ARGS);
18+
extern Datum pg_switch_xlog(PG_FUNCTION_ARGS);
19+
extern Datum pg_create_restore_point(PG_FUNCTION_ARGS);
20+
extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
21+
extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS);
22+
extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS);
23+
extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS);
24+
extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS);
25+
extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS);
26+
extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS);
27+
extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS);
28+
extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS);
29+
extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS);
30+
extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS);
31+
extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS);
32+
extern Datum pg_is_in_backup(PG_FUNCTION_ARGS);
33+
extern Datum pg_backup_start_time(PG_FUNCTION_ARGS);
34+
35+
#endif /* XLOG_FN_H */

src/include/access/xlog_internal.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* needed by rmgr routines (redo support for individual record types).
99
* So the XLogRecord typedef and associated stuff appear in xlog.h.
1010
*
11+
* Note: This file must be includable in both frontend and backend contexts,
12+
* to allow stand-alone tools like pg_receivexlog to deal with WAL files.
13+
*
1114
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
1215
* Portions Copyright (c) 1994, Regents of the University of California
1316
*
@@ -16,8 +19,9 @@
1619
#ifndef XLOG_INTERNAL_H
1720
#define XLOG_INTERNAL_H
1821

19-
#include "access/xlog.h"
20-
#include "fmgr.h"
22+
#include "access/xlogdefs.h"
23+
#include "datatype/timestamp.h"
24+
#include "lib/stringinfo.h"
2125
#include "pgtime.h"
2226
#include "storage/block.h"
2327
#include "storage/relfilenode.h"
@@ -225,6 +229,12 @@ typedef struct xl_restore_point
225229
} xl_restore_point;
226230

227231

232+
/*
233+
* XLogRecord is defined in xlog.h, but we avoid #including that to keep
234+
* this file includable in stand-alone programs.
235+
*/
236+
struct XLogRecord;
237+
228238
/*
229239
* Method table for resource managers.
230240
*
@@ -233,7 +243,7 @@ typedef struct xl_restore_point
233243
typedef struct RmgrData
234244
{
235245
const char *rm_name;
236-
void (*rm_redo) (XLogRecPtr lsn, XLogRecord *rptr);
246+
void (*rm_redo) (XLogRecPtr lsn, struct XLogRecord *rptr);
237247
void (*rm_desc) (StringInfo buf, uint8 xl_info, char *rec);
238248
void (*rm_startup) (void);
239249
void (*rm_cleanup) (void);
@@ -272,26 +282,4 @@ extern bool XLogArchiveCheckDone(const char *xlog);
272282
extern bool XLogArchiveIsBusy(const char *xlog);
273283
extern void XLogArchiveCleanup(const char *xlog);
274284

275-
/*
276-
* These aren't in xlog.h because I'd rather not include fmgr.h there.
277-
*/
278-
extern Datum pg_start_backup(PG_FUNCTION_ARGS);
279-
extern Datum pg_stop_backup(PG_FUNCTION_ARGS);
280-
extern Datum pg_switch_xlog(PG_FUNCTION_ARGS);
281-
extern Datum pg_create_restore_point(PG_FUNCTION_ARGS);
282-
extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS);
283-
extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS);
284-
extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS);
285-
extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS);
286-
extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS);
287-
extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS);
288-
extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS);
289-
extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS);
290-
extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS);
291-
extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS);
292-
extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS);
293-
extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS);
294-
extern Datum pg_is_in_backup(PG_FUNCTION_ARGS);
295-
extern Datum pg_backup_start_time(PG_FUNCTION_ARGS);
296-
297285
#endif /* XLOG_INTERNAL_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy