Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Horizontal database partitioning divides a table’s rows into smaller physical subsets while keeping them part of one logical table. A partition key and its bounds determine where each row belongs. In PostgreSQL’s definition, it means “splitting what is logically one large table into smaller physical pieces.”

What horizontal partitioning divides

Horizontal partitioning divides rows, not columns. Each partition contains a subset of the table’s records, selected according to a partition key. The table remains logically unified, so applications can work with it as one table even though its data is stored in separate physical pieces. PostgreSQL describes this model in its PostgreSQL 17 table-partitioning documentation.

Vertical partitioning is the contrasting general idea of separating columns. The PostgreSQL documentation cited here covers row-based partitioning, not a detailed definition of vertical partitioning, and database systems may implement partitioning differently.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How PostgreSQL assigns rows to partitions

In PostgreSQL declarative partitioning, you define a partitioning method and key on a parent table, then create partitions with bounds that specify which key values they accept. The parent table is virtual and stores no rows itself; its partitions are ordinary tables that hold the data. Inserts are routed to the partition matching their key values. If an update changes a row’s partition key, PostgreSQL can move that row to a different partition. See the PostgreSQL 17 partitioning documentation.

#1 Best Overall

Range partitioning

Range partitioning assigns rows according to intervals of key values, such as ranges of dates. It can suit tables whose data naturally falls into ordered ranges.

List partitioning

List partitioning assigns rows according to specified key values, such as a defined set of categories. A partition’s bounds determine which values it accepts.

Hash partitioning

Hash partitioning uses a hash of the partition key to distribute rows among partitions. PostgreSQL documents hash partitioning in its PostgreSQL 17 CREATE TABLE reference. Supported methods and syntax depend on the database system and version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When partitioning can help—and when it may not

Partitioning can help queries that need only part of a large table if their conditions let the database exclude partitions that cannot contain matching rows. PostgreSQL calls this partition pruning. For example, a query restricted to a date range may avoid scanning partitions whose date bounds fall outside that range. The benefit depends on the partition key and query predicates, not simply on the table being partitioned.

Bulk data operations may also be easier when the partition layout matches the data’s lifecycle. But queries that cannot eliminate partitions may still need to scan many of them. Partitioning adds design and maintenance decisions, and it does not automatically speed every query or replace indexes: indexes may still be useful within individual partitions, depending on how the table is accessed. PostgreSQL recommends choosing a design around the workload rather than a universal table-size threshold; see its partitioning guidance.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Partitioning versus sharding

In common usage, partitioning divides a table into pieces that can remain on the same database server, while sharding distributes subsets of data across multiple servers. The distinction is useful but not a universal standards definition: terminology varies, and PostgreSQL’s wiki labels its overview a work in progress. See the PostgreSQL wiki overview.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.