Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amenzhinsky/postgresql-partitioning-scripts
PostgreSQL Partitioning Scripts
https://github.com/amenzhinsky/postgresql-partitioning-scripts
bash postgresql sql
Last synced: 2 days ago
JSON representation
PostgreSQL Partitioning Scripts
- Host: GitHub
- URL: https://github.com/amenzhinsky/postgresql-partitioning-scripts
- Owner: amenzhinsky
- Created: 2018-11-18T11:08:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-12T17:46:37.000Z (3 days ago)
- Last Synced: 2024-11-12T18:36:01.819Z (3 days ago)
- Topics: bash, postgresql, sql
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 6
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PostgreSQL Partitioning Scripts
Set of scripts that may help to automate PostgreSQL partitioning routines. All of them generate SQL code so inspect it thoroughly first before executing.
## partition-table-monthly.bash
Partitions an existing table into a set of child tables for each month beginning with the oldest record (can be overwritten with `FROM` environment variable) and up to the current month, it also creates the default partition table for rows that may violate partition checks in the future.
It requires some free space at least of the same size as the partitioned table for copying the existing data to new tables.
The script ensures the lowest down-time by copying data without locking the source table assuming there will be no updates/deletes but inserts. Then it acquire an exclusive lock, copy remaining rows and makes table names switch renaming the old one to `table_name_old` for manual removal.
```bash
./partition-table-monthly.bash mydatabase orders created_at | psql
```## create-monthly-partition.bash
Creates a partition for the previously partitioned table for the upcoming month.
```bash
./create-monthly-partition.bash orders created_at | psql
```You may also control the current date with `DATE=2018-01-01` environment variable if you need to go back or forward in time..