Обсуждение: Question on PostgreSQL Table Partitioning – Performance of Queries That Do Not Use the Partition Key

Поиск
Список
Период
Сортировка
Hi,

Question on PostgreSQL Table Partitioning – Performance of Queries That Do Not Use the Partition Key  

We have a table that is approximately 1.6 GB in size. Query performance has started to degrade. Although we have multiple indexes, the large table size is still causing performance issues.

We are planning to partition the table on the primary key. This is an OLTP system, and there are around 100 queries that access this table. About 80 of these queries use the primary key and will therefore benefit directly from the partition key once we implement partitioning. However, the remaining 20 queries do not use the primary key; they rely on other indexed columns.

Our question is: after partitioning the table, and after creating the necessary indexes on each partition, what happens to the performance of those 20 queries that do not use the partition key?
– Will their performance degrade?
– Will it remain the same as before partitioning?
– Is there any chance it will improve?

Additional details: we plan to create only 16 partitions, so the partition count will not be very high.

Is there any benchmarking, documentation, or reference material that can help demonstrate how partitioning will affect the performance of the 20 queries that do not use the partition key?

This information is critical for us before proceeding with the partitioning strategy.


Thank you in advance.

Regards,
Atma



On Wed, Nov 26, 2025 at 8:32 AM atma ram <atmaramkp@gmail.com> wrote:
Hi,

Question on PostgreSQL Table Partitioning – Performance of Queries That Do Not Use the Partition Key  

We have a table that is approximately 1.6 GB in size. Query performance has started to degrade. Although we have multiple indexes, the large table size

1.6GB is pretty darned tiny.  Did you mean TB?

When was the last time the table was vacuumed and analyzed?  Tuning autovacuum parameters is important, but you might have to also create a cron job to regularly manually analyze and vacuum them.

is still causing performance issues.

We are planning to partition the table on the primary key. This is an OLTP system, and there are around 100 queries that access this table. About 80 of these queries use the primary key and will therefore benefit directly from the partition key once we implement partitioning. However, the remaining 20 queries do not use the primary key; they rely on other indexed columns.

Our question is: after partitioning the table, and after creating the necessary indexes on each partition, what happens to the performance of those 20 queries that do not use the partition key?
– Will their performance degrade?
– Will it remain the same as before partitioning?
– Is there any chance it will improve?

Additional details: we plan to create only 16 partitions, so the partition count will not be very high.

Is there any benchmarking, documentation, or reference material that can help demonstrate how partitioning will affect the performance of the 20 queries that do not use the partition key?

This information is critical for us before proceeding with the partitioning strategy.

Every circumstance is different. You're going to have to test it.

--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
On Wed, 2025-11-26 at 18:50 +0530, atma ram wrote:
> We have a table that is approximately 1.6 GB in size. Query performance has started to degrade.
> Although we have multiple indexes, the large table size is still causing performance issues.

1.6 GB is too small for partitioning.

> We are planning to partition the table on the primary key. This is an OLTP system, and there
> are around 100 queries that access this table. About 80 of these queries use the primary key
> and will therefore benefit directly from the partition key once we implement partitioning.

If a table uses the primary key, I cannot see how it could cause performance issues.

I expect that these queries will become slightly *slower* if you partition the table,
because of the overhead of partition pruning.

> However, the remaining 20 queries do not use the primary key; they rely on other indexed columns.
> Our question is: after partitioning the table, and after creating the necessary indexes on
> each partition, what happens to the performance of those 20 queries that do not use the partition key?
> – Will their performance degrade?

Very likely yes, though perhaps only slightly.

> – Will it remain the same as before partitioning?
> – Is there any chance it will improve?

That is unlikely, but possible, for example if the query can choose a faster sequential
scan on some partitions, instead of a slower index scan on the whole table.

> Is there any benchmarking, documentation, or reference material that can help demonstrate
> how partitioning will affect the performance of the 20 queries that do not use the partition key?
> This information is critical for us before proceeding with the partitioning strategy.

The only good way to tell is to implement it on a test database and try it.

But as I said initially, with a 1.6 GB table patritioning is pointless.

Examine the performance bottleneck with EXPLAIN (ANALYZE, BUFFERS) and try to improve
your queries.

Yours,
Laurenz Albe



Hi Laurenz,

Thank you for your reply.

The table size is 1.6TB and not GB. My bad.

The queries using primary key or partition key will be definitely improved. My question is 20 queries that do not use partition key and use only index. Since this is a critical OLTP system, even if there is a slight chance that those 20 queries will degrade performance, then we may not go with partition and find any alternative ways. Hence the question. 

We can do a POC and find out. But wanted to check if there are any existing benchmarking, explanations or details available before we do POC. Is it worth it?

Thanks,
Atma

