diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 6ff76b9d9559fa8a2064dcf228289305dd12ecf8..0a82ecdb32558b2c1b8a2087d88b1d1805b32987 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.251 2008/03/08 21:57:59 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.252 2008/03/26 16:20:46 alvherre Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -56,6 +56,7 @@
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index e4da00e868a03c34c7d5fc418ca24d11bff6d048..f1a7d8d360e81ee3cc4e778a356e5b35146fef4b 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.101 2008/01/01 19:45:46 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.102 2008/03/26 16:20:46 alvherre Exp $
  *
  * INTERFACE ROUTINES
  *		index_open		- open an index relation by relation OID
@@ -67,6 +67,7 @@
 #include "access/transam.h"
 #include "pgstat.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 
 
 /* ----------------------------------------------------------------
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 2e1543c0b0cf2250de3cb7f1d693bc24fa29525f..4dd23b0b9b6c3bd86c11f5389660c24b0477ff64 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.106 2008/01/01 19:45:46 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.107 2008/03/26 16:20:46 alvherre Exp $
  *
  *	NOTES
  *	   Postgres btree pages look like ordinary relation pages.	The opaque
@@ -28,6 +28,7 @@
 #include "storage/freespace.h"
 #include "storage/lmgr.h"
 #include "utils/inval.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c
index a6c1c59059587fcdea8fa8f4a6d7c708147e6f28..9dfbbea831221e89ba76adac0712a1e6440770fd 100644
--- a/src/backend/access/transam/subtrans.c
+++ b/src/backend/access/transam/subtrans.c
@@ -22,7 +22,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.20 2008/01/01 19:45:48 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.21 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,7 +31,7 @@
 #include "access/slru.h"
 #include "access/subtrans.h"
 #include "access/transam.h"
-#include "utils/tqual.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c
index 4c0cb4baf691d0ce26fdb5e224ed461fd8200dc1..bae67d0c4c259dda8712653ee03cf61c05774db3 100644
--- a/src/backend/access/transam/transam.c
+++ b/src/backend/access/transam/transam.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.74 2008/03/11 20:20:35 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.75 2008/03/26 16:20:46 alvherre Exp $
  *
  * NOTES
  *	  This file contains the high level access-method interface to the
@@ -22,7 +22,7 @@
 #include "access/clog.h"
 #include "access/subtrans.h"
 #include "access/transam.h"
-#include "utils/tqual.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 9af53a5953f09e2b2726fc7efa8ad4fcc1f2b9ab..e288f31b1e34854c860415e015df09407f064938 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.260 2008/03/17 19:44:41 petere Exp $
+ *	  $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.261 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -45,6 +45,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/xml.h"
 #include "pg_trace.h"
 
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index 872135affebb774fb8555cf6583aac55bed24384..b23c8b36ab361fd6b5617d353b8430af2d310d48 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.73 2008/02/20 17:44:09 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/catalog/catalog.c,v 1.74 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -38,6 +38,7 @@
 #include "storage/fd.h"
 #include "utils/fmgroids.h"
 #include "utils/relcache.h"
+#include "utils/tqual.h"
 
 
 #define OIDCHARS	10			/* max chars printed by %u */
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 974eec8a06a41570358f7830ba0aeb480dd63f24..8f3f74d179a883d82b5a30a0544dc2b7291edf0e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.328 2008/03/25 22:42:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.329 2008/03/26 16:20:46 alvherre Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -60,6 +60,7 @@
 #include "utils/lsyscache.h"
 #include "utils/relcache.h"
 #include "utils/syscache.h"
