{"id":14069866,"url":"https://github.com/lob/pg_insights","last_synced_at":"2025-10-02T01:31:11.358Z","repository":{"id":152880093,"uuid":"129978376","full_name":"lob/pg_insights","owner":"lob","description":"A collection of convenient SQL for monitoring Postgres database health.","archived":true,"fork":false,"pushed_at":"2019-12-11T00:53:24.000Z","size":14,"stargazers_count":298,"open_issues_count":0,"forks_count":19,"subscribers_count":65,"default_branch":"master","last_synced_at":"2024-09-28T18:04:53.581Z","etag":null,"topics":["database","database-maintenance","database-management","database-monitoring","monitoring","pg-extras","pg-insights","postgres","psql"],"latest_commit_sha":null,"homepage":"","language":"TSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lob.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}},"created_at":"2018-04-17T23:56:41.000Z","updated_at":"2024-07-25T03:39:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"e5331e71-07cf-44c5-a332-14743f3b075d","html_url":"https://github.com/lob/pg_insights","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lob%2Fpg_insights","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lob%2Fpg_insights/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lob%2Fpg_insights/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lob%2Fpg_insights/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lob","download_url":"https://codeload.github.com/lob/pg_insights/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234922780,"owners_count":18907828,"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":["database","database-maintenance","database-management","database-monitoring","monitoring","pg-extras","pg-insights","postgres","psql"],"created_at":"2024-08-13T07:07:18.093Z","updated_at":"2025-10-02T01:31:11.027Z","avatar_url":"https://github.com/lob.png","language":"TSQL","funding_links":[],"categories":["服务端测试","Compiled list","Utilities","TSQL"],"sub_categories":["服务端监控","plv8:"],"readme":"# pg_insights\n\nConvenient SQL for monitoring Postgres database health. This repository is\ninspired by commands from Heroku's\n[pg_extras](https://github.com/heroku/heroku-pg-extras) repository.\n\n## How to Use\n\n### psql\n\nYou can run a script using `psql`'s `-f` option. For example:\n\n```bash\n$ psql postgres -f sql/cache_hit_rate.sql\n```\n\nIt also works with aliases you have setup with `psql`:\n\n```bash\n$ alias psql_my_db=\"psql -h my_db.com -d my_db -U admin\"\n$ psql_my_db -f sql/cache_hit_rate.sql\n```\n\n### Other\n\nYou can also copy/paste any of the SQL in the [`sql/`](sql) directory and run\nwith the Postgres client of your choice.\n\n## Scripts\n\n#### [`active_autovacuums.sql`](sql/active_autovacuums.sql) (admin permission)\n* **Returns all running autovacuums operations.**\n\n#### [`analyze_stats.sql`](sql/analyze_stats.sql) (read permission)\n* **Returns autovacuum analyze stats for each table.**\n\n#### [`bloat.sql`](sql/bloat.sql) (read permission)\n* **Returns the approximate bloat from dead tuples for each table.**\n* This bloat can also be index bloat.\n\n#### [`buffer_cache_usage.sql`](sql/buffer_cache_usage.sql) (admin permission)\n* **Returns the distribution of shared buffers used for each table.**\n* *Requires the [pg_buffercache](https://www.postgresql.org/docs/current/pgbuffercache.html) extension.*\n* Includes the total bytes of a table in shared buffers, the percentage of\n  shared buffers a table is using, and the percentage of a table the exists\n  in shared buffers.\n\n#### [`cache_hit_rate.sql`](sql/cache_hit_rate.sql) (read permission)\n* **Returns the cache hit rate for indices and tables.**\n* This is the rate of queries that only hit in-memory shared buffers rather\n  than having to fetch from disk.\n* Note that a queries that are cache misses in Postgres's shared buffers may\n  still hit the in-memory OS page cache, so a miss not technically go all the\n  way to the disk.\n* Both of these rates should be 99+% ideally.\n\n#### [`index_hit_rate.sql`](sql/index_hit_rate.sql) (read permission)\n* **Returns the index hit rate for each table.**\n* This rate represents the percentage of queries that utilize 1 or more indices\n  when querying a table.\n* These rates should be 99+% ideally.\n\n#### [`index_size.sql`](sql/index_size.sql) (read permission)\n* **Returns the size of each index in bytes.**\n\n#### [`reset_stats.sql`](sql/reset_stats.sql) (admin permission)\n* **Resets pg_stats statistics tables.**\n\n#### [`table_settings.sql`](sql/table_settings.sql) (read permission)\n* **Returns the table-specific settings of each table.**\n\n#### [`table_size.sql`](sql/table_size.sql) (read permission)\n* **Returns the size of each table in bytes.**\n* Does not include size of the tables' indices.\n\n#### [`table_size_with_indices.sql`](sql/table_size_with_indices.sql) (read permission)\n* **Returns size of each table in bytes including all indices.**\n\n#### [`toast_size.sql`](sql/toast_size.sql) (read permission)\n* **Returns total size of all\n  [TOAST](https://www.postgresql.org/docs/current/storage-toast.html) data in\n  each table in bytes.**\n\n#### [`unused_indices.sql`](sql/unused_indices.sql) (read permission)\n* **Returns indices that are rarely used.**\n* Note that sometimes the query optimizer will elect to avoid using indices for\n  tables with a very small number of rows because it can be more efficient.\n\n#### [`vacuum_stats.sql`](sql/vacuum_stats.sql) (read permission)\n* **Returns autovacuum stats for each table.**\n\n## Contributing\n\nPull requests for bug fixes, improvements, or new SQL are always welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flob%2Fpg_insights","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flob%2Fpg_insights","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flob%2Fpg_insights/lists"}