shared_buffers, wal_buffers, WAL files, data files

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: pgsql-hackers(at)postgresql(dot)org
Subject: shared_buffers, wal_buffers, WAL files, data files
Date: 2007-12-05 17:06:41
Message-ID: 4756DAA1.6070209@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

First, I'm not sure this mail should go to this mailing list. As it
refers to source code (mainly src/backend/postmaster/bgwriter.c and
src/backend/access/transam/xlog.c), I sent it here. I apologize if I'm
wrong.

I'm a bit puzzled by the different informations I can read on the
documentation, on the source files and other README files from the
source package. I'm actually using 8.2.5 source files.

I try to answer a simple question : what happens when I do a simple
"INSERT" on a just started PostgreSQL server.

# pg_ctl start
# psql foobase
[...]
foobase=# CREATE TABLE footable (i int4);
CREATE TABLE
foobase=# INSERT INTO footable (i) VALUES (1);
INSERT 0 1

From what I understand with the INSERT statement, here is what happens :
* backend loads first (and only) block from footable file into a shared
buffer
* it modifies this block on the shared buffer, and sets it as dirty

After checkpoint_timeout seconds or after a manual CHECKPOINT (there's
also some other ways to have a checkpoint but in my simple example,
these two seem to be the most probable ones) :
* bgwriter runs CreateCheckPoint
* it will, beyond other things, flush this block from shared buffer to
disk, fsync, sets the block as non-dirty...

... and here is my first question : flushes to the current XLOG file or
to footable data file ? I think it is to XLOG file but I don't find
where in the code the content of WAL files is flushed to data files. If
you know where I can look to get this information, I'm really interested.

From other parts of the documentation, it seems checkpoints are also in
charge of flushing WAL files to data files. I've read something like
this: "a checkpoint writes dirty shared buffers, sync dirty kernel
buffers, recycle WAL files." Also, because of the checkpoint_segments GUC.

And I don't find where wal_buffers are used in all this process.

One last thing (wrt this mail), I think I understand what
full_page_writes does but I wonder what this sentence means : "Writes
full pages to WAL when first modified after a checkpoint." ? (it's the
last part that I don't understand)

Thanks for any pointers.

Regards.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Guillaume Smet 2007-12-05 17:49:00 Re: Better default_statistics_target
Previous Message Alvaro Herrera 2007-12-05 16:29:09 Re: autoconf