SlideShare a Scribd company logo
Mastering data organisation:
Deep dive into PostgreSQL table partitioning
Presented by
Mohammad Zaid Patel
Mydbops
Mydbops MyWebinar - 30
Dec 23rd, 2023
About Me
● PostgreSQL Database consultant
● Experienced in PostgreSQL and related DB
technologies
● Active Blogger
● Tech Speaker
● Likes Cricket, Music & Comedy
Consulting
Services
Consulting
Services
Managed
Services
● Database Management and
consultancy provider
● Founded in 2016
● Assisted 800+ happy customers
● AWS partners
● PCI & ISO certified
About Us
● Why data organisation ?
● Advantages of data organisation
● Techniques of data organisation
● Table partitioning in PostgreSQL
● Table partition techniques
● Demo for table partitioning using pg_partman
● Limitations of table partitioning
● Best practices for table partitioning
Agenda
Why data organisation ?
● Databases are used for storing and retrieving data
● Database becomes a black box
● Piled up with un-organised data
● Performance degradation of the database
Why data organization?
● Organization of data is very essential for
the database functionality
● Plays crucial roles in database efficiency
● Assures data integrity
● Improves the usability of the stored data
Why data organization?
Unorganized data
Organized data
Advantages of organizing your data
Advantages of organizing your data
● Better data retrieval
● Improved query performance
● Data integrity
● Efficient storage and resource utilization
● Ease in maintenance
● Ease in scalability of the database
● Data analysis and reporting
Data organization techniques
Data organization techniques
Index creation :
- Creates a data structure that allows quick access to rows based
on specific column values
- Faster data retrieval for conditions involving indexed columns
- Types: B-tree, GIN,Hash indexes etc
Data Archival:
- Process of moving the old data to a different location
- Clean up database
- Helps in managing the data efficiently over time
Data organization techniques
Schemas:
- Collection of database objects organized into a named namespace
- Provides a way to logically group and organize database objects within a
database
- Multiple schemas with each schema having its own set of objects.
Functional naming of database objects:
- Helps in noting the type of database objects e.g. indexes, views ,
sequences etc
- Easier for the users to understand the database structure and work with
the objects more effectively
Data organization techniques
Relationships among database objects:
- Avoids creation of "orphaned" records and maintaining consistency across
related tables.
- Efficient queries that involve data from multiple tables like JOIN
operations
Table partitioning:
- Involves dividing large tables into smaller, more manageable pieces
- Improves query performance, data management, and maintenance tasks
- Data distribution across partitions.
Table Partitioning in PostgreSQL
Table Partitioning in PostgreSQL
● Database design technique that involves dividing large tables into smaller,
more manageable segments called partitions
id Name Cricket club
01 Virat RCB
02 Dhoni CSK
03 Rohit MI
04 Hardik MI
05 Siraj RCB
06 Jadeja CSK
id Name Cricket club
01 Virat RCB
05 Siraj RCB
02 Dhoni CSK
06 Jadeja CSK
03 Rohit MI
04 Hardik MI
Child table-1
Child table-2
Child table-3
Normal Table Partitioned Table
Parent table
● Partition key, determines how data is distributed across partitions
● Efficient data management, especially for operations like data insertion, updates, and
deletions.
● Enhances query performance by allowing the database to selectively scan only
relevant partitions when queries involve conditions on the partition key
● Ease in data archival
Table Partitioning in PostgreSQL
Types of table partitioning in PostgreSQL
Types of table partitioning in PostgreSQL
PostgreSQL supports different partitioning methods including range partitioning , list
partitioning, and hash partitioning.
Range Partitioning:
- Divides a table into partitions based on ranges of values in a chosen partition key
column
- Partitioning by a date column, each partition may represent a specific time period,
such as months or years
Creating a child table :
CREATE TABLE child_table_2022_01_01 PARTITION OF
parent_table
FOR VALUES FROM ('2022-01-01') TO ('2023-02-01');
Types of table partitioning in PostgreSQL
id Username date_of_creation
01 Jake 01-01-2023
05 Ryan 01-01-2023
02 Anne 02-01-2023
06 Austin 02-01-2023
03 Daniel 03-01-2023
04 Taylor 03-01-2023
Child table-1
Child table-2
Child table-3
Range based partitioned table
Types of table partitioning in PostgreSQL
List based Partitioning:
- Divides a table into partitions based on specific values in a chosen partition key
column.
- Rows with values falling within specific ranges of this key are grouped into individual
partitions
Creating a child table :
CREATE TABLE new_york_child_table PARTITION OF parent_table
FOR VALUES IN (‘New York’);
Types of table partitioning in PostgreSQL
id Username City
01 Jake New York
05 Ryan New York
02 Anne Tokyo
06 Austin Tokyo
03 Daniel London
04 Taylor London
Child table-1
Child table-2
Child table-3
List based partitioned table
Types of table partitioning in PostgreSQL
Hash based Partitioning:
- Divides a table into partitions based on the hash value of a chosen partition key
column
- Uniform distribution of data across partitions by using a hash function
Creating a child table :
CREATE TABLE child_table_1 PARTITION OF parent_table FOR
VALUES WITH (MODULUS 3,REMAINDER 0);
Types of table partitioning in PostgreSQL
id Username City
01 Anne New York
05 Taylor Tokyo
02 Jake Tokyo
06 Austin London
03 Daniel London
04 Ryan New York
Child table-1
Child table-2
Child table-3
List based partitioned table
Remainder
value
0001
0001
0002
0002
0003
0003
Partitioning techniques in PostgreSQL
Partitioning techniques in PostgreSQL
1. Manual Partitioning:
- Creating parent tables and child tables manually
- Maintenance of the child tables should be taken care of
E.g
Creating a parent table :
CREATE TABLE parent_table (
id int,date_column DATE, value INTEGER,
CONSTRAINT pkey PRIMARY KEY (id,date_column)
) PARTITION BY RANGE (date_column);
Partitioning techniques in PostgreSQL
E.g
Creating a child table :
CREATE TABLE child_table_2022 PARTITION OF parent_table
FOR VALUES FROM ('2022-01-01') TO ('2023-01-01');
Partitioning techniques in PostgreSQL
2. Partitioning using pg_partman extension:
- Extension designed to create and oversee sets of partitioned tables
- The creation of child tables is fully managed by the extension itself
- The extension includes a background worker (BGW) process to streamline partition
maintenance
- Optional retention policy that can automatically discard partitions that are no longer
necessary
- Maintenance function takes cares of partition management on
timely basis
Partitioning techniques in PostgreSQL
pg_partman extension is required:
demo_db=# dx
List of installed extensions
Name | Version | Schema | Description
------------+---------+------------+---------------------------------
---------------------
pg_partman | 4.7.3 | partman | Extension to manage partitioned
tables by time or ID
Partitioning techniques in PostgreSQL
Creating a parent table :
Creating a child table :
CREATE TABLE parent_table (
id integer ,created_date date,
CONSTRAINT table01_pkey PRIMARY KEY
(id,created_date)
) partition by range(created_date);
SELECT partman.create_parent( p_parent_table =>
'public.parent_table’, p_control => 'created_date',
p_interval=> '1 day', p_premake => 2);
Demo
Limitations of Table partitioning
Limitations of Table partitioning
● Useful only when the partition key is used
● Regular supervision is required for the pg_partman tool for partition management
● Complexities in data migration services
● Complexities in tables with foreign key relationships
● Child tables that are stored as backup needs to be taken care
● Data accumulation in default table fails the pg_partman functions
Best practices for partitioned table maintenance
● Choose the Right Partition Key
● Understand Query Patterns
● Monitor and Tune Performance
● Choose Appropriate Partitioning Method
● Limit the Number of Partitions
● Implement Data Archiving
● Regularly Update PostgreSQL Version
Best practices for partitioned table maintenance
Any Questions ?
Consulting
Services
Consulting
Services
Connect with us !
Reach us at : info@mydbops.com
Thank you!
Ad

