How to migrate an existing Postgres Table to partitioned table as transparently as possible?

In Postgres 10 “Declarative Partitioning” was introduced, which can relieve you of a good deal of work such as generating triggers or rules with huge if/else statements redirecting to the correct table. Postgres can do this automatically now. Let’s start with the migration: Rename the old table and create a new partitioned table alter table … Read more

How do I execute raw SQL in a django migration

One way: The best way I found to do this is using RunSQL: Migrations contains the RunSQL class. To do this: ./manage.py makemigrations –empty myApp edit the created migrations file to include: operations = [ migrations.RunSQL(‘RAW SQL CODE’) ] As Nathaniel Knight mentioned, RunSQL also accepts a reverse_sql parameter for reversing the migration. See the … Read more

Database partitioning – Horizontal vs Vertical – Difference between Normalization and Row Splitting?

Partitioning is a rather general concept and can be applied in many contexts. When it considers the partitioning of relational data, it usually refers to decomposing your tables either row-wise (horizontally) or column-wise (vertically). Vertical partitioning, aka row splitting, uses the same splitting techniques as database normalization, but ususally the term (vertical / horizontal) data … Read more