Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adyen/adyen-postgres-partitioning
Functions to manage partitions in PostgreSQL with minimal impact for applications
https://github.com/adyen/adyen-postgres-partitioning
database database-maintenance database-management foreign-keys functions index partitioning plpgsql plpgsql-function plpgsql-language postgres postgresql sql
Last synced: 28 days ago
JSON representation
Functions to manage partitions in PostgreSQL with minimal impact for applications
- Host: GitHub
- URL: https://github.com/adyen/adyen-postgres-partitioning
- Owner: Adyen
- License: mit
- Created: 2023-05-26T14:22:56.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2023-12-15T05:28:01.000Z (11 months ago)
- Last Synced: 2024-10-11T09:41:55.003Z (28 days ago)
- Topics: database, database-maintenance, database-management, foreign-keys, functions, index, partitioning, plpgsql, plpgsql-function, plpgsql-language, postgres, postgresql, sql
- Language: PLpgSQL
- Homepage:
- Size: 33.2 KB
- Stars: 35
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# adyen-postgres-partitioning
These functions are designed to create and maintain partitions in PostgreSQL with a minimal impact on the applicaton. The priority is to not impact the application. When multiple options are available the weakest lock possible is being used, when a heavy lock is required we use a timeout to prevent long lasting locks.Every function in this project starts with a detailed comment on what the function does and how to use it.
## Contributing
We strongly encourage you to contribute to our repository. Find out more in our [contribution guidelines](https://github.com/Adyen/.github/blob/master/CONTRIBUTING.md)## Requirements
All function have been tested on postgres 13.## Installation
All function will be installed in the DBA schema. If you don't have this schema yet, create it by running sql/schema/schema.sql.You can add the individual functions directly on the database from `psql` with the `\i` command. Use `psql` to login on your database and run
```sql
\i ..sql
```
N.B. Some functions use other functions and the script `partition_maintenance.sql` requires a set of tables to be created.### Install all functions
To create all the functions and the tables required to configure maintenance apply the following scripts in order from the root directory of the project
sql/schema/schema.sql
sql/tables/tables.sql
sql/functions/create_all_functions.sql### Test functions
To test all functions run the following scripts from the project root folder
test/tables.sql
test/run_functions.sql
test/configuration.sql
test/cleanup.sql## Usage
The functions can be called as any other postgres function
```sql
select dba.(arg1, arg2, ..., argN);
```## Documentation
The functions in this project can- Partition an existing table. The origional table will not partitioned itself, but becomes the first partition
- Add indexes to a partitioned table and all children
- Add foreign keys to a partitioned table and all children
- Add date constraints to a table partitioned on an integer column
- Count the number of available, unused partitions
- Get the details for the last partition
- Add new partitions to a partitioned table. The new partitions will have the same properties as the latest available partition
- Detach partitions from a partitioned table
- Drop detached partitionsBesides all the functions the project also contains the script `partition_maintenance.sql`. This scripts requires two tables being created
- dba.partition_configuration
- dba.detached_partitionsThe scripts performs the following tasks based on the configuration in the table `dba.partition_configuration`.
- Add new partitions
- Add date constraints
- Detach partitions
- Drop detached partitions after a cool-down periodSee the documentation within sql/tables/tables.sql for the configuration details.
## Support
If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue.## License
MIT license. For more information, see the LICENSE file.