{"id":19458502,"url":"https://github.com/postgrespro/pg_grab_statement","last_synced_at":"2025-04-25T06:30:27.839Z","repository":{"id":69542801,"uuid":"42955412","full_name":"postgrespro/pg_grab_statement","owner":"postgrespro","description":"PostgreSQL extension for recoding workload of specific database","archived":false,"fork":false,"pushed_at":"2016-03-21T10:05:22.000Z","size":8,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-24T10:48:42.441Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"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":"2015-09-22T19:15:54.000Z","updated_at":"2023-03-03T05:58:32.000Z","dependencies_parsed_at":"2023-07-06T12:18:09.362Z","dependency_job_id":null,"html_url":"https://github.com/postgrespro/pg_grab_statement","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_grab_statement","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_grab_statement/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_grab_statement/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fpg_grab_statement/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postgrespro","download_url":"https://codeload.github.com/postgrespro/pg_grab_statement/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250766957,"owners_count":21483894,"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":[],"created_at":"2024-11-10T17:27:22.231Z","updated_at":"2025-04-25T06:30:27.829Z","avatar_url":"https://github.com/postgrespro.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"pg_grab_statement - PostgreSQL extension for recoding workload of specific database\n========================================================================\n\npg_grab_statement is a PostgreSQL extension for recording detailed information of successfully committed transactions.\n\nThis extension overrides Executor{Start,End} PostgreSQL hooks and writes detailed information in an unlogged table without using the SQL level.\n\n\nAuthors\n-------\n\n * Dmitry Vasilyev \u003cd.vasilyev@postgrespro.ru\u003e, Postgres Professional, Moscow, Russia\n\n\nLicense\n-------\n\nDevelopment version, available on github, released under the\nGNU General Public License, version 2 (June 1991).\n\nDownloads\n---------\nStable version of pg_grab_statement is available at https://github.com/postgrespro/pg_grab_statement\n\nInstallation\n------------\n\npg_grab_statement is a regular PostgreSQL extension.\nTo build and install it you should ensure the following:\n\n * The development package of PostgreSQL is installed or\n   PostgreSQL is built from source.\n * Your PATH variable is configured so that pg_config command is available.\n\nTypical installation procedure may look like this:\n\n\t$ git clone https://github.com/postgrespro/pg_grab_statement.git\n\t$ cd pg_grab_statement\n\t$ make USE_PGXS=1\n\t$ sudo make USE_PGXS=1 install\n\t$ psql YourDatabaseName -c \"CREATE EXTENSION pg_grab_statement;\"\n\n\nPostgreSQL 9.0 installation notes\n----------------------\nYou need to create the logging table by hand:\n\n\tCREATE SCHEMA grab;\n\tCREATE TABLE grab.statement(\n\t    transaction_id        int,\n\t    query_id              int,\n\t    process_id            int,\n\t    user_id               int,\n\t    query_start           timestamptz,\n\t    total_execution       float8,\n\t    query_type_id         int,\n\t    query_source          text,\n\t    query_param_values    text[],\n\t    query_param_types     regtype[]\n\t);\n\n\n\nChoose your right way to enable the library\n---------------------------------------\n\nLoad library in current session:\n\n\tLOAD 'pg_grab_statement';\n\nOr set shared_preload_libraries in postgresql.conf (works for version \u003e= 9.0) to record all transactions on all databases:\n\n\tshared_preload_libraries = 'pg_grab_statement'\n\nOr enable recording for all new sessions with a specific role (works for version \u003e= 9.4, without restart):\n\n\tALTER ROLE rolename SET session_preload_libraries = 'pg_grab_statement';\n\nOr record all new sessions of all users in a specific database (works for version \u003e= 9.4, without restart):\n\n\tALTER DATABASE dbname SET session_preload_libraries = 'pg_grab_statement';\n\n\nOverhead\n--------\n\n* No overhead if library is not loaded\n* 10-15% with SELECT-only benchmark\n\n\nRecorded data\n--------------\n```\n=# \\d+ grab.statement_log\n                                                Unlogged table \"grab.statement_log\"\n       Column       |           Type           | Modifiers | Storage  | Stats target |                 Description\n--------------------+--------------------------+-----------+----------+--------------+---------------------------------------------\n transaction_id     | integer                  |           | plain    |              | Number of transaction\n query_id           | integer                  |           | plain    |              | Number of query of the specific transaction\n process_id         | integer                  |           | plain    |              | Backend PID\n user_id            | integer                  |           | plain    |              | User ID\n query_start        | timestamp with time zone |           | plain    |              | Timestamp of query execution\n total_execution    | double precision         |           | plain    |              | Total time execution (in seconds)\n query_type_id      | integer                  |           | plain    |              | Type of query operation id\n query_source       | text                     |           | extended |              | Source of the query\n query_param_values | text[]                   |           | extended |              | Parameter values of query\n query_param_types  | regtype[]                |           | extended |              | Parameter types of query\n```\n\nDefenition of query operation types\n-----------------------------------\n```\n=# select * from grab.query_types();\n id | modify |  name\n----+--------+---------\n  0 | t      | UNKNOWN\n  1 | f      | SELECT\n  2 | t      | UPDATE\n  3 | t      | INSERT\n  4 | t      | DELETE\n  5 | t      | UTILITY\n  6 | t      | NOTHING\n(7 rows)\n```\n\nUser view\n---------\n```\n=# \\d+ grab.statements\n                                               View \"grab.statements\"\n       Column       |           Type           | Modifiers | Storage  |                 Description\n--------------------+--------------------------+-----------+----------+---------------------------------------------\n transaction        | integer                  |           | plain    | Number of transaction\n query_number       | integer                  |           | plain    | Number of query of the specific transaction\n backend_pid        | integer                  |           | plain    | Backend PID\n username           | name                     |           | plain    | User name\n query_start        | timestamp with time zone |           | plain    | Timestamp of query execution\n total_execution    | double precision         |           | plain    | Total time execution (in seconds)\n query_type         | text                     |           | extended | Type of query operation\n query_modify_data  | boolean                  |           | plain    | Is query modify data\n query_source       | text                     |           | extended | Source of the query\n query_param_values | text[]                   |           | extended | Parameter values of query\n query_param_types  | regtype[]                |           | extended | Parameter types of query\nView definition:\n SELECT l.transaction_id AS transaction,\n    l.query_id AS query_number,\n    l.process_id AS backend_pid,\n    u.usename AS username,\n    l.query_start,\n    l.total_execution,\n    t.name AS query_type,\n    t.modify AS query_modify_data,\n    l.query_source,\n    l.query_param_values,\n    l.query_param_types\n   FROM grab.statement_log l\n     LEFT JOIN pg_user u ON u.usesysid = l.user_id::oid\n     LEFT JOIN grab.query_types() t(id, modify, name) ON t.id = l.query_type_id;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_grab_statement","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostgrespro%2Fpg_grab_statement","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fpg_grab_statement/lists"}