> On Jul 18, 2022, at 20:03, merryok <merr...@163.com> wrote:
>
> I've read the doc, and it doesn't help too much.
> Finally I've found START_CRIT_SECTION and END_CRIT_SECTION. It's like
> mtr.start(), mtr.commit() in mysql. May I ask why many places are wrapped
> into START_CRIT_SECTION/END_CRIT_SECTION during a single dml operation ?
A PostgreSQL critical section is not the equivalent of MySQL InnoDB
mini-transaction.
A critical section in PostgreSQL is a section of code that needs to run without
interruption to avoid corruption of internal in-memory data structures.
PostgreSQL doesn't have a direct equivalent of a MySQL mini-transaction. When
WAL information is created by a statement, it's stored in the WAL buffers, and
then flushed to disk by the WAL writer (to a first approximation). There's no
special operation that groups pages together for atomic writes; that's done by
the underlying file system flush operation.
> And if Assert(CritSectionCount > 0) isn't satisfied (CritSectionCount need't
> be protected ?), PG server will panic and exit ? If so, what's the
> probability of that ?
If it occurs, it indicates a bug in PostgreSQL. It is *extremely* infrequent
(as in, you can go years without seeing one; I can't remember the last time I
did).