SlideShare a Scribd company logo
With great data(bases) comes
great responsibility
Large table
partitioning with
PostgreSQL and
Django
Paolo Romolini, Caterina Magini
8 December 2020 - Postgres Build 2020
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.3
• Physicist and major science and technology enthusiast
• In 2ndQuadrant from 2018 to 2020 as DBA and Support Engineer
• Now in EDB
About us
• Web developer
• Python and Django enthusiast
• Customer Portal developer
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.4
Summary
• Our use case
• The problem
• Declarative partitioning as possible solution
• The adopted solution
Our use case
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.6
• Facilitate support engineers and
customers job
• Independent management of
companies and users
• Software and repositories
management
• Knowledge base
• Support Ticketing System
The Customer Portal
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.7
• Open source
• Dry principle
• MVT logic
• Excellent documentation
• Django REST Framework
Django
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.8
• Django.contrib.postgres
• JsonB and Array Fields
• Full Text Search
• PostgreSQL specific model indexes
• The Django Project uses it
• https://github.com/django/djangoproject.com
PostgreSQL and Django
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.9
Triggered by ticket events
• Pushover notifications
• Mattermost chats
• Emails
The notifications system
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.10
class EmailMessage(models.Model):
subject = models.CharField(max_length=1024)
to_recipients = ArrayField(models.CharField(max_length=256))
message = models.TextField()
from_email = models.CharField(max_length=256)
metadata = models.JSONField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True, null=True)
[...]
The Email Messages app model
The problem
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.12
• The table was growing too much
• It needed maintenance
Working in DevOps helps!
The Database Table is too large!
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.13
• When an application gets deployed to production early on the performance is great
• After a while, the database starts to get bigger and queries slow down...
• ...and at a certain point, you realize the data is the bottleneck
Table partitioning is a good solution
The DBA’s opinion
A typical scenario
Declarative
partitioning as
possible
solution
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.15
Declarative partitioning in PostgreSQL
Horizontal partitioning: technique for the vertical scalability of a database
Before PostgreSQL 10 From PostgreSQL 10
• Early “partitioning” introduced in
PostgreSQL 8.1
• Heavily based on relation inheritance
• Constraints to define the partitions,
rules and trigger to route data
• Required a lot of maintenance
• Declarative partitioning
• Simplified syntax
• Partitioned tables = new type of
relationship
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.16
The partitioning evolution in PostgreSQL
<=PG 9.6 PG 10 PG 11 PG 12 PG 13
Table inheritance Declarative table
partitioning syntax
Hash partition Partition pruning
enhancements
Partition wise join
enhancements
CHECK constraints Support indexes on
partitions tables
Foreign Keys to
reference
partitioned tables
Partition pruning
improvements
Triggers FOR EACH ROW
Trigger for
partitioned tables
Faster COPY for
partitioned tables
Before ROW-LEVEL
trigger
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.17
● Divide et impera
○ Smaller tables, smaller indexes
● Easier maintenance
● Healthier delete operations and bulk loads
○ Remove a table is faster than removing a lot of records
● Overall performance gains
○ Impact of seqscans
Why partitioning?
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.18
• RANGE
• LIST
• HASH
Partitioning can also be multi-level
Partitioning strategies
Supported partitioning methods:
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.19
Multi-level partitioning
Courtesy of Muhammad Haroon (https://www.2ndquadrant.com/en/blog/scaling-iot-time-series-data-postgres-bdr/)
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.20
CREATE TABLE email_messages (
id serial NOT NULL,
subject varchar(1024) NOT NULL,
message text NOT NULL,
from_email varchar(256) NOT NULL,
html_message text NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NULL,
...
send_to_multiple_recipients boolean NULL,
PRIMARY KEY (id, created_at)
) PARTITION BY RANGE (created_at);
How does it work?
Partitioned table
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.21
CREATE TABLE email_messages_2020_11 PARTITION OF email_messages
FOR VALUES FROM (‘2020-11-01 01:00:00+01’) TO (‘2020-12-01 01:00:00+01’)
CREATE TABLE email_messages_2020_11 PARTITION OF email_messages
FOR VALUES FROM (‘2020-11-01 01:00:00+01’) TO (‘2020-12-01 01:00:00+01’)
How does it work?
Partitions
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.22
The list of columns or expressions that define the partitions bound:
• Range
Can have more > 1 column
• Hash
• List Can have only 1 column/expression
The partitioning key
PARTITION BY {RANGE | LIST | HASH}
({ column_name | (expression )} [ COLLATE collation ] [ opclass ] [,...])
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.23
Indexes, Primary Keys and Foreign Keys support
● CREATE INDEX on partitioned tables locally-partitioned indexes
● Support for UNIQUE and PRIMARY KEY constraints
○ Partition key has to be part of the PRIMARY KEY
● FOREIGN KEYs
○ Partitioned tables can REFERENCE other tables
○ Partitioned tables can be REFERENCED by other tables
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.24
Testing the procedure in QA
Once we understood that partitioning could be the solution, we just had to test it.
• QA environment with PostgreSQL 10
• Large table referenced by another table
• Can’t turn a not partitioned in table into a partitioned one → New table
• Most of the data in the old table are historical, no need to migrate them immediately
• LOCK the old table during the deploy
• Simulate traffic… and check that everything is OK
Needs to upgrade to PG 12
The adopted
solution
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.26
No support for table partitioning in Django
• Third-party django applications?
• Executing SQL query without Django?
Which way to take?
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.27
• PostgreSQL declarative partitioning is transparent to Django
• Doing it using Django tools
Django migrations!
The way we have chosen
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.28
• A way to track django models changes
• They are applied against the database
• You can revert them
Django migrations
$ python manage.py showmigrations email_messages
email_messages
[X] 0001_initial
[X] 0002_auto_20200716_0837
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.29
Specify a different table name
class EmailMessage(models.Model):
[...]
created_at = models.DateTimeField(auto_now_add=True, null=True)
class Meta:
db_table = “email_messages”
Django default database table names:
"%s_%s" % (self.app_label, self.model_name)
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.30
Django migrations with custom SQL
class Migration(migrations.Migration):
[...]
operations = [
migrations.RunSQL(
sql=[(PARTITIONED_TABLES_SQL],
reverse_sql=[DROP_PARTITONED_TABLES_SQL],
)
]
Run the sqlmigrate command
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.31
The partition key of the Django migration
PARTITIONED_TABLES_SQL = """
CREATE TABLE "email_messages" (
"id" serial NOT NULL PRIMARY KEY,
[...]
) PARTITION BY RANGE
(created_at);
"""
PARTITIONED_TABLES_SQL = """
CREATE TABLE "email_messages" (
"id" serial NOT NULL,
[...]
PRIMARY KEY (id, created_at)
) PARTITION BY RANGE
(created_at);
"""
→
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.32
Create the partitions with Django
• Create a new django management command
• Schedule the command as a cron job
• Add another django migration
We are ready to test it in QA!
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.33
Deployment in production
• The deployment ran smoothly
• The old table was attached to the new partition
Success!
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.34
Conclusion
• The declarative PostgreSQL partitions is good
• Django is a great framework
• DevOps
• That’s one way to do it, not the way!
Follow us:
https://www.linkedin.com/in/paoloromolini/
https://www.linkedin.com/in/caterina-magini/
Tweet:
#PostgresBuild2020
#PostgreSQL
#Django

More Related Content

What's hot

PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
Reuven Lerner
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
PgDay.Seoul
 
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
PgDay.Seoul
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報
Masahiko Sawada
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
Alexander Korotkov
 
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
Mydbops
 
MySQLで論理削除と正しく付き合う方法
MySQLで論理削除と正しく付き合う方法MySQLで論理削除と正しく付き合う方法
MySQLで論理削除と正しく付き合う方法
yoku0825
 
PostgreSQL運用管理入門
PostgreSQL運用管理入門PostgreSQL運用管理入門
PostgreSQL運用管理入門
Yoshiyuki Asaba
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
PgDay.Seoul
 
SQLチューニング入門 入門編
SQLチューニング入門 入門編SQLチューニング入門 入門編
SQLチューニング入門 入門編Miki Shimogai
 
カスタムプランと汎用プラン
カスタムプランと汎用プランカスタムプランと汎用プラン
カスタムプランと汎用プラン
Masao Fujii
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
Mydbops
 
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
PgDay.Seoul
 
使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan
NTT DATA OSS Professional Services
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
NTT DATA Technology & Innovation
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
Oddbjørn Steffensen
 
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
PgDay.Seoul
 
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみpg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
Masahiko Sawada
 

What's hot (20)

PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
 
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
 
MySQLで論理削除と正しく付き合う方法
MySQLで論理削除と正しく付き合う方法MySQLで論理削除と正しく付き合う方法
MySQLで論理削除と正しく付き合う方法
 
PostgreSQL運用管理入門
PostgreSQL運用管理入門PostgreSQL運用管理入門
PostgreSQL運用管理入門
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
SQLチューニング入門 入門編
SQLチューニング入門 入門編SQLチューニング入門 入門編
SQLチューニング入門 入門編
 
カスタムプランと汎用プラン
カスタムプランと汎用プランカスタムプランと汎用プラン
カスタムプランと汎用プラン
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
 
使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan使ってみませんか?pg_hint_plan
使ってみませんか?pg_hint_plan
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
 
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
 
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみpg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
 

Similar to Large Table Partitioning with PostgreSQL and Django

New and Improved Features in PostgreSQL 13
New and Improved Features in PostgreSQL 13New and Improved Features in PostgreSQL 13
New and Improved Features in PostgreSQL 13
EDB
 
PostgreSQL 13 is Coming - Find Out What's New!
PostgreSQL 13 is Coming - Find Out What's New!PostgreSQL 13 is Coming - Find Out What's New!
PostgreSQL 13 is Coming - Find Out What's New!
EDB
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
Jimmy Angelakos
 
EDB & ELOS Technologies - Break Free from Oracle
EDB & ELOS Technologies - Break Free from OracleEDB & ELOS Technologies - Break Free from Oracle
EDB & ELOS Technologies - Break Free from Oracle
EDB
 
PostgreSQL as a Strategic Tool
PostgreSQL as a Strategic ToolPostgreSQL as a Strategic Tool
PostgreSQL as a Strategic Tool
EDB
 
EDB: Power to Postgres
EDB: Power to PostgresEDB: Power to Postgres
EDB: Power to Postgres
Ashnikbiz
 
Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2
Ashnikbiz
 
Szabaduljon ki az Oracle szorításából
Szabaduljon ki az Oracle szorításábólSzabaduljon ki az Oracle szorításából
Szabaduljon ki az Oracle szorításából
EDB
 
Managing Data in Jakarta EE Applications
Managing Data in Jakarta EE ApplicationsManaging Data in Jakarta EE Applications
Managing Data in Jakarta EE Applications
Buhake Sindi
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
EDB
 
Break Free from Oracle
Break Free from OracleBreak Free from Oracle
Break Free from Oracle
EDB
 
Expert Guide to Migrating Legacy Databases to Postgres
Expert Guide to Migrating Legacy Databases to PostgresExpert Guide to Migrating Legacy Databases to Postgres
Expert Guide to Migrating Legacy Databases to Postgres
EDB
 
Google BigQuery
Google BigQueryGoogle BigQuery
Google BigQuery
Matthias Feys
 
Un guide complet pour la migration de bases de données héritées vers PostgreSQL
Un guide complet pour la migration de bases de données héritées vers PostgreSQLUn guide complet pour la migration de bases de données héritées vers PostgreSQL
Un guide complet pour la migration de bases de données héritées vers PostgreSQL
EDB
 
Replacing Oracle with EDB Postgres
Replacing Oracle with EDB PostgresReplacing Oracle with EDB Postgres
Replacing Oracle with EDB Postgres
EDB
 
An Expert Guide to Migrating Legacy Databases to PostgreSQL
An Expert Guide to Migrating Legacy Databases to PostgreSQLAn Expert Guide to Migrating Legacy Databases to PostgreSQL
An Expert Guide to Migrating Legacy Databases to PostgreSQL
EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
EDB
 
PostgreSQL as a Strategic Tool
PostgreSQL as a Strategic ToolPostgreSQL as a Strategic Tool
PostgreSQL as a Strategic Tool
EDB
 
DBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptxDBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptx
Hong Ong
 

Similar to Large Table Partitioning with PostgreSQL and Django (20)

New and Improved Features in PostgreSQL 13
New and Improved Features in PostgreSQL 13New and Improved Features in PostgreSQL 13
New and Improved Features in PostgreSQL 13
 
PostgreSQL 13 is Coming - Find Out What's New!
PostgreSQL 13 is Coming - Find Out What's New!PostgreSQL 13 is Coming - Find Out What's New!
PostgreSQL 13 is Coming - Find Out What's New!
 
Practical Partitioning in Production with Postgres
Practical Partitioning in Production with PostgresPractical Partitioning in Production with Postgres
Practical Partitioning in Production with Postgres
 
EDB & ELOS Technologies - Break Free from Oracle
EDB & ELOS Technologies - Break Free from OracleEDB & ELOS Technologies - Break Free from Oracle
EDB & ELOS Technologies - Break Free from Oracle
 
PostgreSQL as a Strategic Tool
PostgreSQL as a Strategic ToolPostgreSQL as a Strategic Tool
PostgreSQL as a Strategic Tool
 
EDB: Power to Postgres
EDB: Power to PostgresEDB: Power to Postgres
EDB: Power to Postgres
 
Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2
 
Szabaduljon ki az Oracle szorításából
Szabaduljon ki az Oracle szorításábólSzabaduljon ki az Oracle szorításából
Szabaduljon ki az Oracle szorításából
 
Managing Data in Jakarta EE Applications
Managing Data in Jakarta EE ApplicationsManaging Data in Jakarta EE Applications
Managing Data in Jakarta EE Applications
 
Oracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration HustleOracle to Postgres Schema Migration Hustle
Oracle to Postgres Schema Migration Hustle
 
Break Free from Oracle
Break Free from OracleBreak Free from Oracle
Break Free from Oracle
 
Expert Guide to Migrating Legacy Databases to Postgres
Expert Guide to Migrating Legacy Databases to PostgresExpert Guide to Migrating Legacy Databases to Postgres
Expert Guide to Migrating Legacy Databases to Postgres
 
Google BigQuery
Google BigQueryGoogle BigQuery
Google BigQuery
 
Un guide complet pour la migration de bases de données héritées vers PostgreSQL
Un guide complet pour la migration de bases de données héritées vers PostgreSQLUn guide complet pour la migration de bases de données héritées vers PostgreSQL
Un guide complet pour la migration de bases de données héritées vers PostgreSQL
 
Replacing Oracle with EDB Postgres
Replacing Oracle with EDB PostgresReplacing Oracle with EDB Postgres
Replacing Oracle with EDB Postgres
 
An Expert Guide to Migrating Legacy Databases to PostgreSQL
An Expert Guide to Migrating Legacy Databases to PostgreSQLAn Expert Guide to Migrating Legacy Databases to PostgreSQL
An Expert Guide to Migrating Legacy Databases to PostgreSQL
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJEDB 13 - New Enhancements for Security and Usability - APJ
EDB 13 - New Enhancements for Security and Usability - APJ
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
 
PostgreSQL as a Strategic Tool
PostgreSQL as a Strategic ToolPostgreSQL as a Strategic Tool
PostgreSQL as a Strategic Tool
 
DBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptxDBT ELT approach for Advanced Analytics.pptx
DBT ELT approach for Advanced Analytics.pptx
 

More from EDB

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube
EDB
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021
EDB
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQL
EDB
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQL
EDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
EDB
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQL
EDB
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
EDB
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQL
EDB
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
EDB
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!
EDB
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos données
EDB
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - Italiano
EDB
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
EDB
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
EDB
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJ
EDB
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
EDB
 
EDB Postgres & Tools in a Smart City Project
EDB Postgres & Tools in a Smart City ProjectEDB Postgres & Tools in a Smart City Project
EDB Postgres & Tools in a Smart City Project
EDB
 

More from EDB (20)

Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaSCloud Migration Paths: Kubernetes, IaaS, or DBaaS
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr UnternehmenDie 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube Migre sus bases de datos Oracle a la nube
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021EFM Office Hours - APJ - July 29, 2021
EFM Office Hours - APJ - July 29, 2021
 
Benchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQLBenchmarking Cloud Native PostgreSQL
Benchmarking Cloud Native PostgreSQL
 
Las Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQLLas Variaciones de la Replicación de PostgreSQL
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?Is There Anything PgBouncer Can’t Do?
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQLData Analysis with TensorFlow in PostgreSQL
Data Analysis with TensorFlow in PostgreSQL
 
A Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAINA Deeper Dive into EXPLAIN
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
IOT with PostgreSQLIOT with PostgreSQL
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
Psql is awesome!Psql is awesome!
Psql is awesome!
 
Comment sauvegarder correctement vos données
Comment sauvegarder correctement vos donnéesComment sauvegarder correctement vos données
Comment sauvegarder correctement vos données
 
Cloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - ItalianoCloud Native PostgreSQL - Italiano
Cloud Native PostgreSQL - Italiano
 
New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13New enhancements for security and usability in EDB 13
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJCloud Native PostgreSQL - APJ
Cloud Native PostgreSQL - APJ
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
EDB Postgres & Tools in a Smart City Project
EDB Postgres & Tools in a Smart City ProjectEDB Postgres & Tools in a Smart City Project
EDB Postgres & Tools in a Smart City Project
 

Recently uploaded

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 

Recently uploaded (20)

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 

Large Table Partitioning with PostgreSQL and Django

  • 1. With great data(bases) comes great responsibility
  • 2. Large table partitioning with PostgreSQL and Django Paolo Romolini, Caterina Magini 8 December 2020 - Postgres Build 2020
  • 3. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.3 • Physicist and major science and technology enthusiast • In 2ndQuadrant from 2018 to 2020 as DBA and Support Engineer • Now in EDB About us • Web developer • Python and Django enthusiast • Customer Portal developer
  • 4. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.4 Summary • Our use case • The problem • Declarative partitioning as possible solution • The adopted solution
  • 6. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.6 • Facilitate support engineers and customers job • Independent management of companies and users • Software and repositories management • Knowledge base • Support Ticketing System The Customer Portal
  • 7. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.7 • Open source • Dry principle • MVT logic • Excellent documentation • Django REST Framework Django
  • 8. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.8 • Django.contrib.postgres • JsonB and Array Fields • Full Text Search • PostgreSQL specific model indexes • The Django Project uses it • https://github.com/django/djangoproject.com PostgreSQL and Django
  • 9. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.9 Triggered by ticket events • Pushover notifications • Mattermost chats • Emails The notifications system
  • 10. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.10 class EmailMessage(models.Model): subject = models.CharField(max_length=1024) to_recipients = ArrayField(models.CharField(max_length=256)) message = models.TextField() from_email = models.CharField(max_length=256) metadata = models.JSONField(null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True, null=True) [...] The Email Messages app model
  • 12. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.12 • The table was growing too much • It needed maintenance Working in DevOps helps! The Database Table is too large!
  • 13. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.13 • When an application gets deployed to production early on the performance is great • After a while, the database starts to get bigger and queries slow down... • ...and at a certain point, you realize the data is the bottleneck Table partitioning is a good solution The DBA’s opinion A typical scenario
  • 15. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.15 Declarative partitioning in PostgreSQL Horizontal partitioning: technique for the vertical scalability of a database Before PostgreSQL 10 From PostgreSQL 10 • Early “partitioning” introduced in PostgreSQL 8.1 • Heavily based on relation inheritance • Constraints to define the partitions, rules and trigger to route data • Required a lot of maintenance • Declarative partitioning • Simplified syntax • Partitioned tables = new type of relationship
  • 16. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.16 The partitioning evolution in PostgreSQL <=PG 9.6 PG 10 PG 11 PG 12 PG 13 Table inheritance Declarative table partitioning syntax Hash partition Partition pruning enhancements Partition wise join enhancements CHECK constraints Support indexes on partitions tables Foreign Keys to reference partitioned tables Partition pruning improvements Triggers FOR EACH ROW Trigger for partitioned tables Faster COPY for partitioned tables Before ROW-LEVEL trigger
  • 17. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.17 ● Divide et impera ○ Smaller tables, smaller indexes ● Easier maintenance ● Healthier delete operations and bulk loads ○ Remove a table is faster than removing a lot of records ● Overall performance gains ○ Impact of seqscans Why partitioning?
  • 18. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.18 • RANGE • LIST • HASH Partitioning can also be multi-level Partitioning strategies Supported partitioning methods:
  • 19. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.19 Multi-level partitioning Courtesy of Muhammad Haroon (https://www.2ndquadrant.com/en/blog/scaling-iot-time-series-data-postgres-bdr/)
  • 20. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.20 CREATE TABLE email_messages ( id serial NOT NULL, subject varchar(1024) NOT NULL, message text NOT NULL, from_email varchar(256) NOT NULL, html_message text NULL, created_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NULL, ... send_to_multiple_recipients boolean NULL, PRIMARY KEY (id, created_at) ) PARTITION BY RANGE (created_at); How does it work? Partitioned table
  • 21. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.21 CREATE TABLE email_messages_2020_11 PARTITION OF email_messages FOR VALUES FROM (‘2020-11-01 01:00:00+01’) TO (‘2020-12-01 01:00:00+01’) CREATE TABLE email_messages_2020_11 PARTITION OF email_messages FOR VALUES FROM (‘2020-11-01 01:00:00+01’) TO (‘2020-12-01 01:00:00+01’) How does it work? Partitions
  • 22. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.22 The list of columns or expressions that define the partitions bound: • Range Can have more > 1 column • Hash • List Can have only 1 column/expression The partitioning key PARTITION BY {RANGE | LIST | HASH} ({ column_name | (expression )} [ COLLATE collation ] [ opclass ] [,...])
  • 23. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.23 Indexes, Primary Keys and Foreign Keys support ● CREATE INDEX on partitioned tables locally-partitioned indexes ● Support for UNIQUE and PRIMARY KEY constraints ○ Partition key has to be part of the PRIMARY KEY ● FOREIGN KEYs ○ Partitioned tables can REFERENCE other tables ○ Partitioned tables can be REFERENCED by other tables
  • 24. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.24 Testing the procedure in QA Once we understood that partitioning could be the solution, we just had to test it. • QA environment with PostgreSQL 10 • Large table referenced by another table • Can’t turn a not partitioned in table into a partitioned one → New table • Most of the data in the old table are historical, no need to migrate them immediately • LOCK the old table during the deploy • Simulate traffic… and check that everything is OK Needs to upgrade to PG 12
  • 26. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.26 No support for table partitioning in Django • Third-party django applications? • Executing SQL query without Django? Which way to take?
  • 27. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.27 • PostgreSQL declarative partitioning is transparent to Django • Doing it using Django tools Django migrations! The way we have chosen
  • 28. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.28 • A way to track django models changes • They are applied against the database • You can revert them Django migrations $ python manage.py showmigrations email_messages email_messages [X] 0001_initial [X] 0002_auto_20200716_0837
  • 29. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.29 Specify a different table name class EmailMessage(models.Model): [...] created_at = models.DateTimeField(auto_now_add=True, null=True) class Meta: db_table = “email_messages” Django default database table names: "%s_%s" % (self.app_label, self.model_name)
  • 30. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.30 Django migrations with custom SQL class Migration(migrations.Migration): [...] operations = [ migrations.RunSQL( sql=[(PARTITIONED_TABLES_SQL], reverse_sql=[DROP_PARTITONED_TABLES_SQL], ) ] Run the sqlmigrate command
  • 31. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.31 The partition key of the Django migration PARTITIONED_TABLES_SQL = """ CREATE TABLE "email_messages" ( "id" serial NOT NULL PRIMARY KEY, [...] ) PARTITION BY RANGE (created_at); """ PARTITIONED_TABLES_SQL = """ CREATE TABLE "email_messages" ( "id" serial NOT NULL, [...] PRIMARY KEY (id, created_at) ) PARTITION BY RANGE (created_at); """ →
  • 32. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.32 Create the partitions with Django • Create a new django management command • Schedule the command as a cron job • Add another django migration We are ready to test it in QA!
  • 33. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.33 Deployment in production • The deployment ran smoothly • The old table was attached to the new partition Success!
  • 34. © Copyright EnterpriseDB Corporation, 2020. All rights reserved.34 Conclusion • The declarative PostgreSQL partitions is good • Django is a great framework • DevOps • That’s one way to do it, not the way!