+#include "utils/snapmgmt.h"
 
 
 static void AddNewRelationTuple(Relation pg_class_desc,
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 4188eec289c9d6ad323dd18bf96c84e33f40c5ea..2f06e792c22ab098a1fb9d8d2855b684b862c646 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.293 2008/03/25 22:42:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.294 2008/03/26 16:20:46 alvherre Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -55,6 +55,7 @@
 #include "utils/relcache.h"
 #include "utils/syscache.h"
 #include "utils/tuplesort.h"
+#include "utils/snapmgmt.h"
 
 
 /* state info for validate_index bulkdelete callback */
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 7a9ad8d19a82de2654dfe95c4264456cadd9c58a..8c1da700e78dd3fce8e5a79a88b15071032d2a62 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.169 2008/01/30 19:46:48 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.170 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,6 +41,7 @@
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 194f3b380a1e0ef05db8af1a5528f059c03bab0f..35caed782a7f60f9c3b0d88734a773a0847689c6 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.296 2008/03/08 01:16:26 adunstan Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.297 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,6 +40,7 @@
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index a2bd018127f4804ed65a62e028327ebc21ac1834..425e90935ef2bf2368889bc59c68c2b48bc9b2b8 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.169 2008/01/01 19:45:49 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.170 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,7 @@
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
 #include "utils/tuplesort.h"
+#include "utils/snapmgmt.h"
 
 
 /* Hook for plugins to get control in ExplainOneQuery() */
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index fe4a1ef1b05c26bd97abe92767381f25acde22d5..82f6fab64dc962bd4db8dab293ddb027b18fbc4f 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.171 2008/02/07 17:09:51 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.172 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,6 +47,7 @@
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index c876f76d92022c9917e296c23ec02d34594af061..af11569b2edb338c8469cd551d636678de1d4d7a 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -14,7 +14,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.70 2008/03/20 20:05:56 alvherre Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.71 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,6 +28,7 @@
 #include "executor/executor.h"
 #include "tcop/pquery.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index e9a0aaf050d6352ffa8ad2838fbc8bf151947873..3ea0c7f272946ee45ae79927525b2146b69e9a13 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -10,7 +10,7 @@
  * Copyright (c) 2002-2008, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.82 2008/03/25 22:42:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.83 2008/03/26 16:20:46 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -32,6 +32,7 @@
 #include "tcop/utility.h"
 #include "utils/builtins.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a11a6844cbd1a430fb0edc434bbda932b7b68368..45c502e4c0e682fb8c2290bc62b2c1f7b443235c 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.244 2008/03/25 22:42:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.245 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -65,6 +65,7 @@
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 5bca2233279bfb6c26e5e5686d70c06e170cd628..18bb9148ff4933eb9f0129c0480377f8c580de40 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.227 2008/01/02 23:34:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.228 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -38,6 +38,7 @@
 #include "utils/inval.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index bc36ef3fed4a6d2cd99eca32f5c34e3508942abc..8b68ef6f307f606f8f990313cf5cf84b045533ae 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.368 2008/03/19 14:18:21 alvherre Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.369 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -48,6 +48,7 @@
 #include "utils/memutils.h"
 #include "utils/pg_rusage.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 #include "pgstat.h"
 
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 2c234071d2119e679e51e1606fc54d93b996bb3b..f8bec2920d473956334f321626c36955041aa882 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.125 2008/01/03 21:23:15 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.126 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -25,7 +25,7 @@
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/syscache.h"
-#include "utils/tqual.h"
+#include "utils/snapmgmt.h"
 #include "mb/pg_wchar.h"
 
 /*
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index 678b43927d7b6d50625b96344d86fca04b8465d0..7b58792139acc73e13d7f2df65ee68a53ce5e5aa 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.122 2008/03/25 22:42:43 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.123 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,6 +28,7 @@
 #include "utils/builtins.h"
 #include "utils/datum.h"
 #include "utils/lsyscache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 #include "utils/typcache.h"
 
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index e53982d6a9854ff34c880d0539da4a077d8ab7e8..c678e2da64ab8bac0470e2c1488d1437422e4413 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.22 2008/01/01 19:45:49 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.23 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,6 +40,7 @@
 #include "executor/nodeBitmapHeapscan.h"
 #include "pgstat.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index b73579181640b57363cb117d51a307108f6ec5c0..200cb7698954167c124b5678bd665f4e4f07b96e 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.189 2008/03/20 20:05:56 alvherre Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.190 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,6 +20,7 @@
 #include "executor/spi_priv.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 #include "utils/typcache.h"
 
 
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index a56dccd2ff5d9482736cd06e5c9769662948c9ba..d5acf40164d514a4ea2787642383d3ade1eb3f25 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.141 2008/03/15 20:46:31 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.142 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -33,6 +33,7 @@
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/relcache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 #include "catalog/catalog.h"
 #include "miscadmin.h"
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index d7ba39bc5d4dd595030a914fdf564b7b816d9385..686a15513d097e83bfd8202f1514d622a46ee58d 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -23,7 +23,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.41 2008/03/11 20:20:35 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.42 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -37,7 +37,7 @@
 #include "access/twophase.h"
 #include "miscadmin.h"
 #include "storage/procarray.h"
-#include "utils/tqual.h"
+#include "utils/snapmgmt.h"
 
 
 /* Our shared memory area */
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index 95ed68d1baeec88b994c7a7d5cb8484ef5cd47c6..df67985c56e3954704e3365a3630af41114eaa04 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -24,7 +24,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.128 2008/03/01 19:26:22 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.129 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,6 +42,7 @@
 #include "storage/large_object.h"
 #include "utils/fmgroids.h"
 #include "utils/resowner.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c
index 651cf1e4f20100042b7acb4e7008b8fb79cdf3f4..d459aa5a482765a718f7d801fb53feee24e118f7 100644
--- a/src/backend/tcop/fastpath.c
+++ b/src/backend/tcop/fastpath.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.97 2008/01/01 19:45:52 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.98 2008/03/26 16:20:47 alvherre Exp $
  *
  * NOTES
  *	  This cruft is the server side of PQfn.
@@ -30,6 +30,7 @@
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
 #include "utils/lsyscache.h"
+#include "utils/snapmgmt.h"
 #include "utils/syscache.h"
 
 
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 19e7c0b070c0a003068e4798ce7f321fc5ec3a6b..c3eab72bf8142fd34e9452eeee7d1f85acadabea 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.545 2008/03/12 23:58:27 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.546 2008/03/26 16:20:47 alvherre Exp $
  *
  * NOTES
  *	  this is the "main" module of the postgres backend and
@@ -66,6 +66,7 @@
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/ps_status.h"
+#include "utils/snapmgmt.h"
 #include "mb/pg_wchar.h"
 
 #include "pgstat.h"
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 0e980385b2efa08468912da1b2034832b6f2018f..f9dc2a72d0395846c09fd72df22de2c9cbb5849b 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.120 2008/01/01 19:45:52 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.121 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,6 +23,7 @@
 #include "tcop/tcopprot.h"
 #include "tcop/utility.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 /*
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index 65f541057ba9b9d38649acebdcf8d6a79343589e..d9bdf121cc059a17d9880c8ec600e70e5af05d0a 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -15,7 +15,7 @@
  *
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.104 2008/02/18 23:00:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.105 2008/03/26 16:20:47 alvherre Exp $
  *
  * ----------
  */
@@ -41,6 +41,7 @@
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 
 
 /* ----------
diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c
index be79d186a1e16423d6a29f33b258f514c110c86c..3d4f131cc81208d49c358d11868fa26d23034371 100644
--- a/src/backend/utils/adt/txid.c
+++ b/src/backend/utils/adt/txid.c
@@ -14,7 +14,7 @@
  *	Author: Jan Wieck, Afilias USA INC.
  *	64-bit txids: Marko Kreen, Skype Technologies
  *
- *	$PostgreSQL: pgsql/src/backend/utils/adt/txid.c,v 1.4 2008/01/01 19:45:53 momjian Exp $
+ *	$PostgreSQL: pgsql/src/backend/utils/adt/txid.c,v 1.5 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -26,6 +26,7 @@
 #include "funcapi.h"
 #include "libpq/pqformat.h"
 #include "utils/builtins.h"
+#include "utils/snapmgmt.h"
 
 
 #ifndef INT64_IS_BUSTED
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index b66c112926ec0c2473779356888f14959f5bc752..d3c94a2b9f9d15602c0bd152e29b8106d17c8889 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -33,7 +33,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.15 2008/01/01 19:45:53 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.16 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -51,6 +51,7 @@
 #include "utils/inval.h"
 #include "utils/memutils.h"
 #include "utils/resowner.h"
+#include "utils/snapmgmt.h"
 
 
 typedef struct
diff --git a/src/backend/utils/time/Makefile b/src/backend/utils/time/Makefile
index 5e886d425e017e7fcf3e2c8b9694a0dcd5ea1fda..68b13e4c390364941a899300292c04e6e8df3a83 100644
--- a/src/backend/utils/time/Makefile
+++ b/src/backend/utils/time/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for utils/time
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/backend/utils/time/Makefile,v 1.13 2008/02/19 10:30:09 petere Exp $
+#    $PostgreSQL: pgsql/src/backend/utils/time/Makefile,v 1.14 2008/03/26 16:20:47 alvherre Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -12,6 +12,6 @@ subdir = src/backend/utils/time
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-OBJS = combocid.o tqual.o
+OBJS = combocid.o tqual.o snapmgmt.o
 
 include $(top_srcdir)/src/backend/common.mk
diff --git a/src/backend/utils/time/snapmgmt.c b/src/backend/utils/time/snapmgmt.c
new file mode 100644
index 0000000000000000000000000000000000000000..b406b4bc69e3d2ac5573290eb7ac00c9021fcb63
--- /dev/null
+++ b/src/backend/utils/time/snapmgmt.c
@@ -0,0 +1,172 @@
+/*-------------------------------------------------------------------------
+ * snapmgmt.c
+ *		PostgreSQL snapshot management code.
+ *
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * IDENTIFICATION
+ *	  $PostgreSQL: pgsql/src/backend/utils/time/snapmgmt.c,v 1.1 2008/03/26 16:20:47 alvherre Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "access/xact.h"
+#include "access/transam.h"
+#include "storage/procarray.h"
+#include "utils/snapmgmt.h"
+#include "utils/tqual.h"
+
+
+/*
+ * These SnapshotData structs are static to simplify memory allocation
+ * (see the hack in GetSnapshotData to avoid repeated malloc/free).
+ */
+static SnapshotData SerializableSnapshotData = {HeapTupleSatisfiesMVCC};
+static SnapshotData LatestSnapshotData = {HeapTupleSatisfiesMVCC};
+
+/* Externally visible pointers to valid snapshots: */
+Snapshot	SerializableSnapshot = NULL;
+Snapshot	LatestSnapshot = NULL;
+
+/*
+ * This pointer is not maintained by this module, but it's convenient
+ * to declare it here anyway.  Callers typically assign a copy of
+ * GetTransactionSnapshot's result to ActiveSnapshot.
+ */
+Snapshot	ActiveSnapshot = NULL;
+
+/*
+ * These are updated by GetSnapshotData.  We initialize them this way
+ * for the convenience of TransactionIdIsInProgress: even in bootstrap
+ * mode, we don't want it to say that BootstrapTransactionId is in progress.
+ */
+TransactionId TransactionXmin = FirstNormalTransactionId;
+TransactionId RecentXmin = FirstNormalTransactionId;
+TransactionId RecentGlobalXmin = FirstNormalTransactionId;
+
+
+/*
+ * GetTransactionSnapshot
+ *		Get the appropriate snapshot for a new query in a transaction.
+ *
+ * The SerializableSnapshot is the first one taken in a transaction.
+ * In serializable mode we just use that one throughout the transaction.
+ * In read-committed mode, we take a new snapshot each time we are called.
+ *
+ * Note that the return value points at static storage that will be modified
+ * by future calls and by CommandCounterIncrement().  Callers should copy
+ * the result with CopySnapshot() if it is to be used very long.
+ */
+Snapshot
+GetTransactionSnapshot(void)
+{
+	/* First call in transaction? */
+	if (SerializableSnapshot == NULL)
+	{
+		SerializableSnapshot = GetSnapshotData(&SerializableSnapshotData, true);
+		return SerializableSnapshot;
+	}
+
+	if (IsXactIsoLevelSerializable)
+		return SerializableSnapshot;
+
+	LatestSnapshot = GetSnapshotData(&LatestSnapshotData, false);
+
+	return LatestSnapshot;
+}
+
+/*
+ * GetLatestSnapshot
+ *		Get a snapshot that is up-to-date as of the current instant,
+ *		even if we are executing in SERIALIZABLE mode.
+ */
+Snapshot
+GetLatestSnapshot(void)
+{
+	/* Should not be first call in transaction */
+	if (SerializableSnapshot == NULL)
+		elog(ERROR, "no snapshot has been set");
+
+	LatestSnapshot = GetSnapshotData(&LatestSnapshotData, false);
+
+	return LatestSnapshot;
+}
+
+/*
+ * CopySnapshot
+ *		Copy the given snapshot.
+ *
+ * The copy is palloc'd in the current memory context.
+ */
+Snapshot
+CopySnapshot(Snapshot snapshot)
+{
+	Snapshot	newsnap;
+	Size		subxipoff;
+	Size		size;
+
+	/* We allocate any XID arrays needed in the same palloc block. */
+	size = subxipoff = sizeof(SnapshotData) +
+		snapshot->xcnt * sizeof(TransactionId);
+	if (snapshot->subxcnt > 0)
+		size += snapshot->subxcnt * sizeof(TransactionId);
+
+	newsnap = (Snapshot) palloc(size);
+	memcpy(newsnap, snapshot, sizeof(SnapshotData));
+
+	/* setup XID array */
+	if (snapshot->xcnt > 0)
+	{
+		newsnap->xip = (TransactionId *) (newsnap + 1);
+		memcpy(newsnap->xip, snapshot->xip,
+			   snapshot->xcnt * sizeof(TransactionId));
+	}
+	else
+		newsnap->xip = NULL;
+
+	/* setup subXID array */
+	if (snapshot->subxcnt > 0)
+	{
+		newsnap->subxip = (TransactionId *) ((char *) newsnap + subxipoff);
+		memcpy(newsnap->subxip, snapshot->subxip,
+			   snapshot->subxcnt * sizeof(TransactionId));
+	}
+	else
+		newsnap->subxip = NULL;
+
+	return newsnap;
+}
+
+/*
+ * FreeSnapshot
+ *		Free a snapshot previously copied with CopySnapshot.
+ *
+ * This is currently identical to pfree, but is provided for cleanliness.
+ *
+ * Do *not* apply this to the results of GetTransactionSnapshot or
+ * GetLatestSnapshot, since those are just static structs.
+ */
+void
+FreeSnapshot(Snapshot snapshot)
+{
+	pfree(snapshot);
+}
+
+/*
+ * FreeXactSnapshot
+ *		Free snapshot(s) at end of transaction.
+ */
+void
+FreeXactSnapshot(void)
+{
+	/*
+	 * We do not free the xip arrays for the static snapshot structs; they
+	 * will be reused soon. So this is now just a state change to prevent
+	 * outside callers from accessing the snapshots.
+	 */
+	SerializableSnapshot = NULL;
+	LatestSnapshot = NULL;
+	ActiveSnapshot = NULL;		/* just for cleanliness */
+}
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index 6fbc935a6bc2d05ed6ca318022b2119db4eabf0b..b6737d406963611aae70e01c2409050dea9da51c 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -31,7 +31,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.109 2008/01/01 19:45:55 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.110 2008/03/26 16:20:47 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,33 +53,6 @@ SnapshotData SnapshotSelfData = {HeapTupleSatisfiesSelf};
 SnapshotData SnapshotAnyData = {HeapTupleSatisfiesAny};
 SnapshotData SnapshotToastData = {HeapTupleSatisfiesToast};
 
-/*
- * These SnapshotData structs are static to simplify memory allocation
- * (see the hack in GetSnapshotData to avoid repeated malloc/free).
- */
-static SnapshotData SerializableSnapshotData = {HeapTupleSatisfiesMVCC};
-static SnapshotData LatestSnapshotData = {HeapTupleSatisfiesMVCC};
-
-/* Externally visible pointers to valid snapshots: */
-Snapshot	SerializableSnapshot = NULL;
-Snapshot	LatestSnapshot = NULL;
-
-/*
- * This pointer is not maintained by this module, but it's convenient
- * to declare it here anyway.  Callers typically assign a copy of
- * GetTransactionSnapshot's result to ActiveSnapshot.
- */
-Snapshot	ActiveSnapshot = NULL;
-
-/*
- * These are updated by GetSnapshotData.  We initialize them this way
- * for the convenience of TransactionIdIsInProgress: even in bootstrap
- * mode, we don't want it to say that BootstrapTransactionId is in progress.
- */
-TransactionId TransactionXmin = FirstNormalTransactionId;
-TransactionId RecentXmin = FirstNormalTransactionId;
-TransactionId RecentGlobalXmin = FirstNormalTransactionId;
-
 /* local functions */
 static bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
 
@@ -1235,130 +1208,6 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin,
 }
 
 
