1616#include "access/xact.h"
1717#include "catalog/pg_type.h"
1818#include "parser/scansup.h"
19+ #include "storage/proc.h"
1920#include "utils/builtins.h"
2021#include "utils/datum.h"
2122#include "utils/lsyscache.h"
@@ -2467,38 +2468,63 @@ processChanges(Action action)
24672468static void
24682469compatibility_check (void )
24692470{
2471+ /*
2472+ * | Edition | ConnPool | ATX | COMPAT_CHECK |
2473+ * -------------------------------------------
2474+ * | std 9.6 | no | no | no |
2475+ * | std 10 | no | no | yes |
2476+ * | std 11 | no | no | yes |
2477+ * | std 12 | no | no | yes |
2478+ * | std 13 | no | no | yes |
2479+ * | ee 9.6 | no | yes | no |
2480+ * | ee 10 | no | yes | yes |
2481+ * | ee 11 | yes | yes | yes |
2482+ * | ee 12 | yes | yes | yes |
2483+ * | ee 13 | yes | yes | yes |
2484+ */
24702485#ifdef PGPRO_EE
24712486
2487+ /* All the ee have ATX. */
2488+ #define ATX_CHECK (getNestLevelATX() != 0)
2489+ /* ee10 and less does not have connpool. */
2490+ #if (PG_VERSION_NUM >=110000 )
2491+ #define CONNPOOL_CHECK (!IsDedicatedBackend)
2492+ #else
2493+ #define CONNPOOL_CHECK (false)
2494+ #endif
2495+
24722496#if (PG_VERSION_NUM < 100000 )
24732497/*
24742498 * This versions does not have dedicated macro to check compatibility.
2475- * So, use simple check here.
2499+ * So, use simple check here for ATX .
24762500 */
2477- #define PG_COMPATIBILITY_CHECK (name ) \
2478- if (getNestLevelATX() != 0) \
2479- elog(ERROR, "%s extension is not compatible with autonomous " \
2480- "transactions and connection pooling", name);
2501+ if (ATX_CHECK )
2502+ {
2503+ freeStatsLists ();
2504+ elog (ERROR ,"pg_variables extension is not compatible with "
2505+ "autonomous transactions" );
2506+ }
24812507#else
24822508/*
2483- * Sinceee12 there is PG_COMPATIBILITY_CHECK macro to check compatibility.
2509+ * Sinceee10 there is PG_COMPATIBILITY_CHECK macro to check compatibility.
24842510 * But for some reasons it may not be present at the moment.
24852511 * So, if PG_COMPATIBILITY_CHECK macro is not present pg_variables are
24862512 * always compatible.
24872513 */
2488- #ifndef PG_COMPATIBILITY_CHECK
2489- #define PG_COMPATIBILITY_CHECK_LOCK
2490- # define PG_COMPATIBILITY_CHECK ( name )
2491- #endif
2514+ #ifdef PG_COMPATIBILITY_CHECK
2515+ {
2516+ if ( ATX_CHECK || CONNPOOL_CHECK )
2517+ freeStatsLists ();
24922518
2493- PG_COMPATIBILITY_CHECK ("pg_variables" );
2519+ PG_COMPATIBILITY_CHECK ("pg_variables" );
2520+ }
2521+ #endif /* PG_COMPATIBILITY_CHECK */
2522+ #endif /* PG_VERSION_NUM */
24942523
2495- #ifdef PG_COMPATIBILITY_CHECK_LOCK
2496- #undef PG_COMPATIBILITY_CHECK_LOCK
2497- #undef PG_COMPATIBILITY_CHECK
2498- #endif
2499- #endif
2524+ #undef ATX_CHECK
2525+ #undef CONNPOOL_CHECK
25002526
2501- #endif
2527+ #endif /* PGPRO_EE */
25022528}
25032529
25042530/*
@@ -2513,8 +2539,8 @@ pgvSubTransCallback(SubXactEvent event, SubTransactionId mySubid,
25132539switch (event )
25142540{
25152541case SUBXACT_EVENT_START_SUB :
2516- compatibility_check ();
25172542pushChangesStack ();
2543+ compatibility_check ();
25182544break ;
25192545case SUBXACT_EVENT_COMMIT_SUB :
25202546processChanges (RELEASE_SAVEPOINT );