This repository contains examples and demonstrations of PostgreSQL's declarative partitioning features. It serves as a companion to my blog post on PostgreSQL declarative partitioning.
For a detailed explanation of the concepts demonstrated in this repository, please visit my blog at: https://sohardh.com/blog-post/postgres-declarative-partitioning/
The examples are organized into the following directories:
- 01_range.sql: Examples of RANGE partitioning with queries demonstrating partition pruning
- 02_list.sql: Examples of LIST partitioning
- 03_hash.sql: Examples of HASH partitioning
- 01_subpartitioning.sql: Examples of multi-level partitioning (subpartitioning)
- 02_row_movement.sql: Examples of row movement between partitions
- 01_static_vs_dynamic.sql: Examples demonstrating static vs dynamic partition pruning
This project includes a Docker Compose file to set up a PostgreSQL 18 environment:
docker-compose up -dThe database will be accessible at localhost:5432 with the following credentials:
- Database: partitioning_demo
- Username: postgres
- Password: postgres
You can then run the SQL scripts in the order of the directories to explore the different partitioning techniques.