Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sampling based statistics of wait events

License

NotificationsYou must be signed in to change notification settings

postgrespro/pg_wait_sampling

Repository files navigation

Build StatusPGXN versionGitHub license

pg_wait_sampling – sampling based statistics of wait events

Introduction

PostgreSQL 9.6+ provides an information about current wait event of particularprocess. However, in order to gather descriptive statistics of serverbehavior user have to sample current wait event multiple times.pg_wait_sampling is an extension for collecting sampling statistics of waitevents.

The module must be loaded by addingpg_wait_sampling toshared_preload_libraries in postgresql.conf, because it requires additionalshared memory and launches background worker. This means that a server restartis needed to add or remove the module.

Whenpg_wait_sampling is enabled, it collects two kinds of statistics.

  • History of waits events. It's implemented as in-memory ring buffer wheresamples of each process wait events are written with given (configurable)period. Therefore, for each running process user can see some number ofrecent samples depending on history size (configurable). Assuming there isa client who periodically read this history and dump it somewhere, usercan have continuous history.
  • Waits profile. It's implemented as in-memory hash table where countof samples are accumulated per each process and each wait event(and each query withpg_stat_statements). This hashtable can be reset by user request. Assuming there is a client whoperiodically dumps profile and resets it, user can have statistics ofintensivity of wait events among time.

In combination withpg_stat_statements this extension can also provideper query statistics.

pg_wait_sampling launches special background worker for gathering thestatistics above.

Availability

pg_wait_sampling is implemented as an extension and not available in defaultPostgreSQL installation. It is available fromgithubunder the same license asPostgreSQLand supports PostgreSQL 9.6+.

Installation

pg_wait_sampling is PostgreSQL extension which requires PostgreSQL 9.6 orhigher. Before build and install you should ensure following:

  • PostgreSQL version is 9.6 or higher.
  • You have development package of PostgreSQL installed or you builtPostgreSQL from source.
  • Your PATH variable is configured so thatpg_config command available, orset PG_CONFIG variable.

Typical installation procedure may look like this:

$ git clone https://github.com/postgrespro/pg_wait_sampling.git$ cd pg_wait_sampling$ make USE_PGXS=1$ sudo make USE_PGXS=1 install$ make USE_PGXS=1 installcheck$ psql DB -c "CREATE EXTENSION pg_wait_sampling;"

Compilation on Windows is not supported, since the extension uses symbols from PostgreSQLthat are not exported.

Usage

pg_wait_sampling interacts with user by set of views and functions.

pg_wait_sampling_current view – information about current wait events forall processed including background workers.

Column nameColumn typeDescription
pidint4Id of process
event_typetextName of wait event type
eventtextName of wait event
queryidint8Id of query

pg_wait_sampling_get_current(pid int4) returns the same table for single givenprocess.

pg_wait_sampling_history view – history of wait events obtained by sampling intoin-memory ring buffer.

Column nameColumn typeDescription
pidint4Id of process
tstimestamptzSample timestamp
event_typetextName of wait event type
eventtextName of wait event
queryidint8Id of query

pg_wait_sampling_profile view – profile of wait events obtained by sampling intoin-memory hash table.

Column nameColumn typeDescription
pidint4Id of process
event_typetextName of wait event type
eventtextName of wait event
queryidint8Id of query
counttextCount of samples

pg_wait_sampling_reset_profile() function resets the profile.

The work of wait event statistics collector worker is controlled by followingGUCs.

Parameter nameData typeDescriptionDefault value
pg_wait_sampling.history_sizeint4Size of history in-memory ring buffer5000
pg_wait_sampling.history_periodint4Period for history sampling in milliseconds10
pg_wait_sampling.profile_periodint4Period for profile sampling in milliseconds10
pg_wait_sampling.profile_pidboolWhether profile should be per pidtrue
pg_wait_sampling.profile_queriesboolWhether profile should be per queryfalse

Ifpg_wait_sampling.profile_pid is set to false, sampling profile wouldn't becollected in per-process manner. In this case the value of pid could wouldbe always zero and corresponding row contain samples among all the processes.

Whilepg_wait_sampling.profile_queries is set to falsequeryid field inviews will be zero.

These GUCs are allowed to be changed by superuser. Also, they are placed intoshared memory. Thus, they could be changed from any backend and affects workerruntime.

SeePostgreSQL documentationfor list of possible wait events.

Contribution

Please, notice, thatpg_wait_sampling is still under development and whileit's stable and tested, it may contains some bugs. Don't hesitate to raiseissues at github withyour bug reports.

If you're lacking of some functionality inpg_wait_sampling and feeling powerto implement it then you're welcome to make pull requests.

Releases

New features are developed in feature-branches and then merged intomaster. To make a new release:

  1. BumpPGXN version in theMETA.json.
  2. Mergemaster intostable.
  3. Tag new release in thestable withgit tag -a v1.1.X, where the last digit is used for indicating compatible shared library changes and bugfixes. Second digit is used to indicate extension schema change, i.e. whenALTER EXTENSION pg_wait_sampling UPDATE; is required.
  4. Mergestable intodebian. This separate branch is used to independently supportDebian packaging and @anayrat with @df7cb have an access there.

Authors

About

Sampling based statistics of wait events

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors20


[8]ページ先頭

©2009-2025 Movatter.jp