All Projects → idlesign → pg_analyse

idlesign / pg_analyse

Licence: BSD-3-Clause license
Tools to gather useful information from PostgreSQL

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to pg analyse

flvAnalyser
FLV v1.0 analyser
Stars: ✭ 76 (+300%)
Mutual labels:  analyser
lints
Lint all your JavaScript, CSS, HTML, Markdown and Dockerfiles with a single command
Stars: ✭ 14 (-26.32%)
Mutual labels:  analyser
audio-tag-analyzer
Extracts metadata music metadata found in audio files
Stars: ✭ 18 (-5.26%)
Mutual labels:  analyser
Storm
Simple and powerful toolkit for BoltDB
Stars: ✭ 1,814 (+9447.37%)
Mutual labels:  indexes
pg reindex
Console utility for gracefully rebuild indexes/pkeys for PostgreSQL, with minimal locking in semi-auto mode.
Stars: ✭ 20 (+5.26%)
Mutual labels:  indexes
go-mongo-indexer
CLI tool to manage mongo database collection indexes through json files
Stars: ✭ 24 (+26.32%)
Mutual labels:  indexes

pg_analyse

https://github.com/idlesign/pg_analyse

release lic ci coverage

https://github.com/idlesign/pg_analyse/blob/master/pg_analyse_cli.gif

Description

Tools to gather useful information from PostgreSQL

This package can function both as Python module and as a command line utility. Command line interface can show gathered information in the form of tables or JSON.

Use it to gather information manually or in Continuous Integration.

Can give you some information on:

  • Index health (bloat, duplicates, unused, etc.);
  • Tables missing PKs and indexes;
  • Slowest queries.

Note

SQLs used for inspections are available in https://github.com/mfvanek/pg-index-health-sql

Requirements

  • Python 3.6+
  • psycopg 2

Installation

; If you do not have psycopg2 yet, install it as `psycopg2` or `psycopg2-binary`.
; You may also want to install `envbox` to get PG connection settings from .env files.
; Your distribution may require issuing `pip3` command instead of plain `pip`.
$ pip install psycopg2-binary envbox

; If you want to use it just as Python module:
$ pip install pg_analyse

; If you want to use it from command line:
$ pip install pg_analyse[cli]

Usage

Hint

One can set PG_ANALYSE_DSN environment variable instead of explicitly passing DSN to connect to PostgreSQL. If envbox is installed this variable can be defined in .env file .

Python module

from pg_analyse.toolbox import Analyser, analyse_and_format

analyser = Analyser(dsn='user=test')

inspections = analyser.run()
inspection = inspections[0]

print(inspection.alias)
print(inspection.result)

# Shortcut function is available:
out = analyse_and_format()

CLI

; Show known inspections and descriptions:
$ pg_analyse inspections

; Use DSN from the environment variable (see hint above),
; print out complex values (e.g. sizes) in human-friendly way:
$ pg_analyse run --human

; Run certain inspections, override default params.
; Use "common" keyword to pass params common for all inspections.
$ pg_analyse run --one idx_unused --one idx_bloat --args "idx_bloat:schema=my,bloat_min=20;common:schema=my"

; Use explicitly passed DSN:
$ pg_analyse run --dsn "host=myhost.net port=6432 user=test password=xxx sslmode=verify-full sslrootcert=/home/my.pem"
; Local connection as `postgres` user with password:
$ pg_analyse run --dsn "host=127.0.0.1 user=postgres password=yourpass"

; Output analysis result as json (instead of tables):
$ pg_analyse run --fmt json

Adding Inspections

To add a new inspection to pg_analyse:

  1. Compose SQL for inspection and put it into a file under sql/ directory.
  2. Add a subclass of Inspection into inspections/bundled.py. Fill in alias, sql_name attributes (see docstrings in Inspection).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].