SlideShare a Scribd company logo
1 of 38
Download to read offline
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!

More Related Content

Similar to Data Organisation: Table Partitioning in PostgreSQL

7 - Enterprise IT in Action
7 - Enterprise IT in Action7 - Enterprise IT in Action
7 - Enterprise IT in ActionRaymond Gao
 
Sql server lesson7
Sql server lesson7Sql server lesson7
Sql server lesson7Ala Qunaibi
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…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 parameterizationQuery parameterization
Query parameterizationRiteshkiit
 
Microsoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdfMicrosoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdfSpiritsoftsTraining
 
SQL Server 2019 Master Data Service
SQL Server 2019 Master Data ServiceSQL Server 2019 Master Data Service
SQL Server 2019 Master Data ServiceKenichiro Nakamura
 
An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...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
 
An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...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
 
MySQL Indexing
MySQL IndexingMySQL Indexing
MySQL IndexingBADR
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsCloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsPushkar Chivate
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
Large Table Partitioning with PostgreSQL and Django
 Large Table Partitioning with PostgreSQL and Django Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and DjangoEDB
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationSpark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationDatabricks
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesSperasoft
 
SQL Server 2016 - Stretch DB
SQL Server 2016 - Stretch DB SQL Server 2016 - Stretch DB
SQL Server 2016 - Stretch DB Shy Engelberg
 

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

7 - Enterprise IT in Action
7 - Enterprise IT in Action7 - Enterprise IT in Action
7 - Enterprise IT in Action
 
Sql server lesson7
Sql server lesson7Sql server lesson7
Sql server lesson7
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Microsoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdfMicrosoft Power BI Online Training.pdf
Microsoft Power BI Online Training.pdf
 
SQL Server 2019 Master Data Service
SQL Server 2019 Master Data ServiceSQL Server 2019 Master Data Service
SQL Server 2019 Master Data Service
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...An extended database reverse engineering v a key for database forensic invest...
An extended database reverse engineering v a key for database forensic invest...
 
An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...An extended database reverse engineering – a key for database forensic invest...
An extended database reverse engineering – a key for database forensic invest...
 
MySQL Indexing
MySQL IndexingMySQL Indexing
MySQL Indexing
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsCloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure tools
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
Large Table Partitioning with PostgreSQL and Django
 Large Table Partitioning with PostgreSQL and Django Large Table Partitioning with PostgreSQL and Django
Large Table Partitioning with PostgreSQL and Django
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationSpark SQL Beyond Official Documentation
Spark SQL Beyond Official Documentation
 
tw_242.ppt
tw_242.ppttw_242.ppt
tw_242.ppt
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
 
SQL Server 2016 - Stretch DB
SQL Server 2016 - Stretch DB SQL Server 2016 - Stretch DB
SQL Server 2016 - Stretch DB
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
 
SQLDay2013_ChrisWebb_CubeDesign&PerformanceTuning
SQLDay2013_ChrisWebb_CubeDesign&PerformanceTuningSQLDay2013_ChrisWebb_CubeDesign&PerformanceTuning
SQLDay2013_ChrisWebb_CubeDesign&PerformanceTuning
 

More from Mydbops

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024Mydbops
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...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 RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMydbops
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Mydbops
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15Mydbops
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventMydbops
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...Mydbops
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Mydbops
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mydbops
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsMydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDBMydbops
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mydbops
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesMydbops
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Mydbops
 
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsMydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLMydbops
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Mydbops
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at RestMydbops
 

More from Mydbops (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDB
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificates
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops
 
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQL
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

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