{"id":19458474,"url":"https://github.com/postgrespro/pg_wait_sampling","last_synced_at":"2025-04-04T08:04:35.799Z","repository":{"id":6084508,"uuid":"54636498","full_name":"postgrespro/pg_wait_sampling","owner":"postgrespro","description":"Sampling based statistics of wait events","archived":false,"fork":false,"pushed_at":"2025-03-26T09:55:23.000Z","size":168,"stargazers_count":156,"open_issues_count":5,"forks_count":38,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-03-28T07:02:48.622Z","etag":null,"topics":["history","postgres","profile","sampling","waits"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postgrespro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-24T11:19:52.000Z","updated_at":"2025-03-20T01:15:08.000Z","dependencies_parsed_at":"2025-01-24T23:10:38.048Z","dependency_job_id":"91f2ab19-bc8f-40f1-b124-c48f9c142921","html_url":"https://github.com/postgrespro/pg_wait_sampling","commit_stats":{"total_commits":111,"total_committers":19,"mean_commits":5.842105263157895,"dds":0.7747747747747747,"last_synced_commit":"c6ae0dd43220afc12c5eec80ad349e6896eaac8e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_wait_sampling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_wait_sampling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_wait_sampling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_wait_sampling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postgrespro","download_url":"https://codeload.github.com/postgrespro/pg_wait_sampling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247137624,"owners_count":20889903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["history","postgres","profile","sampling","waits"],"created_at":"2024-11-10T17:27:14.799Z","updated_at":"2025-04-04T08:04:35.776Z","avatar_url":"https://github.com/postgrespro.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://app.travis-ci.com/postgrespro/pg_wait_sampling.svg?branch=master)](https://app.travis-ci.com/postgrespro/pg_wait_sampling)\n[![GitHub license](https://img.shields.io/badge/license-PostgreSQL-blue.svg)](https://raw.githubusercontent.com/postgrespro/pg_wait_sampling/master/LICENSE)\n\n`pg_wait_sampling` – sampling based statistics of wait events\n=============================================================\n\nIntroduction\n------------\n\nPostgreSQL provides information about current wait event of particular\nprocess.  However, in order to gather descriptive statistics of server\nbehavior user have to sample current wait event multiple times.\n`pg_wait_sampling` is an extension for collecting sampling statistics of wait\nevents.\n\nThe module must be loaded by adding `pg_wait_sampling` to\n`shared_preload_libraries` in postgresql.conf, because it requires additional\nshared memory and launches background worker.  This means that a server restart\nis needed to add or remove the module.\n\nWhen used with `pg_stat_statements` it is recommended to put `pg_stat_statements`\nbefore `pg_wait_sampling` in `shared_preload_libraries` so queryIds of\nutility statements are not rewritten by the former.\n\nWhen `pg_wait_sampling` is enabled, it collects two kinds of statistics.\n\n * History of waits events.  It's implemented as in-memory ring buffer where\n   samples of each process wait events are written with given (configurable)\n   period.  Therefore, for each running process user can see some number of\n   recent samples depending on history size (configurable).  Assuming there is\n   a client who periodically read this history and dump it somewhere, user\n   can have continuous history.\n * Waits profile.  It's implemented as in-memory hash table where count\n   of samples are accumulated per each process and each wait event\n   (and each query with `pg_stat_statements`).  This hash\n   table can be reset by user request.  Assuming there is a client who\n   periodically dumps profile and resets it, user can have statistics of\n   intensivity of wait events among time.\n\nIn combination with `pg_stat_statements` this extension can also provide\nper query statistics.\n\n`pg_wait_sampling` launches special background worker for gathering the\nstatistics above.\n\nAvailability\n------------\n\n`pg_wait_sampling` is implemented as an extension and not available in default\nPostgreSQL installation. It is available from\n[github](https://github.com/postgrespro/pg_wait_sampling)\nunder the same license as\n[PostgreSQL](http://www.postgresql.org/about/licence/)\nand supports PostgreSQL 13+.\n\nInstallation\n------------\n\nPre-built `pg_wait_sampling` packages are provided in official PostgreSQL\nrepository: https://download.postgresql.org/pub/repos/\n\nManual build\n------------\n\n`pg_wait_sampling` is PostgreSQL extension which requires PostgreSQL 13 or\nhigher. Before build and install you should ensure following:\n\n * PostgreSQL version is 13 or higher.\n * You have development package of PostgreSQL installed or you built\n   PostgreSQL from source.\n * Your PATH variable is configured so that `pg_config` command available, or\n   set PG_CONFIG variable.\n\nTypical installation procedure may look like this:\n\n    $ git clone https://github.com/postgrespro/pg_wait_sampling.git\n    $ cd pg_wait_sampling\n    $ make USE_PGXS=1\n    $ sudo make USE_PGXS=1 install\n\nThen add `shared_preload_libraries = pg_wait_sampling` to `postgresql.conf` and\nrestart the server.\n\nTo test your installation:\n\n    $ make USE_PGXS=1 installcheck\n\nTo create the extension in the target database:\n\n    CREATE EXTENSION pg_wait_sampling;\n\nCompilation on Windows is not supported, since the extension uses symbols from PostgreSQL\nthat are not exported.\n\nUsage\n-----\n\n`pg_wait_sampling` interacts with user by set of views and functions.\n\n`pg_wait_sampling_current` view – information about current wait events for\nall processed including background workers.\n\n| Column name | Column type |      Description        |\n| ----------- | ----------- | ----------------------- |\n| pid         | int4        | Id of process           |\n| event_type  | text        | Name of wait event type |\n| event       | text        | Name of wait event      |\n| queryid     | int8        | Id of query             |\n\n`pg_wait_sampling_get_current(pid int4)` returns the same table for single given\nprocess.\n\n`pg_wait_sampling_history` view – history of wait events obtained by sampling into\nin-memory ring buffer.\n\n| Column name | Column type |      Description        |\n| ----------- | ----------- | ----------------------- |\n| pid         | int4        | Id of process           |\n| ts          | timestamptz | Sample timestamp        |\n| event_type  | text        | Name of wait event type |\n| event       | text        | Name of wait event      |\n| queryid     | int8        | Id of query             |\n\n`pg_wait_sampling_profile` view – profile of wait events obtained by sampling into\nin-memory hash table.\n\n| Column name | Column type |      Description        |\n| ----------- | ----------- | ----------------------- |\n| pid         | int4        | Id of process           |\n| event_type  | text        | Name of wait event type |\n| event       | text        | Name of wait event      |\n| queryid     | int8        | Id of query             |\n| count       | text        | Count of samples        |\n\n`pg_wait_sampling_reset_profile()` function resets the profile.\n\nThe work of wait event statistics collector worker is controlled by following\nGUCs.\n\n| Parameter name                   | Data type | Description                                 | Default value |\n|----------------------------------| --------- |---------------------------------------------|--------------:|\n| pg_wait_sampling.history_size    | int4      | Size of history in-memory ring buffer       |          5000 |\n| pg_wait_sampling.history_period  | int4      | Period for history sampling in milliseconds |            10 |\n| pg_wait_sampling.profile_period  | int4      | Period for profile sampling in milliseconds |            10 |\n| pg_wait_sampling.profile_pid     | bool      | Whether profile should be per pid           |          true |\n| pg_wait_sampling.profile_queries | enum      | Whether profile should be per query         |           top |\n| pg_wait_sampling.sample_cpu      | bool      | Whether on CPU backends should be sampled   |          true |\n\nIf `pg_wait_sampling.profile_pid` is set to false, sampling profile wouldn't be\ncollected in per-process manner.  In this case the value of pid could would\nbe always zero and corresponding row contain samples among all the processes.\n\nIf `pg_wait_sampling.profile_queries` is set to `none`, `queryid` field in\nviews will be zero. If it is set to `top`, queryIds only of top level statements\nare recorded. If it is set to `all`, queryIds of nested statements are recorded.\n\nIf `pg_wait_sampling.sample_cpu` is set to true then processes that are not\nwaiting on anything are also sampled. The wait event columns for such processes\nwill be NULL.\n\nValues of these GUC variables can be changed only in config file or with ALTER SYSTEM.\nThen you need to reload server's configuration (such as with pg_reload_conf function)\nfor changes to take effect.\n\nSee\n[PostgreSQL documentation](http://www.postgresql.org/docs/devel/static/monitoring-stats.html#WAIT-EVENT-TABLE)\nfor list of possible wait events.\n\nContribution\n------------\n\nPlease, notice, that `pg_wait_sampling` is still under development and while\nit's stable and tested, it may contains some bugs. Don't hesitate to raise\n[issues at github](https://github.com/postgrespro/pg_wait_sampling/issues) with\nyour bug reports.\n\nIf you're lacking of some functionality in `pg_wait_sampling` and feeling power\nto implement it then you're welcome to make pull requests.\n\nAuthors\n-------\n\n * Alexander Korotkov \u003ca.korotkov@postgrespro.ru\u003e, Postgres Professional,\n   Moscow, Russia\n * Ildus Kurbangaliev \u003ci.kurbangaliev@gmail.com\u003e, Postgres Professional,\n   Moscow, Russia\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_wait_sampling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostgrespro%2Fpg_wait_sampling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_wait_sampling/lists"}