• This repository has been archived on 18/Mar/2022
  • Stars
    star
    299
  • Rank 139,269 (Top 3 %)
  • Language TSQL
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of convenient SQL for monitoring Postgres database health.

pg_insights

Convenient SQL for monitoring Postgres database health. This repository is inspired by commands from Heroku's pg_extras repository.

How to Use

psql

You can run a script using psql's -f option. For example:

$ psql postgres -f sql/cache_hit_rate.sql

It also works with aliases you have setup with psql:

$ alias psql_my_db="psql -h my_db.com -d my_db -U admin"
$ psql_my_db -f sql/cache_hit_rate.sql

Other

You can also copy/paste any of the SQL in the sql/ directory and run with the Postgres client of your choice.

Scripts

active_autovacuums.sql (admin permission)

  • Returns all running autovacuums operations.

analyze_stats.sql (read permission)

  • Returns autovacuum analyze stats for each table.

bloat.sql (read permission)

  • Returns the approximate bloat from dead tuples for each table.
  • This bloat can also be index bloat.

buffer_cache_usage.sql (admin permission)

  • Returns the distribution of shared buffers used for each table.
  • Requires the pg_buffercache extension.
  • Includes the total bytes of a table in shared buffers, the percentage of shared buffers a table is using, and the percentage of a table the exists in shared buffers.

cache_hit_rate.sql (read permission)

  • Returns the cache hit rate for indices and tables.
  • This is the rate of queries that only hit in-memory shared buffers rather than having to fetch from disk.
  • Note that a queries that are cache misses in Postgres's shared buffers may still hit the in-memory OS page cache, so a miss not technically go all the way to the disk.
  • Both of these rates should be 99+% ideally.

index_hit_rate.sql (read permission)

  • Returns the index hit rate for each table.
  • This rate represents the percentage of queries that utilize 1 or more indices when querying a table.
  • These rates should be 99+% ideally.

index_size.sql (read permission)

  • Returns the size of each index in bytes.

reset_stats.sql (admin permission)

  • Resets pg_stats statistics tables.

table_settings.sql (read permission)

  • Returns the table-specific settings of each table.

table_size.sql (read permission)

  • Returns the size of each table in bytes.
  • Does not include size of the tables' indices.

table_size_with_indices.sql (read permission)

  • Returns size of each table in bytes including all indices.

toast_size.sql (read permission)

  • Returns total size of all TOAST data in each table in bytes.

unused_indices.sql (read permission)

  • Returns indices that are rarely used.
  • Note that sometimes the query optimizer will elect to avoid using indices for tables with a very small number of rows because it can be more efficient.

vacuum_stats.sql (read permission)

  • Returns autovacuum stats for each table.

Contributing

Pull requests for bug fixes, improvements, or new SQL are always welcome!

More Repositories

1

generate-changelog

Generate a changelog from git commits.
JavaScript
543
star
2

lambda-pdftk-example

Example project that runs PDFtk in AWS Lambda
JavaScript
100
star
3

lob-ruby

Ruby Wrapper for Lob API
Ruby
97
star
4

lob-node

Node.js Wrapper for Lob API
JavaScript
84
star
5

lob-python

Python Wrapper for Lob API
Python
79
star
6

lob-php

PHP Client for Lob API
PHP
67
star
7

hapi-bookshelf-models

NO LONGER SUPPORTED
JavaScript
35
star
8

litmus

Data schema validation in Elixir
Elixir
34
star
9

examples

HTML Examples for use with Lob Print & Mail APIs
HTML
22
star
10

intern-interviews

HTML
21
star
11

lob-java

Java Wrapper for Lob API
Java
19
star
12

ui-components

Lob's Vue component library
Vue
17
star
13

hapi-rate-limiter

JavaScript
16
star
14

lob-elixir

Elixir Library for Lob API
Elixir
15
star
15

aws-creds

CLI tool to authenticate with Okta as the IdP to fetch AWS credentials
Go
12
star
16

lob-typescript-sdk

TypeScript
10
star
17

lob-openapi

OpenAPI v3 spec for Lob API
JavaScript
8
star
18

nomad-autoscaler-cloudwatch-apm

Nomad Autoscaler APM Plugin for AWS Cloudwatch
Go
7
star
19

react-address-autocomplete

React Autocomplete component for Lob Address Autocomplete
JavaScript
6
star
20

usps-webtools-api

Open source documentation for USPS Web Tools API
JavaScript
6
star
21

pdffonts

Node bindings for Poppler's pdffonts CLI
JavaScript
4
star
22

lob-address-elements

A JavaScript library that adds address autocompletion and verification to a standard HTML Web form.
JavaScript
4
star
23

medusa-next-address-autocomplete

Next starter project for MedusaJS and Lob Address Autocomplete
JavaScript
3
star
24

action_sam_jackson

Respond to comments/issues with a message and a gif of Samuel L. Jackson
JavaScript
3
star
25

fluent-plugin-json-transform

A plugin for doing arbitrary transformation on input JSON.
Ruby
3
star
26

address-elements

JavaScript
3
star
27

lob-go

Go wrapper for Lob API
Go
3
star
28

hapi-bookshelf-total-count

Hapi plugin used with Bookshelf models to calculate the total number of records that match a query and appends it to the response
JavaScript
3
star
29

react-lob-address-autocomplete

JavaScript
1
star
30

vue-address-autocomplete

JavaScript
1
star
31

pdf-wrapper-template

A template for the pdf-wrapper interview question
TypeScript
1
star
32

lob-node-examples

JavaScript
1
star
33

typed

CLI tool for typescript tasks & migrations
Python
1
star
34

lob-dotnet

.NET Wrapper for Lob API
C#
1
star