@@ -198,8 +198,6 @@ static time_t last_pgstat_start_time;
198
198
199
199
static bool pgStatRunningInCollector = false;
200
200
201
- static PgStat_SubXactStatus * pgStatXactStack = NULL ;
202
-
203
201
/*
204
202
* Info about current "snapshot" of stats file
205
203
*/
@@ -740,158 +738,6 @@ pgstat_initialize(void)
740
738
}
741
739
742
740
743
- /* ------------------------------------------------------------
744
- * Transaction integration
745
- * ------------------------------------------------------------
746
- */
747
-
748
- /*
749
- * Called from access/transam/xact.c at top-level transaction commit/abort.
750
- */
751
- void
752
- AtEOXact_PgStat (bool isCommit , bool parallel )
753
- {
754
- PgStat_SubXactStatus * xact_state ;
755
-
756
- AtEOXact_PgStat_Database (isCommit , parallel );
757
-
758
- /* handle transactional stats information */
759
- xact_state = pgStatXactStack ;
760
- if (xact_state != NULL )
761
- {
762
- Assert (xact_state -> nest_level == 1 );
763
- Assert (xact_state -> prev == NULL );
764
-
765
- AtEOXact_PgStat_Relations (xact_state , isCommit );
766
- }
767
- pgStatXactStack = NULL ;
768
-
769
- /* Make sure any stats snapshot is thrown away */
770
- pgstat_clear_snapshot ();
771
- }
772
-
773
- /*
774
- * Called from access/transam/xact.c at subtransaction commit/abort.
775
- */
776
- void
777
- AtEOSubXact_PgStat (bool isCommit , int nestDepth )
778
- {
779
- PgStat_SubXactStatus * xact_state ;
780
-
781
- /* merge the sub-transaction's transactional stats into the parent */
782
- xact_state = pgStatXactStack ;
783
- if (xact_state != NULL &&
784
- xact_state -> nest_level >= nestDepth )
785
- {
786
- /* delink xact_state from stack immediately to simplify reuse case */
787
- pgStatXactStack = xact_state -> prev ;
788
-
789
- AtEOSubXact_PgStat_Relations (xact_state , isCommit , nestDepth );
790
-
791
- pfree (xact_state );
792
- }
793
- }
794
-
795
- /*
796
- * Save the transactional stats state at 2PC transaction prepare.
797
- */
798
- void
799
- AtPrepare_PgStat (void )
800
- {
801
- PgStat_SubXactStatus * xact_state ;
802
-
803
- xact_state = pgStatXactStack ;
804
- if (xact_state != NULL )
805
- {
806
- Assert (xact_state -> nest_level == 1 );
807
- Assert (xact_state -> prev == NULL );
808
-
809
- AtPrepare_PgStat_Relations (xact_state );
810
- }
811
- }
812
-
813
- /*
814
- * Clean up after successful PREPARE.
815
- *
816
- * Note: AtEOXact_PgStat is not called during PREPARE.
817
- */
818
- void
819
- PostPrepare_PgStat (void )
820
- {
821
- PgStat_SubXactStatus * xact_state ;
822
-
823
- /*
824
- * We don't bother to free any of the transactional state, since it's all
825
- * in TopTransactionContext and will go away anyway.
826
- */
827
- xact_state = pgStatXactStack ;
828
- if (xact_state != NULL )
829
- {
830
- Assert (xact_state -> nest_level == 1 );
831
- Assert (xact_state -> prev == NULL );
832
-
833
- PostPrepare_PgStat_Relations (xact_state );
834
- }
835
- pgStatXactStack = NULL ;
836
-
837
- /* Make sure any stats snapshot is thrown away */
838
- pgstat_clear_snapshot ();
839
- }
840
-
841
- /*
842
- * Discard any data collected in the current transaction. Any subsequent
843
- * request will cause new snapshots to be read.
844
- *
845
- * This is also invoked during transaction commit or abort to discard
846
- * the no-longer-wanted snapshot.
847
- */
848
- void
849
- pgstat_clear_snapshot (void )
850
- {
851
- pgstat_assert_is_up ();
852
-
853
- /* Release memory, if any was allocated */
854
- if (pgStatLocalContext )
855
- MemoryContextDelete (pgStatLocalContext );
856
-
857
- /* Reset variables */
858
- pgStatLocalContext = NULL ;
859
- pgStatDBHash = NULL ;
860
- replSlotStatHash = NULL ;
861
- subscriptionStatHash = NULL ;
862
-
863
- /*
864
- * Historically the backend_status.c facilities lived in this file, and
865
- * were reset with the same function. For now keep it that way, and
866
- * forward the reset request.
867
- */
868
- pgstat_clear_backend_activity_snapshot ();
869
- }
870
-
871
- /*
872
- * Ensure (sub)transaction stack entry for the given nest_level exists, adding
873
- * it if needed.
874
- */
875
- PgStat_SubXactStatus *
876
- pgstat_xact_stack_level_get (int nest_level )
877
- {
878
- PgStat_SubXactStatus * xact_state ;
879
-
880
- xact_state = pgStatXactStack ;
881
- if (xact_state == NULL || xact_state -> nest_level != nest_level )
882
- {
883
- xact_state = (PgStat_SubXactStatus * )
884
- MemoryContextAlloc (TopTransactionContext ,
885
- sizeof (PgStat_SubXactStatus ));
886
- xact_state -> nest_level = nest_level ;
887
- xact_state -> prev = pgStatXactStack ;
888
- xact_state -> first = NULL ;
889
- pgStatXactStack = xact_state ;
890
- }
891
- return xact_state ;
892
- }
893
-
894
-
895
741
/* ------------------------------------------------------------
896
742
* Public functions used by backends follow
897
743
* ------------------------------------------------------------
@@ -1319,6 +1165,36 @@ pgstat_send_inquiry(TimestampTz clock_time, TimestampTz cutoff_time, Oid databas
1319
1165
pgstat_send (& msg , sizeof (msg ));
1320
1166
}
1321
1167
1168
+ /*
1169
+ * Discard any data collected in the current transaction. Any subsequent
1170
+ * request will cause new snapshots to be read.
1171
+ *
1172
+ * This is also invoked during transaction commit or abort to discard
1173
+ * the no-longer-wanted snapshot.
1174
+ */
1175
+ void
1176
+ pgstat_clear_snapshot (void )
1177
+ {
1178
+ pgstat_assert_is_up ();
1179
+
1180
+ /* Release memory, if any was allocated */
1181
+ if (pgStatLocalContext )
1182
+ MemoryContextDelete (pgStatLocalContext );
1183
+
1184
+ /* Reset variables */
1185
+ pgStatLocalContext = NULL ;
1186
+ pgStatDBHash = NULL ;
1187
+ replSlotStatHash = NULL ;
1188
+ subscriptionStatHash = NULL ;
1189
+
1190
+ /*
1191
+ * Historically the backend_status.c facilities lived in this file, and
1192
+ * were reset with the same function. For now keep it that way, and
1193
+ * forward the reset request.
1194
+ */
1195
+ pgstat_clear_backend_activity_snapshot ();
1196
+ }
1197
+
1322
1198
/*
1323
1199
* Support function for the SQL-callable pgstat* functions. Returns
1324
1200
* the collected statistics for one database or NULL. NULL doesn't mean
0 commit comments