pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedHow does Postgres store a B-Tree on disk while using the OS file system?
4+ messages / 3 participants
[nested] [flat]
* How does Postgres store a B-Tree on disk while using the OS file system?
@ 2023-03-07 00:24 Siddharth Jain <siddhsql@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: Siddharth Jain @ 2023-03-07 00:24 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
I am trying to sharpen my understanding of Postgres. As I understand,
Postgres does not write directly to disk blocks. It uses the file system
provided by the OS:
https://dba.stackexchange.com/questions/80036/is-there-a-way-to-store-a-postgresql-database-directly...
My question: How can it then store a B Tree on disk? I would think storing
a B Tree requires storing disk offset addresses and so on (for a node to
navigate to another etc.). For this, one would need to write directly to
the disk using low-level disk access functions and not use file system API.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How does Postgres store a B-Tree on disk while using the OS file system?
@ 2023-03-07 00:49 Ron <ronljohnsonjr@gmail.com>
parent: Siddharth Jain <siddhsql@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Ron @ 2023-03-07 00:49 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 3/6/23 18:24, Siddharth Jain wrote:
> I am trying to sharpen my understanding of Postgres. As I understand,
> Postgres does not write directly to disk blocks. It uses the file system
> provided by the OS:
> https://dba.stackexchange.com/questions/80036/is-there-a-way-to-store-a-postgresql-database-directly...
> My question: How can it then store a B Tree on disk? I would think storing
> a B Tree requires storing disk offset addresses and so on (for a node to
> navigate to another etc.). For this, one would need to write directly to
> the disk using low-level disk access functions and not use file system API.
Disk offsets... *file* offsets... one is just a step up on the abstraction
layer.
How can that be? The OS only knows about Logical Block Addresses, which are
a huge list of block numbers (just like userland software sees files as long
lists of bytes). It hasn't see cylinders, heads and platters in almost
FORTY (more, probably, for SCSI and mainframe systems) years.
--
Born in Arizona, moved to Babylonia.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How does Postgres store a B-Tree on disk while using the OS file system?
@ 2023-03-07 01:07 Christophe Pettus <xof@thebuild.com>
parent: Siddharth Jain <siddhsql@gmail.com>
1 sibling, 1 reply; 4+ messages in thread
From: Christophe Pettus @ 2023-03-07 01:07 UTC (permalink / raw)
To: Siddharth Jain <siddhsql@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
> On Mar 6, 2023, at 16:24, Siddharth Jain <siddhsql@gmail.com> wrote:
> My question: How can it then store a B Tree on disk? I would think storing a B Tree requires storing disk offset addresses and so on (for a node to navigate to another etc.). For this, one would need to write directly to the disk using low-level disk access functions and not use file system API.
All of PostgreSQL's relations (tables and indexes) are stored in files. (They're actually stored in a set of files if it's larger than 1GB, but each relation is treated as one logical file.) The "pointers" in this case are just offsets from the start of that file.
There's some additional information here:
https://www.postgresql.org/docs/current/storage.html
and here:
https://www.postgresql.org/docs/current/btree-implementation.html
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How does Postgres store a B-Tree on disk while using the OS file system?
@ 2023-03-07 02:53 Siddharth Jain <siddhsql@gmail.com>
parent: Christophe Pettus <xof@thebuild.com>
0 siblings, 0 replies; 4+ messages in thread
From: Siddharth Jain @ 2023-03-07 02:53 UTC (permalink / raw)
To: Christophe Pettus <xof@thebuild.com>; +Cc: pgsql-general@lists.postgresql.org
thanks Christophe. will try to go through it. its bit difficult to grasp.
On Mon, Mar 6, 2023 at 5:08 PM Christophe Pettus <xof@thebuild.com> wrote:
>
>
> > On Mar 6, 2023, at 16:24, Siddharth Jain <siddhsql@gmail.com> wrote:
> > My question: How can it then store a B Tree on disk? I would think
> storing a B Tree requires storing disk offset addresses and so on (for a
> node to navigate to another etc.). For this, one would need to write
> directly to the disk using low-level disk access functions and not use file
> system API.
>
> All of PostgreSQL's relations (tables and indexes) are stored in files.
> (They're actually stored in a set of files if it's larger than 1GB, but
> each relation is treated as one logical file.) The "pointers" in this case
> are just offsets from the start of that file.
>
> There's some additional information here:
>
> https://www.postgresql.org/docs/current/storage.html
>
> and here:
>
> https://www.postgresql.org/docs/current/btree-implementation.html
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2023-03-07 02:53 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 00:24 How does Postgres store a B-Tree on disk while using the OS file system? Siddharth Jain <siddhsql@gmail.com>
2023-03-07 00:49 ` Ron <ronljohnsonjr@gmail.com>
2023-03-07 01:07 ` Christophe Pettus <xof@thebuild.com>
2023-03-07 02:53 ` Siddharth Jain <siddhsql@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox