Database Table Partitioning: Faster Queries & Data Management

Database Table Partitioning: Faster Queries & Data Management

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1287
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1244
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1034
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1108
  • image_website-_0.webp
    Website development for Red Pear
    555

Database Table Partitioning: Faster Queries & Data Management

We implement database table partitioning. The problem of data growth is one of the most common causes of performance degradation. In a recent project, a client's events table had grown to 500 million rows, and queries were hanging for 30 seconds. We implemented monthly range partitioning — response time dropped to 50 ms, and storage costs decreased by 40% due to archiving old partitions.

In another project, a log table consumed 1.5 TB. After daily partitioning, the active set shrank to 50 GB, and TTFB dropped from 3 seconds to 200 ms. Without partitioning, every SELECT scans the entire table, inflating LCP and INP. Partition pruning eliminates unnecessary partitions, accelerating queries by 5–20x depending on selectivity. A typical query for the last month with range partitioning on a date column runs 10x faster than a full scan.

Our engineers have 10+ years of experience in database optimization and have successfully delivered over 50 partitioning projects. We guarantee a correctly working solution.

What Problems Does Table Partitioning Solve?

  • Performance degradation: Large tables without partitioning scan everything, increasing LCP and TTFB. Queries filtering by date or category suffer the most.
  • Maintenance difficulties: Cleaning or archiving old data becomes a painful DELETE with locking.
  • High storage costs: SSDs are expensive; storing all history on fast storage is wasteful.

How We Implement Table Partitioning

Stack and Tools

Component Tools
DBMS PostgreSQL (10+), MySQL (8.0+)
Automation pg_partman, cron
Migration logical replication, batch processing

Partitioning Types Comparison

Type Description When to Use
Range Values range (dates, numbers) Time-series data, logs, events
Hash Key hash Even load distribution, no natural split
List Value list (countries, statuses) Fixed categories

Concrete Case

Client: a marketing agency. Table events — 500 million rows, growing 10 million per month. Queries for last year's statistics were slow; backups were 200 GB.

We designed range partitioning on created_at with monthly partitions. Set up pg_partman: premake 3 partitions ahead, retention 12 months (auto-delete).

CREATE TABLE events ( id BIGSERIAL, user_id INTEGER NOT NULL, event_type VARCHAR(64) NOT NULL, payload JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT now() ) PARTITION BY RANGE (created_at); CREATE TABLE events_2023_01 PARTITION OF events FOR VALUES FROM ('2023-01-01') TO ('2023-02-01'); -- pg_partman: create schedule SELECT partman.create_parent( p_parent_table => 'public.events', p_control => 'created_at', p_type => 'native', p_interval => 'monthly', p_premake => 3 ); 

Result: queries sped up 10x, production size was only the latest 6 months, old data moved to object storage.

Why Choosing the Right Partition Key Matters

Partition pruning only works when the WHERE clause explicitly uses the key. A typical mistake is wrapping the key in a function: DATE(created_at) = '2023-01-15' — pruning disables. Correct: created_at >= '2023-01-15' AND created_at < '2023-01-16'. We verify this during testing.

How to Perform Zero-Downtime Migration?

  1. Create a new partitioned table with the same columns.
  2. Copy data in monthly batches (separate INSERT).
  3. Switch via transaction: ALTER TABLE events RENAME TO events_old; ALTER TABLE events_partitioned RENAME TO events; — seconds.
  4. Drop the old table after a week of monitoring.
  5. Configure pg_partman for automatic management.
Detailed Migration Plan

Copying large volumes without locking — use logical replication or pglogical. The process takes from hours to a day depending on data size. We perform migration during business hours or in a minimal window.

Our Work Process

  1. Analysis — profile queries, identify slowest, assess data volume and growth rate.
  2. Design — choose key and partitioning type (range, hash, list), number of partitions.
  3. Implementation — write scripts, configure pg_partman, create historical partitions.
  4. Testing — verify partition pruning, benchmark before/after.
  5. Deployment — migrate using the described scheme, during business hours or minimal window.
  6. Monitoring — set up alerts for missed partitions and threshold breaches.

Timelines and What's Included

Estimated timelines: from 3 to 10 business days. The cost is calculated individually. What is included:

  • Partitioning schema documentation
  • Scripts for partition creation and management
  • Automated maintenance setup (pg_partman or equivalent)
  • Monitoring and alerting instructions
  • 3-month warranty on correct operation

Contact us for a free project assessment — we will analyze your workload and propose the optimal solution.

Common Mistakes in Table Partitioning

  • Wrong key — pruning doesn't work, performance degrades
  • Indexes created on parent but not on all partitions (PG < 11)
  • No premake — new partitions aren't created on time
  • In MySQL, unique keys must include the partition key

When Partitioning Is Not Needed

  • Table smaller than 10–20 million rows — indexes suffice
  • No clear key (data without temporal or categorical label)
  • Queries don't filter by key — no benefit

More about PostgreSQL partitioning — official documentation

Contact us for a free project assessment. We will analyze your workload and propose the optimal solution.