Recommended

Tech-Spark: Scaling Databases
Tech-Spark: Scaling Databases
Ralph Attard
 
introduction to big data and data scienece
introduction to big data and data scienece
nehayarrapothu
 
SQLDAY 2023 Chodkowski Adrian Databricks Performance Tuning
SQLDAY 2023 Chodkowski Adrian Databricks Performance Tuning
SeeQuality.net
 
Statistics and Indexes Internals
Statistics and Indexes Internals
Antonios Chatzipavlis
 
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Michael Rys
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql
Łukasz Grala
 
NoSQL - A Closer Look to Couchbase
NoSQL - A Closer Look to Couchbase
Mohammad Shaker
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
rainynovember12
 
JSSUG: SQL Sever Index Tuning
JSSUG: SQL Sever Index Tuning
Kenichiro Nakamura
 
7 - Enterprise IT in Action
7 - Enterprise IT in Action
Raymond Gao
 
Sql server lesson7
Sql server lesson7
Ala Qunaibi
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Query parameterization
Query parameterization
Riteshkiit
 
Microsoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdf
SpiritsoftsTraining
 
SQL Server 2019 Master Data Service
SQL Server 2019 Master Data Service
Kenichiro Nakamura
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
SQLServer Database Structures
SQLServer Database Structures
Antonios Chatzipavlis
 
