All Projects → petergeoghegan → Pg_query_internals

petergeoghegan / Pg_query_internals

Licence: other
Query PostgreSQL internals using SQL

Labels

Projects that are alternatives of or similar to Pg query internals

Plpgsql check
plpgsql_check is linter tool for language PL/pgSQL (native language for PostgreSQL store procedures).
Stars: ✭ 322 (+1794.12%)
Mutual labels:  plpgsql
Audit Trigger
Simple, easily customised trigger-based auditing for PostgreSQL (Postgres). See also pgaudit.
Stars: ✭ 493 (+2800%)
Mutual labels:  plpgsql
Mysql Sys
The MySQL sys schema
Stars: ✭ 758 (+4358.82%)
Mutual labels:  plpgsql
100daysofiac
100 Days of IaC in Azure
Stars: ✭ 347 (+1941.18%)
Mutual labels:  plpgsql
Vector Datasource
Tilezen vector tile service - OpenStreetMap data in several formats
Stars: ✭ 427 (+2411.76%)
Mutual labels:  plpgsql
Pgtap
PostgreSQL Unit Testing Suite
Stars: ✭ 631 (+3611.76%)
Mutual labels:  plpgsql
Postgres Json Schema
JSON Schema validation for PostgreSQL
Stars: ✭ 319 (+1776.47%)
Mutual labels:  plpgsql
Odata V4 Typeorm
OData to TYPEORM query compiler
Stars: ✭ 16 (-5.88%)
Mutual labels:  plpgsql
Mixerp
Open Source ERP, HRM, MRP, MPS
Stars: ✭ 472 (+2676.47%)
Mutual labels:  plpgsql
Demo
“Happy Lager” Craft CMS demo site.
Stars: ✭ 730 (+4194.12%)
Mutual labels:  plpgsql
103976
103976个英语单词库(sql版,csv版,Excel版)包含英文单词,中文翻译,单词的词性及多种词义,执行SQL语句就可以生成表,支持SQL Server,MySQL等多种数据库
Stars: ✭ 361 (+2023.53%)
Mutual labels:  plpgsql
Pg Shortkey
YouTube-like Short IDs as Postgres Primary Keys
Stars: ✭ 402 (+2264.71%)
Mutual labels:  plpgsql
Postgrest Starter Kit
Starter Kit and tooling for authoring REST API backends with PostgREST
Stars: ✭ 657 (+3764.71%)
Mutual labels:  plpgsql
Hioshop Server
海风小店,开源商城,微信小程序商城服务器端
Stars: ✭ 331 (+1847.06%)
Mutual labels:  plpgsql
Mysql Deadlocks
收集一些常见的 MySQL 死锁案例
Stars: ✭ 777 (+4470.59%)
Mutual labels:  plpgsql
Cgasm
We're insanely passionate about command line asm documentation in the cloud, and we're crushing it!
Stars: ✭ 321 (+1788.24%)
Mutual labels:  plpgsql
Node Sqlite3
Asynchronous, non-blocking SQLite3 bindings for Node.js
Stars: ✭ 5,083 (+29800%)
Mutual labels:  plpgsql
Pg Mask
Simple data masking for PostgreSQL
Stars: ✭ 16 (-5.88%)
Mutual labels:  plpgsql
Chinook Database
Sample database for SQL Server, Oracle, MySQL, PostgreSQL, SQLite, DB2
Stars: ✭ 786 (+4523.53%)
Mutual labels:  plpgsql
Blog
Everything about database,business.(Most for PostgreSQL).
Stars: ✭ 6,330 (+37135.29%)
Mutual labels:  plpgsql

pg_query_internals: Query PostgreSQL internals using SQL

Current version: 0.2

Author: Peter Geoghegan <[email protected]>

License: PostgreSQL license

Minimum supported version: PostgreSQL 9.5 (most things work on earlier versions, though)

Requires: contrib/pageinspect, contrib/pg_buffercache

Overview

pg_query_internals is a collection of SQL queries that are useful for inspecting the state of a PostgreSQL database. SQL queries for querying the contents of the buffer cache are provided, as well as for querying the structure of a given B-Tree index, and how the index is cached.

These queries are published for educational purposes only; they are not designed for production use. These queries may have some hard-coded assumptions about the underlying data being queried, although that is generally directly noted in comments. While the queries may be useful as a starting point for certain types of low-level investigations, they are generally not usable as instrumentation to find issues in production systems.

In short, the SQL queries are written for those with a specific interest in PostgreSQL internals, and in particular the internals of the B-Tree access method and PostgreSQL buffer manager.

Usage

The SQL queries within pg_query_internals.sql are intended to be run on an ad-hoc basis. The queries are deliberatly not packaged as functions within an extension.

Graphviz

The SQL query within graphviz-query.sql can be used to generate a graph of a PostgreSQL B-Tree using graphviz. The bash script generate-btree-graph.sh gives an example of how this can be coordinated and managed.

This is based on a much earlier approach by Heikki Linnakangas.

Other resources

For those that wish to learn more about PostgreSQL B-Tree indexes, the following resources are suggested:

  • The blogpost "Discovering the Computer Science Behind Postgres Indexes", by Pat Shaughnessy:

http://patshaughnessy.net/2014/11/11/discovering-the-computer-science-behind-postgres-indexes

Good high-level overview.

  • The PostgreSQL nbtree README.

The authoritative source of information on PostgreSQL B-Tree indexes.

  • The paper "A symmetric concurrent B-tree algorithm", from Lanin & Shasha.

This is the paper that the PostgreSQL page deletion (and page recycling) algorithm is based on. Although this isn't the original Lehman & Yao B-Tree paper that first described the optimistic technique used to avoid "crabbing" of buffer locks (these locks are sometimes called "latches" in the literature), it is the more useful resource in my opinion. Note that the algorithm is implemented in a slightly different manner in PostgreSQL, though the differences that are directly noted in the nbtree README.

Lanin & Shasha's paper is of far more practical use to implementers, who may consider skipping the Lehman & Yao paper entirely. For example, it specifically takes issue with a strange tacit assumption made by the Lehman & Yao paper: the assumption that page reads and writes are always atomic. This assumption justifies the Lehman & Yao contention that their algorithm requires no locks during index scans. This claim is rather a lot stronger than the claim that only one lock is required at a time during a descent of the B-Tree, which is all that PostgreSQL manages, and all that Lanin & Shasha see fit to claim for their enhanced algorithm.

The Lanin & Shasha paper actually describes a practical deletion algorithm, rather than assuming that in general page deletion can happen during a period in which the system is offline, as Lehman & Yao rather fancifully suggest. Since all practical requirements are met at once, the Lanin & Shasha design is a truly comprehensive guide to implementing a real-world, high concurrency B-Tree structure.

  • "The Internals of PostgreSQL" website:

http://www.interdb.jp/pg/index.html

This website is a good general starting point for learning about PostgreSQL internals more generally.

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].