On 2013-06-19 15:01:44 -0700, Jeff Janes wrote:
> On Thu, Feb 7, 2013 at 12:01 PM, Andres Freund <and...@2ndquadrant.com>wrote:
> 
> > On 2013-02-07 11:15:46 -0800, Jeff Janes wrote:
> > >
> > > Does anyone have suggestions on how to hack the system to make it
> > > fast-forward the current transaction id? It would certainly make
> > > testing this kind of thing faster if I could make transaction id
> > > increment by 100 each time a new one is generated.  Then wrap-around
> > > could be approached in minutes rather than hours.
> >
> > I had various plpgsql functions to do that, but those still took quite
> > some time. As I needed it before I just spent some minutes hacking up a
> > contrib module to do the job.
> >
> 
> Hi Andres,
> 
> Your patch needs the file "xidfuncs--1.0.sql", but does not include it.
> 
> I could probably guess what needs to be in that file, but do you still have
> a copy of it?

Hm. Sorry. Not sure how that happened. The commit in my local branch for
that seems to have it ;). Attached.

> > I doubt it really think it makes sense as a contrib module on its own
> > though?

> Maybe PGXN?

Hm. As of now I am not yet that convinced of PGXN for C containing
extensions.

Greetings,

Andres Freund

-- 
 Andres Freund                     http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
>From b32cc0dca23f0477b26cb9d733b1d7ef391a77cc Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Wed, 20 Feb 2013 17:20:00 +0100
Subject: [PATCH] add xidfuncs

---
 contrib/Makefile                   |  3 ++-
 contrib/xidfuncs/Makefile          | 18 ++++++++++++++
 contrib/xidfuncs/xidfuncs--1.0.sql |  5 ++++
 contrib/xidfuncs/xidfuncs.c        | 50 ++++++++++++++++++++++++++++++++++++++
 contrib/xidfuncs/xidfuncs.control  |  5 ++++
 5 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 contrib/xidfuncs/Makefile
 create mode 100644 contrib/xidfuncs/xidfuncs--1.0.sql
 create mode 100644 contrib/xidfuncs/xidfuncs.c
 create mode 100644 contrib/xidfuncs/xidfuncs.control

diff --git a/contrib/Makefile b/contrib/Makefile
index fcd7c1e..64d10cc 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -51,7 +51,8 @@ SUBDIRS = \
 		tsearch2	\
 		unaccent	\
 		vacuumlo	\
-		worker_spi
+		worker_spi	\
+		xidfuncs
 
 ifeq ($(with_openssl),yes)
 SUBDIRS += sslinfo
diff --git a/contrib/xidfuncs/Makefile b/contrib/xidfuncs/Makefile
new file mode 100644
index 0000000..6977a3b
--- /dev/null
+++ b/contrib/xidfuncs/Makefile
@@ -0,0 +1,18 @@
+# contrib/xidfuncs/Makefile
+
+MODULE_big	= xidfuncs
+OBJS		= xidfuncs.o
+
+EXTENSION = xidfuncs
+DATA = xidfuncs--1.0.sql
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/xidfuncs
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/contrib/xidfuncs/xidfuncs--1.0.sql b/contrib/xidfuncs/xidfuncs--1.0.sql
new file mode 100644
index 0000000..db7c9ed
--- /dev/null
+++ b/contrib/xidfuncs/xidfuncs--1.0.sql
@@ -0,0 +1,5 @@
+CREATE FUNCTION burnxids(numxids int4)
+    RETURNS int8
+    VOLATILE
+    AS 'MODULE_PATHNAME', 'burnxids'
+    LANGUAGE C;
diff --git a/contrib/xidfuncs/xidfuncs.c b/contrib/xidfuncs/xidfuncs.c
new file mode 100644
index 0000000..d24a48f
--- /dev/null
+++ b/contrib/xidfuncs/xidfuncs.c
@@ -0,0 +1,50 @@
+/*-------------------------------------------------------------------------
+ * contrib/xidfuncs/xidfuncs.c
+ *
+ * Copyright (c) 2013, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *	  contrib/xidfuncs/xidfuncs.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "postgres.h"
+
+#include "access/transam.h"
+#include "access/xact.h"
+#include "funcapi.h"
+#include "storage/proc.h"
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1(burnxids);
+
+extern Datum burnxids(PG_FUNCTION_ARGS);
+
+Datum
+burnxids(PG_FUNCTION_ARGS)
+{
+	int nxids = PG_GETARG_INT32(0);
+	int i;
+	TransactionId last;
+
+	if (nxids <= 1)
+		elog(ERROR, "can't burn a negative amount of xids");
+
+	if (nxids > 1<<30)
+		elog(ERROR, "burning too many xids is dangerous");
+
+	if (GetTopTransactionIdIfAny() != InvalidTransactionId)
+		elog(ERROR, "can't burn xids in a transaction with xid");
+
+	for (i = 0; i < nxids; i++)
+	{
+		last = GetNewTransactionId(false);
+	}
+
+	/* don't keep xid as assigned */
+	MyPgXact->xid = InvalidTransactionId;
+
+	return Int64GetDatum((int64)last);
+}
diff --git a/contrib/xidfuncs/xidfuncs.control b/contrib/xidfuncs/xidfuncs.control
new file mode 100644
index 0000000..bca7194
--- /dev/null
+++ b/contrib/xidfuncs/xidfuncs.control
@@ -0,0 +1,5 @@
+# xidfuncs extension
+comment = 'xid debugging functions'
+default_version = '1.0'
+module_pathname = '$libdir/xidfuncs'
+relocatable = true
-- 
1.8.2.rc2.4.g7799588.dirty

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

Reply via email to