Re: [HACKERS] Logical decoding

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Joshua Bay <joshuabay93(at)gmail(dot)com>
Cc: pgsql-committers(at)postgresql(dot)org, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Logical decoding
Date: 2016-07-11 05:03:27
Message-ID: CAMsr+YE029uoBuQoGBJEckReat=r7ZYhc24LTrE53MxXL2u7oQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On 9 July 2016 at 01:57, Joshua Bay <joshuabay93(at)gmail(dot)com> wrote:

> where are the entry points to logical decoding?
>

Well, it depends on what level you're looking at.

Data is read using the xlogreader and fed into the decoding system by the
walsender (when using a logical slot) and the SQL level
pg_logical_slot_[get|peek]_changes functions. See XLogSendLogical() as
called by WalSndLoop() and see pg_logical_slot_get_changes_guts() .

WAL records are passed through to logical decoding and depending on the
xlog entry type the reorder buffer and/or snapshot builder. Then when a
transaction commit is detected the registered output plugin is invoked and
its callbacks are used to process the buffered transaction.

> Specifically, we want to know whether logical decoding happens immediately
> after commit, or whether there is a polling thread that scans the Write
> Ahead Log and then dumps to the special table?
>

There's no "polling thread", but that's probably the closer of the two. A
walsender using a logical slot reads WAL as it becomes available. It sleeps
on a latch if it runs out of WAL to read and is woken when there's more. It
isn't dumped to some special table, it's managed by the reorder buffer
infrastructure which uses its own special data structures. Reading may lag
behind WAL generation since it's "pulled" by the client and happens lazily
after commit.

> and where are this code is in the codebase?
>

src/backend/replication/logical/*
src/backend/replication/walsender.c
src/backend/access/transam/xlogreader.c
src/include/access/xlogreader.h
src/include/replication/output_plugin.h
contrib/test_decoding/
doc/src/sgml/logicaldecoding.sgml

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2016-07-11 05:13:11 Re: [COMMITTERS] Logical decoding
Previous Message Tom Lane 2016-07-10 16:46:33 pgsql: Revert "Add some temporary code to record stack usage at server

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2016-07-11 05:10:07 Re: pgbench - minor fix for meta command only scripts
Previous Message Craig Ringer 2016-07-11 04:53:02 Re: Issue with bgworker, SPI and pgstat_report_stat