-/*
- * GetTransactionSnapshot
- *		Get the appropriate snapshot for a new query in a transaction.
- *
- * The SerializableSnapshot is the first one taken in a transaction.
- * In serializable mode we just use that one throughout the transaction.
- * In read-committed mode, we take a new snapshot each time we are called.
- *
- * Note that the return value points at static storage that will be modified
- * by future calls and by CommandCounterIncrement().  Callers should copy
- * the result with CopySnapshot() if it is to be used very long.
- */
-Snapshot
-GetTransactionSnapshot(void)
-{
-	/* First call in transaction? */
-	if (SerializableSnapshot == NULL)
-	{
-		SerializableSnapshot = GetSnapshotData(&SerializableSnapshotData, true);
-		return SerializableSnapshot;
-	}
-
-	if (IsXactIsoLevelSerializable)
-		return SerializableSnapshot;
-
-	LatestSnapshot = GetSnapshotData(&LatestSnapshotData, false);
-
-	return LatestSnapshot;
-}
-
-/*
- * GetLatestSnapshot
- *		Get a snapshot that is up-to-date as of the current instant,
- *		even if we are executing in SERIALIZABLE mode.
- */
-Snapshot
-GetLatestSnapshot(void)
-{
-	/* Should not be first call in transaction */
-	if (SerializableSnapshot == NULL)
-		elog(ERROR, "no snapshot has been set");
-
-	LatestSnapshot = GetSnapshotData(&LatestSnapshotData, false);
-
-	return LatestSnapshot;
-}
-
-/*
- * CopySnapshot
- *		Copy the given snapshot.
- *
- * The copy is palloc'd in the current memory context.
- */
-Snapshot
-CopySnapshot(Snapshot snapshot)
-{
-	Snapshot	newsnap;
-	Size		subxipoff;
-	Size		size;
-
-	/* We allocate any XID arrays needed in the same palloc block. */
-	size = subxipoff = sizeof(SnapshotData) +
-		snapshot->xcnt * sizeof(TransactionId);
-	if (snapshot->subxcnt > 0)
-		size += snapshot->subxcnt * sizeof(TransactionId);
-
-	newsnap = (Snapshot) palloc(size);
-	memcpy(newsnap, snapshot, sizeof(SnapshotData));
-
-	/* setup XID array */
-	if (snapshot->xcnt > 0)
-	{
-		newsnap->xip = (TransactionId *) (newsnap + 1);
-		memcpy(newsnap->xip, snapshot->xip,
-			   snapshot->xcnt * sizeof(TransactionId));
-	}
-	else
-		newsnap->xip = NULL;
-
-	/* setup subXID array */
-	if (snapshot->subxcnt > 0)
-	{
-		newsnap->subxip = (TransactionId *) ((char *) newsnap + subxipoff);
-		memcpy(newsnap->subxip, snapshot->subxip,
-			   snapshot->subxcnt * sizeof(TransactionId));
-	}
-	else
-		newsnap->subxip = NULL;
-
-	return newsnap;
-}
-
-/*
- * FreeSnapshot
- *		Free a snapshot previously copied with CopySnapshot.
- *
- * This is currently identical to pfree, but is provided for cleanliness.
- *
- * Do *not* apply this to the results of GetTransactionSnapshot or
- * GetLatestSnapshot, since those are just static structs.
- */
-void
-FreeSnapshot(Snapshot snapshot)
-{
-	pfree(snapshot);
-}
-
-/*
- * FreeXactSnapshot
- *		Free snapshot(s) at end of transaction.
- */
-void
-FreeXactSnapshot(void)
-{
-	/*
-	 * We do not free the xip arrays for the static snapshot structs; they
-	 * will be reused soon. So this is now just a state change to prevent
-	 * outside callers from accessing the snapshots.
-	 */
-	SerializableSnapshot = NULL;
-	LatestSnapshot = NULL;
-	ActiveSnapshot = NULL;		/* just for cleanliness */
-}
-
 /*
  * XidInMVCCSnapshot
  *		Is the given XID still-in-progress according to the snapshot?
diff --git a/src/include/access/relscan.h b/src/include/access/relscan.h
index 62a0276fd06f6b1176e5d398d8ad82432b5d643c..eebcc86bb30412f0649178d4b1fc760ccbb8ec46 100644
--- a/src/include/access/relscan.h
+++ b/src/include/access/relscan.h
@@ -7,16 +7,17 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.60 2008/01/14 01:39:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/relscan.h,v 1.61 2008/03/26 16:20:48 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef RELSCAN_H
 #define RELSCAN_H
 
+#include "access/htup.h"
 #include "access/skey.h"
 #include "storage/bufpage.h"
-#include "utils/tqual.h"
+#include "utils/snapshot.h"
 
 
 typedef struct HeapScanDescData
diff --git a/src/include/storage/large_object.h b/src/include/storage/large_object.h
index 5d538e35457a3113e239cd02d4f7efd2123b0ed5..1430e7d63cc8565ecdb19bd8ca6b9311ca088aa9 100644
--- a/src/include/storage/large_object.h
+++ b/src/include/storage/large_object.h
@@ -8,14 +8,14 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/storage/large_object.h,v 1.39 2008/01/01 19:45:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/large_object.h,v 1.40 2008/03/26 16:20:48 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef LARGE_OBJECT_H
 #define LARGE_OBJECT_H
 
-#include "utils/tqual.h"
+#include "utils/snapshot.h"
 
 
 /*----------
diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h
index 26b27fa941806568c35e06ed5831047e8fd9df71..160b6c9670e4f097e6c0b64959d45328c7b5bf5d 100644
--- a/src/include/storage/procarray.h
+++ b/src/include/storage/procarray.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.20 2008/01/09 21:52:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.21 2008/03/26 16:20:48 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,6 +15,7 @@
 #define PROCARRAY_H
 
 #include "storage/lock.h"
+#include "utils/snapshot.h"
 
 
 extern Size ProcArrayShmemSize(void);
@@ -25,6 +26,8 @@ extern void ProcArrayRemove(PGPROC *proc, TransactionId latestXid);
 extern void ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid);
 extern void ProcArrayClearTransaction(PGPROC *proc);
 
+extern Snapshot GetSnapshotData(Snapshot snapshot, bool serializable);
+
 extern bool TransactionIdIsInProgress(TransactionId xid);
 extern bool TransactionIdIsActive(TransactionId xid);
 extern TransactionId GetOldestXmin(bool allDbs, bool ignoreVacuum);
diff --git a/src/include/utils/snapmgmt.h b/src/include/utils/snapmgmt.h
new file mode 100644
index 0000000000000000000000000000000000000000..349523ea2e14379720473878b287e10a5fb7c6f3
--- /dev/null
+++ b/src/include/utils/snapmgmt.h
@@ -0,0 +1,33 @@
+/*-------------------------------------------------------------------------
+ *
+ * snapmgmt.h
+ *	  POSTGRES snapshot management definitions
+ *
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/utils/snapmgmt.h,v 1.1 2008/03/26 16:20:48 alvherre Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef SNAPMGMT_H
+#define SNAPMGMT_H
+
+#include "utils/snapshot.h"
+
+
+extern PGDLLIMPORT Snapshot SerializableSnapshot;
+extern PGDLLIMPORT Snapshot LatestSnapshot;
+extern PGDLLIMPORT Snapshot ActiveSnapshot;
+
+extern TransactionId TransactionXmin;
+extern TransactionId RecentXmin;
+extern TransactionId RecentGlobalXmin;
+
+extern Snapshot GetTransactionSnapshot(void);
+extern Snapshot GetLatestSnapshot(void);
+extern Snapshot CopySnapshot(Snapshot snapshot);
+extern void FreeSnapshot(Snapshot snapshot);
+extern void FreeXactSnapshot(void);
+
+#endif /* SNAPMGMT_H */
diff --git a/src/include/utils/snapshot.h b/src/include/utils/snapshot.h
new file mode 100644
index 0000000000000000000000000000000000000000..7dca978ee98cbf2c72061ac19f314fc242dc619f
--- /dev/null
+++ b/src/include/utils/snapshot.h
@@ -0,0 +1,62 @@
+/*-------------------------------------------------------------------------
+ *
+ * snapshot.h
+ *	  POSTGRES snapshot definition
+ *
+ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/utils/snapshot.h,v 1.1 2008/03/26 16:20:48 alvherre Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef SNAPSHOT_H
+#define SNAPSHOT_H
+
+#include "access/htup.h"
+#include "storage/buf.h"
+
+
+typedef struct SnapshotData *Snapshot;
+
+#define InvalidSnapshot		((Snapshot) NULL)
+
+/*
+ * We use SnapshotData structures to represent both "regular" (MVCC)
+ * snapshots and "special" snapshots that have non-MVCC semantics.
+ * The specific semantics of a snapshot are encoded by the "satisfies"
+ * function.
+ */
+typedef bool (*SnapshotSatisfiesFunc) (HeapTupleHeader tuple,
+									   Snapshot snapshot, Buffer buffer);
+
+typedef struct SnapshotData
+{
+	SnapshotSatisfiesFunc satisfies;	/* tuple test function */
+
+	/*
+	 * The remaining fields are used only for MVCC snapshots, and are normally
+	 * just zeroes in special snapshots.  (But xmin and xmax are used
+	 * specially by HeapTupleSatisfiesDirty.)
+	 *
+	 * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see
+	 * the effects of all older XIDs except those listed in the snapshot. xmin
+	 * is stored as an optimization to avoid needing to search the XID arrays
+	 * for most tuples.
+	 */
+	TransactionId xmin;			/* all XID < xmin are visible to me */
+	TransactionId xmax;			/* all XID >= xmax are invisible to me */
+	uint32		xcnt;			/* # of xact ids in xip[] */
+	TransactionId *xip;			/* array of xact IDs in progress */
+	/* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
+	int32		subxcnt;		/* # of xact ids in subxip[], -1 if overflow */
+	TransactionId *subxip;		/* array of subxact IDs in progress */
+
+	/*
+	 * note: all ids in subxip[] are >= xmin, but we don't bother filtering
+	 * out any that are >= xmax
+	 */
+	CommandId	curcid;			/* in my xact, CID < curcid are visible */
+} SnapshotData;
+
+#endif /* SNAPSHOT_H */
diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h
index a0399bd3318036e59e7844e175c40f320b4461b5..c9e078369f34f674679ea9bde07f2e4b93b5e876 100644
--- a/src/include/utils/tqual.h
+++ b/src/include/utils/tqual.h
@@ -8,59 +8,16 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.71 2008/01/01 19:45:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.72 2008/03/26 16:20:48 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef TQUAL_H
 #define TQUAL_H
 
