Re: Does PostgreSQL cache all columns of a table after SELECT? - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: Does PostgreSQL cache all columns of a table after SELECT?
Date
Msg-id 9471e8396d5e0de1b0b087678f52e9dc478837a8.camel@cybertec.at
Whole thread Raw
In response to Does PostgreSQL cache all columns of a table after SELECT?  (Tim Schwenke <tim@trallnag.com>)
List pgsql-novice
On Mon, 2023-06-05 at 14:15 +0200, Tim Schwenke wrote:
> Hello,
>
> I have the following table with the following columns:
>
> large_a: text (few dozen characters up to a few hundred)
> large_b: text (few dozen characters up to a few hundred)
>
> The table has several million rows. The DB is running on a large machine.
>
> I perform the following query:
>
> select large_a from table;
>
> The first query takes a few minutes. Afterwards I see that the cache in memory has grown. Next query only takes a few
seconds.
>
> What I want to know:
>
> Does the cache also contain large_b? Or is only large_a cached? Assumption is that memory is large enough to fit
everything.

It depends.

If "large_a" and "large_b" are TOASTed, then they will only be cached if the column
is explicitly selected.

For shorter attributes, the whole row is in one piece, and all columns will get cached.

However, for sequential scans that are larger than a quarter of shared buffers,
PostgreSQL uses a ring buffer to avoid blowing out the cache.  In that case, most
data won't be cached for the next query.

Yours,
Laurenz Albe



pgsql-novice by date:

Previous
From: Tim Schwenke
Date:
Subject: Re: Does PostgreSQL cache all columns of a table after SELECT?
Next
From: "David G. Johnston"
Date:
Subject: Re: Does PostgreSQL cache all columns of a table after SELECT?