Index: pre_prepare.c
===================================================================
RCS file: /cvsroot/preprepare/preprepare/pre_prepare.c,v
retrieving revision 1.1
diff -p -u -r1.1 pre_prepare.c
--- pre_prepare.c	13 May 2009 20:54:04 -0000	1.1
+++ pre_prepare.c	25 May 2009 13:37:52 -0000
@@ -35,6 +35,7 @@
 
 PG_MODULE_MAGIC;
 
+static bool  pre_prepare_at_init  = NULL;
 static char *pre_prepare_relation = NULL;
 
 void _PG_init(void);
@@ -125,6 +126,15 @@ int pre_prepare_all() {
  */
 void
 _PG_init(void) {
+  DefineCustomBoolVariable("preprepare.at_init",
+			   "Do we prepare the statements at backend init start",
+			   "You have to setup local_preload_libraries too",
+			   &pre_prepare_at_init,
+			   PGC_USERSET,
+			   NULL, 
+			   NULL);
+  EmitWarningsOnPlaceholders("prepare.at_init");
+
   DefineCustomStringVariable("preprepare.relation",
 			     "Table name where to find statements to prepare",
 			     "Can be schema qualified, must have columns \"name\" and \"statement\"",
@@ -132,8 +142,21 @@ _PG_init(void) {
 			     PGC_USERSET,
 			     NULL, 
 			     NULL);
-
   EmitWarningsOnPlaceholders("prepare.relation");
+
+  if( pre_prepare_at_init ) {
+    int err;
+
+    err = SPI_connect();
+    if (err != SPI_OK_CONNECT)
+      elog(ERROR, "SPI_connect: %s", SPI_result_code_string(err));
+
+    pre_prepare_all();
+
+    err = SPI_finish();
+    if (err != SPI_OK_FINISH)
+      elog(ERROR, "SPI_finish: %s", SPI_result_code_string(err));
+  }
 }
 
 /*