-#include "access/htup.h"
-#include "storage/buf.h"
+#include "utils/snapshot.h"
 
 
-/*
- * We use SnapshotData structures to represent both "regular" (MVCC)
- * snapshots and "special" snapshots that have non-MVCC semantics.
- * The specific semantics of a snapshot are encoded by the "satisfies"
- * function.
- */
-typedef struct SnapshotData *Snapshot;
-
-typedef bool (*SnapshotSatisfiesFunc) (HeapTupleHeader tuple,
-										   Snapshot snapshot, Buffer buffer);
-
-typedef struct SnapshotData
-{
-	SnapshotSatisfiesFunc satisfies;	/* tuple test function */
-
-	/*
-	 * The remaining fields are used only for MVCC snapshots, and are normally
-	 * just zeroes in special snapshots.  (But xmin and xmax are used
-	 * specially by HeapTupleSatisfiesDirty.)
-	 *
-	 * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see
-	 * the effects of all older XIDs except those listed in the snapshot. xmin
-	 * is stored as an optimization to avoid needing to search the XID arrays
-	 * for most tuples.
-	 */
-	TransactionId xmin;			/* all XID < xmin are visible to me */
-	TransactionId xmax;			/* all XID >= xmax are invisible to me */
-	uint32		xcnt;			/* # of xact ids in xip[] */
-	TransactionId *xip;			/* array of xact IDs in progress */
-	/* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */
-	int32		subxcnt;		/* # of xact ids in subxip[], -1 if overflow */
-	TransactionId *subxip;		/* array of subxact IDs in progress */
-
-	/*
-	 * note: all ids in subxip[] are >= xmin, but we don't bother filtering
-	 * out any that are >= xmax
-	 */
-	CommandId	curcid;			/* in my xact, CID < curcid are visible */
-} SnapshotData;
-
-#define InvalidSnapshot		((Snapshot) NULL)
-
 /* Static variables representing various special snapshot semantics */
 extern PGDLLIMPORT SnapshotData SnapshotNowData;
 extern PGDLLIMPORT SnapshotData SnapshotSelfData;