An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...
eSAT Publishing House
 
An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...
eSAT Journals
 
MySQL Indexing
MySQL Indexing
BADR
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure tools
Pushkar Chivate
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
hemrajpro009
 
Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and Django
EDB
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official Documentation
Databricks
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Scaling TiDB for Large-Scale Application
Scaling TiDB for Large-Scale Application
Mydbops
 
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 

More Related Content

Similar to Data Organisation: Table Partitioning in PostgreSQL (20)

JSSUG: SQL Sever Index Tuning
JSSUG: SQL Sever Index Tuning
Kenichiro Nakamura
 
7 - Enterprise IT in Action
7 - Enterprise IT in Action
Raymond Gao
 
Sql server lesson7
Sql server lesson7
Ala Qunaibi
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Query parameterization
Query parameterization
Riteshkiit
 
Microsoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdf
SpiritsoftsTraining
 
SQL Server 2019 Master Data Service
SQL Server 2019 Master Data Service
Kenichiro Nakamura
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
SQLServer Database Structures
SQLServer Database Structures
Antonios Chatzipavlis
 
An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...
eSAT Publishing House
 
An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...
eSAT Journals
 
MySQL Indexing
MySQL Indexing
BADR
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure tools
Pushkar Chivate
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
hemrajpro009
 
Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and Django
EDB
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official Documentation
Databricks
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
7 - Enterprise IT in Action
7 - Enterprise IT in Action
Raymond Gao
 
Sql server lesson7
Sql server lesson7
Ala Qunaibi
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
Aaron Shilo
 
Query parameterization
Query parameterization
Riteshkiit
 
Microsoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdf
SpiritsoftsTraining
 
SQL Server 2019 Master Data Service
SQL Server 2019 Master Data Service
Kenichiro Nakamura
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
Data warehouse and Data Mining (PEC-IT602B).pptx
Data warehouse and Data Mining (PEC-IT602B).pptx
UtsavChakraborty6
 
An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...
eSAT Publishing House
 
An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...
eSAT Journals
 
MySQL Indexing
MySQL Indexing
BADR
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure tools
Pushkar Chivate
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
 
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
1702272914_Introducing_MongoDB_Limit_projection_sorting.pptx
hemrajpro009
 
Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and Django
EDB
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official Documentation
Databricks
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 

More from Mydbops (20)

Scaling TiDB for Large-Scale Application
Scaling TiDB for Large-Scale Application
Mydbops
 
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
AWS Blue Green Deployment for Databases - Mydbops
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Demystifying Real time Analytics with TiDB
Demystifying Real time Analytics with TiDB
Mydbops
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Efficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Scaling TiDB for Large-Scale Application
Scaling TiDB for Large-Scale Application
Mydbops
 
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mydbops
 
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Mydbops
 
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
Mydbops
 
