Re: [HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-02-04 Thread Alvaro Herrera

I didn't like this bit too much:

 diff --git a/contrib/pg_xlogdump/tables.c b/contrib/pg_xlogdump/tables.c
 new file mode 100644
 index 000..e947e0d
 --- /dev/null
 +++ b/contrib/pg_xlogdump/tables.c
 @@ -0,0 +1,78 @@

 +/*
 + * RmgrTable linked only to functions available outside of the backend.
 + *
 + * needs to be synced with src/backend/access/transam/rmgr.c
 + */
 +const RmgrData RmgrTable[RM_MAX_ID + 1] = {
 + {XLOG, NULL, xlog_desc, NULL, NULL, NULL},
 + {Transaction, NULL, xact_desc, NULL, NULL, NULL},

So I propose the following patch instead.  This lets pg_xlogdump compile
only the file it needs, and not concern itself with the rest of rmgr.c.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services
commit 6779c7ff81323699e82252a6e5b92a97319cb924
Author: Alvaro Herrera alvhe...@alvh.no-ip.org
Date:   Mon Feb 4 13:12:54 2013 -0300

Split out rm_desc pointers into their own table

This allows the split file to be compiled by frontend code

diff --git a/src/backend/access/transam/Makefile b/src/backend/access/transam/Makefile
index eb6cfc5..3f1a9e4 100644
--- a/src/backend/access/transam/Makefile
+++ b/src/backend/access/transam/Makefile
@@ -12,9 +12,9 @@ subdir = src/backend/access/transam
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-OBJS = clog.o transam.o varsup.o xact.o rmgr.o slru.o subtrans.o multixact.o \
-	timeline.o twophase.o twophase_rmgr.o xlog.o xlogarchive.o xlogfuncs.o \
-	xlogreader.o xlogutils.o
+OBJS = clog.o multixact.o rmgrdesc.o rmgr.o slru.o subtrans.o timeline.o \
+	transam.o twophase.o twophase_rmgr.o varsup.o xact.o xlogarchive.o \
+	xlogfuncs.o xlog.o xlogreader.o xlogutils.o
 
 include $(top_srcdir)/src/backend/common.mk
 
diff --git a/src/backend/access/transam/rmgr.c b/src/backend/access/transam/rmgr.c
index cc210a7..0c0a2d1 100644
--- a/src/backend/access/transam/rmgr.c
+++ b/src/backend/access/transam/rmgr.c
@@ -24,23 +24,24 @@
 #include storage/standby.h
 #include utils/relmapper.h
 
+/* See rmgrdesc.c, too */
 
 const RmgrData RmgrTable[RM_MAX_ID + 1] = {
-	{XLOG, xlog_redo, xlog_desc, NULL, NULL, NULL},
-	{Transaction, xact_redo, xact_desc, NULL, NULL, NULL},
-	{Storage, smgr_redo, smgr_desc, NULL, NULL, NULL},
-	{CLOG, clog_redo, clog_desc, NULL, NULL, NULL},
-	{Database, dbase_redo, dbase_desc, NULL, NULL, NULL},
-	{Tablespace, tblspc_redo, tblspc_desc, NULL, NULL, NULL},
-	{MultiXact, multixact_redo, multixact_desc, NULL, NULL, NULL},
-	{RelMap, relmap_redo, relmap_desc, NULL, NULL, NULL},
-	{Standby, standby_redo, standby_desc, NULL, NULL, NULL},
-	{Heap2, heap2_redo, heap2_desc, NULL, NULL, NULL},
-	{Heap, heap_redo, heap_desc, NULL, NULL, NULL},
-	{Btree, btree_redo, btree_desc, btree_xlog_startup, btree_xlog_cleanup, btree_safe_restartpoint},
-	{Hash, hash_redo, hash_desc, NULL, NULL, NULL},
-	{Gin, gin_redo, gin_desc, gin_xlog_startup, gin_xlog_cleanup, gin_safe_restartpoint},
-	{Gist, gist_redo, gist_desc, gist_xlog_startup, gist_xlog_cleanup, NULL},
-	{Sequence, seq_redo, seq_desc, NULL, NULL, NULL},
-	{SPGist, spg_redo, spg_desc, spg_xlog_startup, spg_xlog_cleanup, NULL}
+	{XLOG, xlog_redo, NULL, NULL, NULL},
+	{Transaction, xact_redo, NULL, NULL, NULL},
+	{Storage, smgr_redo, NULL, NULL, NULL},
+	{CLOG, clog_redo, NULL, NULL, NULL},
+	{Database, dbase_redo, NULL, NULL, NULL},
+	{Tablespace, tblspc_redo, NULL, NULL, NULL},
+	{MultiXact, multixact_redo, NULL, NULL, NULL},
+	{RelMap, relmap_redo, NULL, NULL, NULL},
+	{Standby, standby_redo, NULL, NULL, NULL},
+	{Heap2, heap2_redo, NULL, NULL, NULL},
+	{Heap, heap_redo, NULL, NULL, NULL},
+	{Btree, btree_redo, btree_xlog_startup, btree_xlog_cleanup, btree_safe_restartpoint},
+	{Hash, hash_redo, NULL, NULL, NULL},
+	{Gin, gin_redo, gin_xlog_startup, gin_xlog_cleanup, gin_safe_restartpoint},
+	{Gist, gist_redo, gist_xlog_startup, gist_xlog_cleanup, NULL},
+	{Sequence, seq_redo, NULL, NULL, NULL},
+	{SPGist, spg_redo, spg_xlog_startup, spg_xlog_cleanup, NULL}
 };
diff --git a/src/backend/access/transam/rmgrdesc.c b/src/backend/access/transam/rmgrdesc.c
new file mode 100644
index 000..20315c4
--- /dev/null
+++ b/src/backend/access/transam/rmgrdesc.c
@@ -0,0 +1,47 @@
+/*
+ * rmgrdesc.c
+ *
+ * Resource managers descriptor function definitions
+ *
+ * src/backend/access/transam/rmgrdesc.c
+ */
+#include postgres.h
+
+#include access/clog.h
+#include access/gin.h
+#include access/gist_private.h
+#include access/hash.h
+#include access/heapam_xlog.h
+#include access/multixact.h
+#include access/nbtree.h
+#include access/spgist.h
+#include access/xact.h
+#include access/xlog_internal.h
+#include catalog/storage_xlog.h
+#include commands/dbcommands.h
+#include commands/sequence.h
+#include commands/tablespace.h
+#include storage/standby.h
+#include utils/relmapper.h
+
+/* See rmgr.c, too */
+
+const RmgrDescData RmgrDescTable[RM_MAX_ID + 1] = {
+	{ xlog_desc },
+	{ xact_desc },
+	{ smgr_desc },

Re: [HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-02-04 Thread Andres Freund
On 2013-02-04 13:22:26 -0300, Alvaro Herrera wrote:
 
 I didn't like this bit too much:
 
  diff --git a/contrib/pg_xlogdump/tables.c b/contrib/pg_xlogdump/tables.c
  new file mode 100644
  index 000..e947e0d
  --- /dev/null
  +++ b/contrib/pg_xlogdump/tables.c
  @@ -0,0 +1,78 @@
 
  +/*
  + * RmgrTable linked only to functions available outside of the backend.
  + *
  + * needs to be synced with src/backend/access/transam/rmgr.c
  + */
  +const RmgrData RmgrTable[RM_MAX_ID + 1] = {
  +   {XLOG, NULL, xlog_desc, NULL, NULL, NULL},
  +   {Transaction, NULL, xact_desc, NULL, NULL, NULL},
 
 So I propose the following patch instead.  This lets pg_xlogdump compile
 only the file it needs, and not concern itself with the rest of rmgr.c.

Hm. Not sure whats the advantage of that, duplicates about as much and
makes it harder to copy  paste between both files.
I am fine with it, I just don't see a clear advantage of either way.

 diff --git a/src/include/access/xlog_internal.h 
 b/src/include/access/xlog_internal.h
 index ce9957e..b751882 100644
 --- a/src/include/access/xlog_internal.h
 +++ b/src/include/access/xlog_internal.h
 @@ -231,15 +231,17 @@ typedef struct xl_end_of_recovery
  struct XLogRecord;
  
  /*
 - * Method table for resource managers.
 + * Method tables for resource managers.
   *
 - * RmgrTable[] is indexed by RmgrId values (see rmgr.h).
 + * RmgrDescData (for textual descriptor functions) is split so that the file 
 it
 + * lives in can be used by frontend programs.
 + *
 + * RmgrTable[] and RmgrDescTable[] are indexed by RmgrId values (see rmgr.h).
   */
  typedef struct RmgrData
  {
   const char *rm_name;
   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);
   bool(*rm_safe_restartpoint) (void);
 @@ -247,6 +249,14 @@ typedef struct RmgrData
  
  extern const RmgrData RmgrTable[];
  
 +typedef struct RmgrDescData
 +{
 + void(*rm_desc) (StringInfo buf, uint8 xl_info, char *rec);
 +} RmgrDescData;
 +
 +extern const RmgrDescData RmgrDescTable[];
 +

I think we would at least need to include rm_name here as well.

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-02-04 Thread Alvaro Herrera
Andres Freund wrote:
 On 2013-02-04 13:22:26 -0300, Alvaro Herrera wrote:

  +typedef struct RmgrDescData
  +{
  +   void(*rm_desc) (StringInfo buf, uint8 xl_info, char *rec);
  +} RmgrDescData;
  +
  +extern const RmgrDescData RmgrDescTable[];
  +
 
 I think we would at least need to include rm_name here as well.

Not rm_name (that would be duplicative), but a comment with the name of
each rmgr's name in its line should be sufficient.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-02-04 Thread Andres Freund
On 2013-02-04 14:55:56 -0300, Alvaro Herrera wrote:
 Andres Freund wrote:
  On 2013-02-04 13:22:26 -0300, Alvaro Herrera wrote:
 
   +typedef struct RmgrDescData
   +{
   + void(*rm_desc) (StringInfo buf, uint8 xl_info, char *rec);
   +} RmgrDescData;
   +
   +extern const RmgrDescData RmgrDescTable[];
   +
  
  I think we would at least need to include rm_name here as well.
 
 Not rm_name (that would be duplicative), but a comment with the name of
 each rmgr's name in its line should be sufficient.

Maybe I am misunderstanding what you want to do, but xlogdump prints the
name of the rmgr and allows to filter by it, how would we do that
without rm_name?

Greetings,

Andres Freund

-- 
 Andres Freund http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-02-04 Thread Alvaro Herrera
Andres Freund wrote:
 On 2013-02-04 14:55:56 -0300, Alvaro Herrera wrote:
  Andres Freund wrote:
   On 2013-02-04 13:22:26 -0300, Alvaro Herrera wrote:
  
+typedef struct RmgrDescData
+{
+   void(*rm_desc) (StringInfo buf, uint8 xl_info, char 
*rec);
+} RmgrDescData;
+
+extern const RmgrDescData RmgrDescTable[];
+
   
   I think we would at least need to include rm_name here as well.
  
  Not rm_name (that would be duplicative), but a comment with the name of
  each rmgr's name in its line should be sufficient.
 
 Maybe I am misunderstanding what you want to do, but xlogdump prints the
 name of the rmgr and allows to filter by it, how would we do that
 without rm_name?

Oh, I thought you wanted it for code documentation purposes only.  Okay,
that makes sense.  (Of course, we'd remove it from RmgrTable).

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training  Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] [PATCH 4/5] Add pg_xlogdump contrib module

2013-01-08 Thread Andres Freund
From: Andres Freund and...@anarazel.de

Authors: Andres Freund, Heikki Linnakangas
---
 contrib/Makefile  |   1 +
 contrib/pg_xlogdump/Makefile  |  37 +++
 contrib/pg_xlogdump/compat.c  |  58 
 contrib/pg_xlogdump/pg_xlogdump.c | 654 ++
 contrib/pg_xlogdump/tables.c  |  78 +
 doc/src/sgml/ref/allfiles.sgml|   1 +
 doc/src/sgml/ref/pg_xlogdump.sgml |  76 +
 doc/src/sgml/reference.sgml   |   1 +
 src/backend/access/transam/rmgr.c |   1 +
 src/backend/catalog/catalog.c |   2 +
 src/tools/msvc/Mkvcbuild.pm   |  16 +-
 11 files changed, 924 insertions(+), 1 deletion(-)
 create mode 100644 contrib/pg_xlogdump/Makefile
 create mode 100644 contrib/pg_xlogdump/compat.c
 create mode 100644 contrib/pg_xlogdump/pg_xlogdump.c
 create mode 100644 contrib/pg_xlogdump/tables.c
 create mode 100644 doc/src/sgml/ref/pg_xlogdump.sgml

diff --git a/contrib/Makefile b/contrib/Makefile
index fcd7c1e..5d290b8 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -39,6 +39,7 @@ SUBDIRS = \
pg_trgm \
pg_upgrade  \
pg_upgrade_support \
+   pg_xlogdump \
pgbench \
pgcrypto\
pgrowlocks  \
diff --git a/contrib/pg_xlogdump/Makefile b/contrib/pg_xlogdump/Makefile
new file mode 100644
index 000..1adef35
--- /dev/null
+++ b/contrib/pg_xlogdump/Makefile
@@ -0,0 +1,37 @@
+# contrib/pg_xlogdump/Makefile
+
+PGFILEDESC = pg_xlogdump
+PGAPPICON=win32
+
+PROGRAM = pg_xlogdump
+OBJS =  pg_xlogdump.o compat.o tables.o xlogreader.o $(RMGRDESCOBJS) \
+   $(WIN32RES)
+
+# XXX: Perhaps this should be done by a wildcard rule so that you don't need
+# to remember to add new rmgrdesc files to this list.
+RMGRDESCSOURCES = clogdesc.c dbasedesc.c gindesc.c gistdesc.c hashdesc.c \
+   heapdesc.c mxactdesc.c nbtdesc.c relmapdesc.c seqdesc.c smgrdesc.c \
+   spgdesc.c standbydesc.c tblspcdesc.c xactdesc.c xlogdesc.c
+
+RMGRDESCOBJS = $(patsubst %.c,%.o,$(RMGRDESCSOURCES))
+
+EXTRA_CLEAN = $(RMGRDESCSOURCES) xlogreader.c
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/pg_xlogdump
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
+
+override CPPFLAGS := -DFRONTEND $(CPPFLAGS)
+
+xlogreader.c: % : $(top_srcdir)/src/backend/access/transam/%
+   rm -f $@  $(LN_S) $ .
+
+$(RMGRDESCSOURCES): % : $(top_srcdir)/src/backend/access/rmgrdesc/%
+   rm -f $@  $(LN_S) $ .
diff --git a/contrib/pg_xlogdump/compat.c b/contrib/pg_xlogdump/compat.c
new file mode 100644
index 000..e150afb
--- /dev/null
+++ b/contrib/pg_xlogdump/compat.c
@@ -0,0 +1,58 @@
+/*-
+ *
+ * compat.c
+ * Reimplementations of various backend functions.
+ *
+ * Portions Copyright (c) 2012, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * contrib/pg_xlogdump/compat.c
+ *
+ * This file contains client-side implementations for various backend
+ * functions that the rm_desc functions in *desc.c files rely on.
+ *
+ *-
+ */
+
+/* ugly hack, same as in e.g pg_controldata */
+#define FRONTEND 1
+#include postgres.h
+
+#include catalog/catalog.h
+#include datatype/timestamp.h
+#include lib/stringinfo.h
+#include storage/relfilenode.h
+#include utils/timestamp.h
+#include utils/datetime.h
+
+const char *
+timestamptz_to_str(TimestampTz dt)
+{
+   return unimplemented-timestamp;
+}
+
+const char *
+relpathbackend(RelFileNode rnode, BackendId backend, ForkNumber forknum)
+{
+   return unimplemented-relpathbackend;
+}
+
+/*
+ * Provide a hacked up compat layer for StringInfos so xlog desc functions can
+ * be linked/called.
+ */
+void
+appendStringInfo(StringInfo str, const char *fmt, ...)
+{
+   va_list args;
+
+   va_start(args, fmt);
+   vprintf(fmt, args);
+   va_end(args);
+}
+
+void
+appendStringInfoString(StringInfo str, const char *string)
+{
+   appendStringInfo(str, %s, string);
+}
diff --git a/contrib/pg_xlogdump/pg_xlogdump.c 
b/contrib/pg_xlogdump/pg_xlogdump.c
new file mode 100644
index 000..29ee73e
--- /dev/null
+++ b/contrib/pg_xlogdump/pg_xlogdump.c
@@ -0,0 +1,654 @@
+/*-
+ *
+ * pg_xlogdump.c - decode and display WAL
+ *
+ * Copyright (c) 2012, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *   contrib/pg_xlogdump/pg_xlogdump.c
+ *-
+ */
+
+/* ugly hack, same as in e.g pg_controldata */
+#define FRONTEND 1
+#include postgres.h
+
+#include unistd.h
+
+#include access/xlog.h
+#include access/xlogreader.h
+#include