@@ -84,15 +41,6 @@ extern PGDLLIMPORT SnapshotData SnapshotToastData;
 #define IsMVCCSnapshot(snapshot)  \
 	((snapshot)->satisfies == HeapTupleSatisfiesMVCC)
 
-
-extern PGDLLIMPORT Snapshot SerializableSnapshot;
-extern PGDLLIMPORT Snapshot LatestSnapshot;
-extern PGDLLIMPORT Snapshot ActiveSnapshot;
-
-extern TransactionId TransactionXmin;
-extern TransactionId RecentXmin;
-extern TransactionId RecentGlobalXmin;
-
 /*
  * HeapTupleSatisfiesVisibility
  *		True iff heap tuple satisfies a time qual.
@@ -149,13 +97,4 @@ extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTupleHeader tuple,
 extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
 					 uint16 infomask, TransactionId xid);
 
-extern Snapshot GetTransactionSnapshot(void);
-extern Snapshot GetLatestSnapshot(void);
-extern Snapshot CopySnapshot(Snapshot snapshot);
-extern void FreeSnapshot(Snapshot snapshot);
-extern void FreeXactSnapshot(void);
-
-/* in procarray.c; declared here to avoid including tqual.h in procarray.h: */
-extern Snapshot GetSnapshotData(Snapshot snapshot, bool serializable);
-
 #endif   /* TQUAL_H */
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 635a992820f87c8f4f7671e113a4035e225cde90..88df20ec60230398bcea1ffc696ba7f09e34eb67 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.204 2008/03/25 22:42:45 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.205 2008/03/26 16:20:48 alvherre Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -32,6 +32,7 @@
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
+#include "utils/snapmgmt.h"
 #include "utils/typcache.h"