On Wed, Nov 26, 2025 at 9:05 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
On Wed, 2025-11-26 at 18:50 +0530, atma ram wrote:
> We have a table that is approximately 1.6 GB in size. Query performance has started to degrade.
> Although we have multiple indexes, the large table size is still causing performance issues.

1.6 GB is too small for partitioning.

> We are planning to partition the table on the primary key. This is an OLTP system, and there
> are around 100 queries that access this table. About 80 of these queries use the primary key
> and will therefore benefit directly from the partition key once we implement partitioning.

If a table uses the primary key, I cannot see how it could cause performance issues.

I expect that these queries will become slightly *slower* if you partition the table,
because of the overhead of partition pruning.

> However, the remaining 20 queries do not use the primary key; they rely on other indexed columns.
> Our question is: after partitioning the table, and after creating the necessary indexes on
> each partition, what happens to the performance of those 20 queries that do not use the partition key?
> – Will their performance degrade?

Very likely yes, though perhaps only slightly.

> – Will it remain the same as before partitioning?
> – Is there any chance it will improve?

That is unlikely, but possible, for example if the query can choose a faster sequential
scan on some partitions, instead of a slower index scan on the whole table.

> Is there any benchmarking, documentation, or reference material that can help demonstrate
> how partitioning will affect the performance of the 20 queries that do not use the partition key?
> This information is critical for us before proceeding with the partitioning strategy.

The only good way to tell is to implement it on a test database and try it.

But as I said initially, with a 1.6 GB table patritioning is pointless.

Examine the performance bottleneck with EXPLAIN (ANALYZE, BUFFERS) and try to improve
your queries.

Yours,
Laurenz Albe
An old greybeard COBOL programmer would say that a critical OLTP table should only be accessed via one index (customer_id, sale_id, PK, etc), and there should be as few indices as possible on the table.  The DBA would then partition based on that index.  Any reports should be run from a separate table which is populated from the OLTP table.  (This is why reporting databases and their big brothers "data warehouses" were developed: so you aren't querying the whole critical OLTP table.)

In your case, right now, my first DBA task would be to ensure that the table is regularly vacuumed and analyzed.

On Wed, Nov 26, 2025 at 11:29 AM atma ram <atmaramkp@gmail.com> wrote:
Hi Laurenz,

Thank you for your reply.

The table size is 1.6TB and not GB. My bad.

The queries using primary key or partition key will be definitely improved. My question is 20 queries that do not use partition key and use only index. Since this is a critical OLTP system, even if there is a slight chance that those 20 queries will degrade performance, then we may not go with partition and find any alternative ways. Hence the question. 

We can do a POC and find out. But wanted to check if there are any existing benchmarking, explanations or details available before we do POC. Is it worth it?

Thanks,
Atma

On Wed, Nov 26, 2025 at 9:05 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
On Wed, 2025-11-26 at 18:50 +0530, atma ram wrote:
> We have a table that is approximately 1.6 GB in size. Query performance has started to degrade.
> Although we have multiple indexes, the large table size is still causing performance issues.

1.6 GB is too small for partitioning.

> We are planning to partition the table on the primary key. This is an OLTP system, and there
> are around 100 queries that access this table. About 80 of these queries use the primary key
> and will therefore benefit directly from the partition key once we implement partitioning.

If a table uses the primary key, I cannot see how it could cause performance issues.

I expect that these queries will become slightly *slower* if you partition the table,
because of the overhead of partition pruning.

> However, the remaining 20 queries do not use the primary key; they rely on other indexed columns.
> Our question is: after partitioning the table, and after creating the necessary indexes on
> each partition, what happens to the performance of those 20 queries that do not use the partition key?
> – Will their performance degrade?

Very likely yes, though perhaps only slightly.

> – Will it remain the same as before partitioning?
> – Is there any chance it will improve?

That is unlikely, but possible, for example if the query can choose a faster sequential
scan on some partitions, instead of a slower index scan on the whole table.

> Is there any benchmarking, documentation, or reference material that can help demonstrate
> how partitioning will affect the performance of the 20 queries that do not use the partition key?
> This information is critical for us before proceeding with the partitioning strategy.

The only good way to tell is to implement it on a test database and try it.

But as I said initially, with a 1.6 GB table patritioning is pointless.

Examine the performance bottleneck with EXPLAIN (ANALYZE, BUFFERS) and try to improve
your queries.

Yours,
Laurenz Albe


--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
On Wed, 2025-11-26 at 21:59 +0530, atma ram wrote:
> The table size is 1.6TB and not GB. My bad.
>
> The queries using primary key or partition key will be definitely improved.

That's not what I would expect, but if you tested it, ok.

> My question is 20 queries that do not use partition key and use only index.
> Since this is a critical OLTP system, even if there is a slight chance that
> those 20 queries will degrade performance, then we may not go with partition
> and find any alternative ways. Hence the question. 

I am pretty sure that the performance will be (at least slightly) worse.

Yours,
Laurenz Albe