AWS Blue Green Deployment for Databases - Mydbops
AWS Blue Green Deployment for Databases - Mydbops
Mydbops
 
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
Mydbops
 
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
Mydbops
 
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Mydbops
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Read/Write Splitting using MySQL Router - Mydbops Meetup16
Mydbops
 
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
Mydbops
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Demystifying Real time Analytics with TiDB
Demystifying Real time Analytics with TiDB
Mydbops
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
Efficient MySQL Indexing and what's new in MySQL Explain
Efficient MySQL Indexing and what's new in MySQL Explain
Mydbops
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
Mydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mydbops
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Mydbops
 
Ad

Recently uploaded (20)

Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Ad

Data Organisation: Table Partitioning in PostgreSQL

  • 1. Mastering data organisation: Deep dive into PostgreSQL table partitioning Presented by Mohammad Zaid Patel Mydbops Mydbops MyWebinar - 30 Dec 23rd, 2023
  • 2. About Me ● PostgreSQL Database consultant ● Experienced in PostgreSQL and related DB technologies ● Active Blogger ● Tech Speaker ● Likes Cricket, Music & Comedy
  • 3. Consulting Services Consulting Services Managed Services ● Database Management and consultancy provider ● Founded in 2016 ● Assisted 800+ happy customers ● AWS partners ● PCI & ISO certified About Us
  • 4. ● Why data organisation ? ● Advantages of data organisation ● Techniques of data organisation ● Table partitioning in PostgreSQL ● Table partition techniques ● Demo for table partitioning using pg_partman ● Limitations of table partitioning ● Best practices for table partitioning Agenda
  • 6. ● Databases are used for storing and retrieving data ● Database becomes a black box ● Piled up with un-organised data ● Performance degradation of the database Why data organization?
  • 7. ● Organization of data is very essential for the database functionality ● Plays crucial roles in database efficiency ● Assures data integrity ● Improves the usability of the stored data Why data organization?
  • 10. Advantages of organizing your data ● Better data retrieval ● Improved query performance ● Data integrity ● Efficient storage and resource utilization ● Ease in maintenance ● Ease in scalability of the database ● Data analysis and reporting
  • 12. Data organization techniques Index creation : - Creates a data structure that allows quick access to rows based on specific column values - Faster data retrieval for conditions involving indexed columns - Types: B-tree, GIN,Hash indexes etc Data Archival: - Process of moving the old data to a different location - Clean up database - Helps in managing the data efficiently over time
  • 13. Data organization techniques Schemas: - Collection of database objects organized into a named namespace - Provides a way to logically group and organize database objects within a database - Multiple schemas with each schema having its own set of objects. Functional naming of database objects: - Helps in noting the type of database objects e.g. indexes, views , sequences etc - Easier for the users to understand the database structure and work with the objects more effectively
  • 14. Data organization techniques Relationships among database objects: - Avoids creation of "orphaned" records and maintaining consistency across related tables. - Efficient queries that involve data from multiple tables like JOIN operations Table partitioning: - Involves dividing large tables into smaller, more manageable pieces - Improves query performance, data management, and maintenance tasks - Data distribution across partitions.
  • 15. Table Partitioning in PostgreSQL
  • 16. Table Partitioning in PostgreSQL ● Database design technique that involves dividing large tables into smaller, more manageable segments called partitions id Name Cricket club 01 Virat RCB 02 Dhoni CSK 03 Rohit MI 04 Hardik MI 05 Siraj RCB 06 Jadeja CSK id Name Cricket club 01 Virat RCB 05 Siraj RCB 02 Dhoni CSK 06 Jadeja CSK 03 Rohit MI 04 Hardik MI Child table-1 Child table-2 Child table-3 Normal Table Partitioned Table Parent table
  • 17. ● Partition key, determines how data is distributed across partitions ● Efficient data management, especially for operations like data insertion, updates, and deletions. ● Enhances query performance by allowing the database to selectively scan only relevant partitions when queries involve conditions on the partition key ● Ease in data archival Table Partitioning in PostgreSQL
  • 18. Types of table partitioning in PostgreSQL
  • 19. Types of table partitioning in PostgreSQL PostgreSQL supports different partitioning methods including range partitioning , list partitioning, and hash partitioning. Range Partitioning: - Divides a table into partitions based on ranges of values in a chosen partition key column - Partitioning by a date column, each partition may represent a specific time period, such as months or years Creating a child table : CREATE TABLE child_table_2022_01_01 PARTITION OF parent_table FOR VALUES FROM ('2022-01-01') TO ('2023-02-01');
  • 20. Types of table partitioning in PostgreSQL id Username date_of_creation 01 Jake 01-01-2023 05 Ryan 01-01-2023 02 Anne 02-01-2023 06 Austin 02-01-2023 03 Daniel 03-01-2023 04 Taylor 03-01-2023 Child table-1 Child table-2 Child table-3 Range based partitioned table
  • 21. Types of table partitioning in PostgreSQL List based Partitioning: - Divides a table into partitions based on specific values in a chosen partition key column. - Rows with values falling within specific ranges of this key are grouped into individual partitions Creating a child table : CREATE TABLE new_york_child_table PARTITION OF parent_table FOR VALUES IN (‘New York’);
  • 22. Types of table partitioning in PostgreSQL id Username City 01 Jake New York 05 Ryan New York 02 Anne Tokyo 06 Austin Tokyo 03 Daniel London 04 Taylor London Child table-1 Child table-2 Child table-3 List based partitioned table
  • 23. Types of table partitioning in PostgreSQL Hash based Partitioning: - Divides a table into partitions based on the hash value of a chosen partition key column - Uniform distribution of data across partitions by using a hash function Creating a child table : CREATE TABLE child_table_1 PARTITION OF parent_table FOR VALUES WITH (MODULUS 3,REMAINDER 0);
  • 24. Types of table partitioning in PostgreSQL id Username City 01 Anne New York 05 Taylor Tokyo 02 Jake Tokyo 06 Austin London 03 Daniel London 04 Ryan New York Child table-1 Child table-2 Child table-3 List based partitioned table Remainder value 0001 0001 0002 0002 0003 0003
  • 26. Partitioning techniques in PostgreSQL 1. Manual Partitioning: - Creating parent tables and child tables manually - Maintenance of the child tables should be taken care of E.g Creating a parent table : CREATE TABLE parent_table ( id int,date_column DATE, value INTEGER, CONSTRAINT pkey PRIMARY KEY (id,date_column) ) PARTITION BY RANGE (date_column);
  • 27. Partitioning techniques in PostgreSQL E.g Creating a child table : CREATE TABLE child_table_2022 PARTITION OF parent_table FOR VALUES FROM ('2022-01-01') TO ('2023-01-01');
  • 28. Partitioning techniques in PostgreSQL 2. Partitioning using pg_partman extension: - Extension designed to create and oversee sets of partitioned tables - The creation of child tables is fully managed by the extension itself - The extension includes a background worker (BGW) process to streamline partition maintenance - Optional retention policy that can automatically discard partitions that are no longer necessary - Maintenance function takes cares of partition management on timely basis
  • 29. Partitioning techniques in PostgreSQL pg_partman extension is required: demo_db=# dx List of installed extensions Name | Version | Schema | Description ------------+---------+------------+--------------------------------- --------------------- pg_partman | 4.7.3 | partman | Extension to manage partitioned tables by time or ID
  • 30. Partitioning techniques in PostgreSQL Creating a parent table : Creating a child table : CREATE TABLE parent_table ( id integer ,created_date date, CONSTRAINT table01_pkey PRIMARY KEY (id,created_date) ) partition by range(created_date); SELECT partman.create_parent( p_parent_table => 'public.parent_table’, p_control => 'created_date', p_interval=> '1 day', p_premake => 2);
  • 31. Demo
  • 32. Limitations of Table partitioning
  • 33. Limitations of Table partitioning ● Useful only when the partition key is used ● Regular supervision is required for the pg_partman tool for partition management ● Complexities in data migration services ● Complexities in tables with foreign key relationships ● Child tables that are stored as backup needs to be taken care ● Data accumulation in default table fails the pg_partman functions
  • 34. Best practices for partitioned table maintenance
  • 35. ● Choose the Right Partition Key ● Understand Query Patterns ● Monitor and Tune Performance ● Choose Appropriate Partitioning Method ● Limit the Number of Partitions ● Implement Data Archiving ● Regularly Update PostgreSQL Version Best practices for partitioned table maintenance