Re: Does PostgreSQL cache all columns of a table after SELECT?

From: Tim Schwenke <tim(at)trallnag(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "Pgsql Novice" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Re: Does PostgreSQL cache all columns of a table after SELECT?
Date: 2023-06-05 13:47:34
Message-ID: 1888bd0285f.c47bd298692167.399116048841887836@trallnag.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello,

I just tested it and it indeed works this way.

1. Created new table with only relevant columns.

2. Stopped PostgreSQL DB.

3. Dropped page cache.

4. Started again.

5. Run query against new table

6. Way less cache used, query is faster, less data is being read into cache.

---- On Mon, 05 Jun 2023 15:17:17 +0200 Tim Schwenke <tim(at)trallnag(dot)com> wrote ---

Hello David,

from what I understand, in PostgreSQL, tables are stored in one or more files called segments. There is no separation by columns.

https://www.postgresql.org/docs/8.1/storage.html

This means if I select a single column from a table the first time, the full file / segment is read and put into page cache if there is enough space. This means a table with only one large column large_a takes up less page cache compared to a table with many large columns large_a and large_b, even though in both cases only large_a is selected.

Is that more or less correct? Ignoring toast?

Tim S.

---- On Mon, 05 Jun 2023 14:58:21 +0200 David G. Johnston wrote ---

>
>
> On Monday, June 5, 2023, Tim Schwenke mailto:tim(at)trallnag(dot)com> wrote:
>
>
> Does the cache also contain large_b? Or is only large_a cached? Assumption is that memory is large enough to fit everything.
>
>
> Shared buffers is a page cache.
>
> David J. 
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Laurenz Albe 2023-06-05 13:58:38 Re: Does PostgreSQL cache all columns of a table after SELECT?
Previous Message Tim Schwenke 2023-06-05 13:19:08 Re: Does PostgreSQL cache all columns of a table after SELECT?