forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7949d95
committed
Introduce pluggable APIs for Cumulative Statistics
This commit adds support in the backend for $subject, allowingout-of-core extensions to plug their own custom kinds of cumulativestatistics. This feature has come up a few times into the lists, andthe first, original, suggestion came from Andres Freund, aboutpg_stat_statements to use the cumulative statistics APIs in sharedmemory rather than its own less efficient internals. The advantage ofthis implementation is that this can be extended to any kind ofstatistics.The stats kinds are divided into two parts:- The in-core "builtin" stats kinds, with designated initializers, ableto use IDs up to 128.- The "custom" stats kinds, able to use a range of IDs from 128 to 256(128 slots available as of this patch), with information saved inTopMemoryContext. This can be made larger, if necessary.There are two types of cumulative statistics in the backend:- For fixed-numbered objects (like WAL, archiver, etc.). These areattached to the snapshot and pgstats shmem control structures forefficiency, and built-in stats kinds still do that to avoid anyredirection penalty. The data of custom kinds is stored in a firstarray in snapshot structure and a second array in the shmem controlstructure, both indexed by their ID, acting as an equivalent of thebuiltin stats.- For variable-numbered objects (like tables, functions, etc.). Theseare stored in a dshash using the stats kind ID in the hash lookup key.Internally, the handling of the builtin stats is unchanged, and bothfixed and variabled-numbered objects are supported. Structuredefinitions for builtin stats kinds are renamed to reflect better thedifferences with custom kinds.Like custom RMGRs, custom cumulative statistics can only be loaded withshared_preload_libraries at startup, and must allocate a unique IDshared across all the PostgreSQL extension ecosystem with the followingwiki page to avoid conflicts:https://wiki.postgresql.org/wiki/CustomCumulativeStatsThis makes the detection of the stats kinds and their handling whenreading and writing stats much easier than, say, allocating IDs forstats kinds from a shared memory counter, that may change the ID used bya stats kind across restarts. When under development, extensions canuse PGSTAT_KIND_EXPERIMENTAL.Two examples that can be used as templates for fixed-numbered andvariable-numbered stats kinds will be added in some follow-up commits,with tests to provide coverage.Some documentation is added to explain how to use this plugin facility.Author: Michael PaquierReviewed-by: Dmitry Dolgov, Bertrand DrouvotDiscussion:https://postgr.es/m/Zmqm9j5EO0I4W8dx@paquier.xyz1 parent365b5a3 commit7949d95
File tree
6 files changed
+348
-33
lines changed- doc/src/sgml
- src
- backend/utils
- activity
- adt
- include
- utils
6 files changed
+348
-33
lines changedLines changed: 57 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3864 | 3864 |
| |
3865 | 3865 |
| |
3866 | 3866 |
| |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
| 3870 | + | |
| 3871 | + | |
| 3872 | + | |
| 3873 | + | |
| 3874 | + | |
| 3875 | + | |
| 3876 | + | |
| 3877 | + | |
| 3878 | + | |
| 3879 | + | |
| 3880 | + | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
| 3922 | + | |
| 3923 | + | |
3867 | 3924 |
| |
3868 | 3925 |
| |
3869 | 3926 |
| |
|
0 commit comments
Comments
(0)