Django partitioning is a package for Django, which implement PostgreSQL table partitioning on the fly, at the database level. It creates several triggers and functions and inserts them directly into the database. After setup partitioning, record will be inserted into the correct partition, if partition doesn't exist, it will be created for you automatically.
- Django >=1.11 <=5.0
- PostgreSQL >= 8.0
Also, note psycopg2-binary (2.7.5-2.9.9) will be needed as PostgreSQL database adapter.
Install using pip
...
$ pip install django-postgresql-partitioning
- Add
partitioning
toINSTALLED_APPS
:
INSTALLED_APPS = [
...
partitioning,
]
- Add partitioning configuration to your models:
from partitioning.decorators import partitioning
@partitioning([
{'type': 'list', 'column': 'tag'},
{'type': 'range_month', 'column': 'created'},
])
class Message(models.Model):
text = models.TextField()
tag = models.CharField(max_length=255)
created = models.DateTimeField()
- Lastly setup partitioning:
$ python manage.py setup_partitioning app_name
type
- partition type, currently supported:
- list
- range_day
- range_week
- range_month
- range_year
column
- column, used to determine which partition record belongs to.
Clone the repo:
$ git clone https://github.com/starnavi-team/django-postgresql-partitioning.git
Install requirements.
$ pip install -r requirements.txt
Use tox testing tool to run the tests against all supported versions of Python and Django. Install tox globally, and then simply run:
$ tox