{"id":13705730,"url":"https://github.com/pgsentinel/pgsentinel","last_synced_at":"2026-02-07T12:00:38.770Z","repository":{"id":82042027,"uuid":"140053781","full_name":"pgsentinel/pgsentinel","owner":"pgsentinel","description":"postgresql extension providing Active session history ","archived":false,"fork":false,"pushed_at":"2026-02-03T03:09:44.000Z","size":158,"stargazers_count":187,"open_issues_count":14,"forks_count":26,"subscribers_count":13,"default_branch":"master","last_synced_at":"2026-02-03T17:04:52.199Z","etag":null,"topics":["ash","database","extension","postgres","postgresql","postgresql-extension","troubleshooting","tuning"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"postgresql","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgsentinel.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-07-07T04:53:38.000Z","updated_at":"2026-02-03T03:09:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"63d75678-56f7-49ce-859f-d87151c4b0ac","html_url":"https://github.com/pgsentinel/pgsentinel","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/pgsentinel/pgsentinel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgsentinel%2Fpgsentinel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgsentinel%2Fpgsentinel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgsentinel%2Fpgsentinel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgsentinel%2Fpgsentinel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgsentinel","download_url":"https://codeload.github.com/pgsentinel/pgsentinel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgsentinel%2Fpgsentinel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29193993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ash","database","extension","postgres","postgresql","postgresql-extension","troubleshooting","tuning"],"created_at":"2024-08-02T22:00:46.900Z","updated_at":"2026-02-07T12:00:38.695Z","avatar_url":"https://github.com/pgsentinel.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"`pgsentinel` – sampling active session history\n=============================================================\n\n[![Build Status](https://travis-ci.org/pgsentinel/pgsentinel.svg?branch=master)](https://travis-ci.org/pgsentinel/pgsentinel)\n\nIntroduction\n------------\n\nPostgreSQL provides session activity. However, in order to gather activity\nbehavior, users have to sample the pg_stat_activity view multiple times.\n`pgsentinel` is an extension to record active session history and link\n the activity with query statistics (`pg_stat_statements`).\n\nThe module must be loaded by adding `pgsentinel` to\n`shared_preload_libraries` in postgresql.conf, which means a server restart\nis needed.\n\nWhen `pgsentinel` is enabled, it collects the history of session activity:\n\n * It's implemented as an in-memory ring buffer where\n   samples are written with a given (configurable)\n   period.  Therefore, the user can see some number of\n   recent samples depending on the history size (configurable).\n\nIn combination with `pg_stat_statements`, this extension can link the session activity with\nquery statistics.\n\nTo get more granular queries statistics, `pgsentinel` samples the `pg_stat_statements` view:\n\n * at the same time it is sampling the active sessions\n * only for the queryid associated to an active session (if any) during the sampling\n\n`pgsentinel` launches a special background worker for gathering session activities.\n\nAvailability\n------------\n\n`pgsentinel` is implemented as an extension and not available in the default\nPostgreSQL installation. It is available from\n[github](https://github.com/pgsentinel/pgsentinel)\nunder the same license as\n[PostgreSQL License](https://github.com/pgsentinel/pgsentinel/blob/master/LICENSE)\nand supports PostgreSQL 9.6+.\n\nInstallation\n------------\n\n`pgsentinel` is a PostgreSQL extension which requires PostgreSQL 9.6 or\nhigher. Before the build and install steps, you should ensure the following:\n\n * PostgreSQL version is 9.6 or higher.\n * You have the development package of PostgreSQL installed or you built\n   PostgreSQL from source.\n * Your `PATH` variable configuration includes `pg_config`, or\n   you've set a value for `PG_CONFIG`.\n\nThe typical installation procedure may look like:\n\nAs `pgsentinel` uses the `pg_stat_statements` extension (officially bundled with PostgreSQL) for tracking which queries get executed in your database, add the following entries to your postgres.conf:\n\n    $ shared_preload_libraries = 'pg_stat_statements,pgsentinel'\n    $ # Increase the max size of the query strings Postgres records\n    $ track_activity_query_size = 2048\n    $ # Track statements generated by stored procedures as well\n    $ pg_stat_statements.track = all\n\nrestart the postgresql daemon and create the extension:\n\n    $ git clone https://github.com/pgsentinel/pgsentinel.git\n    $ cd pgsentinel/src\n    $ make\n    $ sudo make install\n    $ psql DB -c \"CREATE EXTENSION pgsentinel;\"\n\n\nUsage\n-----\n\n`pgsentinel` reports the active session history activity through the `pg_active_session_history` view:\n\n |     Column      |           Type           | Collation | Nullable | Default  |\n | ------------------ | -------------------------- | -----------  | ----------  | ---------  |\n  | ash_time         | timestamp with time zone |           |          |  |\n  | datid            | oid                      |           |          |  |\n  | datname          | text                     |           |          |  |\n  | pid              | integer                  |           |          |  |\n  | leader_pid             | integer                  |           |          |  |\n  | usesysid         | oid                      |           |          |  |\n  | usename          | text                     |           |          |  |\n  | application_name | text                     |           |          |  |\n  | client_addr      | text                     |           |          |  |\n  | client_hostname  | text                     |           |          |  |\n  | client_port      | integer                  |           |          |  |\n  | backend_start    | timestamp with time zone |           |          |  |\n  | xact_start       | timestamp with time zone |           |          |  |\n  | query_start      | timestamp with time zone |           |          |  |\n  | state_change     | timestamp with time zone |           |          |  |\n  | wait_event_type  | text                     |           |          |  |\n  | wait_event       | text                     |           |          |  |\n  | state            | text                     |           |          |  |\n  | backend_xid      | xid                      |           |          |  |\n  | backend_xmin     | xid                      |           |          |  |\n  | top_level_query  | text                     |           |          |  |\n  | query            | text                     |           |          |  |\n  | cmdtype          | text                     |           |          |  |\n  | queryid          | bigint                   |           |          |  |\n  | backend_type     | text                     |           |          |  |\n  | blockers         | integer                  |           |          |  |\n  | blockerpid       | integer                  |           |          |  |\n  | blocker_state    | text                     |           |          |  |\n\nYou can see it as samplings of `pg_stat_activity` providing more information:\n\n* `ash_time`: the sampling time\n* `top_level_query`: the top level statement (in case PL/pgSQL is used)\n* `query`: the statement being executed (not normalised, as it is in `pg_stat_statements`, which means you see parameter values)\n* `cmdtype`: the statement type (SELECT,UPDATE,INSERT,DELETE,UTILITY,UNKNOWN,NOTHING)\n* `queryid`: the queryid of the statement which links to pg_stat_statements\n* `blockers`: the number of blockers\n* `blockerpid`: the pid of the blocker (if blockers = 1), the pid of one blocker (if blockers \u003e 1)\n* `blocker_state`: state of the blocker (state of the blockerpid) \n\n`pgsentinel` also reports query statistics history through the `pg_stat_statements_history` view:\n\n\n |     Column      |           Type           | Collation | Nullable | Default  |\n | ------------------ | -------------------------- | -----------  | ----------  | ---------  |\n| ash_time            | timestamp with time zone |           |          | |\n| userid              | oid                      |           |          | |\n| dbid                | oid                      |           |          | |\n| queryid             | bigint                   |           |          | |\n| calls               | bigint                   |           |          | |\n| total_exec_time          | double precision         |           |          | |\n| rows                | bigint                   |           |          | |\n| shared_blks_hit     | bigint                   |           |          | |\n| shared_blks_read    | bigint                   |           |          | |\n| shared_blks_dirtied | bigint                   |           |          | |\n| shared_blks_written | bigint                   |           |          | |\n| local_blks_hit      | bigint                   |           |          | |\n| local_blks_read     | bigint                   |           |          | |\n| local_blks_dirtied  | bigint                   |           |          | |\n| local_blks_written  | bigint                   |           |          | |\n| temp_blks_read      | bigint                   |           |          | |\n| temp_blks_written   | bigint                   |           |          | |\n| blk_read_time       | double precision         |           |          | |\n| blk_write_time      | double precision         |           |          | |\n| plans      | bigint         |           |          | |\n| total_plan_time      | double precision         |           |          | |\n| wal_records      | bigint         |           |          | |\n| wal_fpi      | bigint         |           |          | |\n| wal_bytes      | numeric         |           |          | |\n\nThe field descriptions are the same as for `pg_stat_statements` (except for the `ash_time` one, which is the time of the active session history sampling).\n\nThe worker is controlled by the following GUCs:\n\n|         Parameter name              | Data type |                  Description                | Default value | Min value  |\n| ----------------------------------- | --------- | ------------------------------------------- | ------------  | -------- |\n| pgsentinel_ash.sampling_period     | int4      | Period for history sampling in seconds |            1 | 1 |\n| pgsentinel_ash.max_entries     | int4      | Size of pg_active_session_history in-memory ring buffer |            1000 | 1000 |\n| pgsentinel.db_name        | char      |  database the worker should connect to          |          postgres | |\n| pgsentinel_ash.track_idle_trans     | boolean      | track session in idle in transaction state |            false |  |\n| pgsentinel_pgssh.max_entries     | int4      | Size of pg_stat_statements_history in-memory ring buffer |            1000 | 1000 |\n| pgsentinel_pgssh.enable     | boolean      | enable pg_stat_statements_history |            false |  |\n\nRemark\n-------------------------\n\n* Some fields may be NULL depending on the version (for example, `leader_pid` is NULL for version \u003c= 13.0...)\n\nSee how to query the view in this short video\n-------------\n[![Alt text](https://raw.githubusercontent.com/pgsentinel/pg_ash_scripts/master/images/video_pg_ash_scripts.PNG)](https://www.youtube.com/watch?v=WVKzKjlK75U)\n\n\n### The videos are available on [youtube](https://www.youtube.com/channel/UCGVciSS2YwnPhtHHGB3Ep3A)\n\n\nContribution\n------------\n\nIf you're lacking some functionality in `pgsentinel` then you're welcome to make pull requests.\n\nAuthor\n-------\n\n * Bertrand Drouvot \u003cbdrouvot@gmail.com\u003e,\n   France, [Twitter](https://twitter.com/BertrandDrouvot)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgsentinel%2Fpgsentinel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgsentinel%2Fpgsentinel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgsentinel%2Fpgsentinel/lists"}