diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index edd6ffe..c1b0f8a 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3376,8 +3376,13 @@ PostgresMain(int argc, char *argv[], const char *username)
 	/*
 	 * process any libraries that should be preloaded at backend start (this
 	 * likewise can't be done until GUC settings are complete)
+	 *
+	 * ensure that we run the library's _PG_init() function from within
+	 * a transaction, so that it's able to use SPI
 	 */
+	start_xact_command();
 	process_local_preload_libraries();
+	finish_xact_command();
 
 	/*
 	 * Send this backend's cancellation info to the frontend.
