postgresql/contrib
Alvaro Herrera f49a80c481 Fix "base" snapshot handling in logical decoding
Two closely related bugs are fixed.  First, xmin of logical slots was
advanced too early.  During xl_running_xacts processing, xmin of the
slot was set to the oldest running xid in the record, but that's wrong:
actually, snapshots which will be used for not-yet-replayed transactions
might consider older txns as running too, so we need to keep xmin back
for them.  The problem wasn't noticed earlier because DDL which allows
to delete tuple (set xmax) while some another not-yet-committed
transaction looks at it is pretty rare, if not unique: e.g. all forms of
ALTER TABLE which change schema acquire ACCESS EXCLUSIVE lock
conflicting with any inserts. The included test case (test_decoding's
oldest_xmin) uses ALTER of a composite type, which doesn't have such
interlocking.

To deal with this, we must be able to quickly retrieve oldest xmin
(oldest running xid among all assigned snapshots) from ReorderBuffer. To
fix, add another list of ReorderBufferTXNs to the reorderbuffer, where
transactions are sorted by base-snapshot-LSN.  This is slightly
different from the existing (sorted by first-LSN) list, because a
transaction can have an earlier LSN but a later Xmin, if its first
record does not obtain an xmin (eg. xl_xact_assignment).  Note this new
list doesn't fully replace the existing txn list: we still need that one
to prevent WAL recycling.

The second issue concerns SnapBuilder snapshots and subtransactions.
SnapBuildDistributeNewCatalogSnapshot never assigned a snapshot to a
transaction that is known to be a subtxn, which is good in the common
case that the top-level transaction already has one (no point in doing
so), but a bug otherwise.  To fix, arrange to transfer the snapshot from
the subtxn to its top-level txn as soon as the kinship gets known.
test_decoding's snapshot_transfer verifies this.

Also, fix a minor memory leak: refcount of toplevel's old base snapshot
was not decremented when the snapshot is transferred from child.

Liberally sprinkle code comments, and rewrite a few existing ones.  This
part is my (Álvaro's) contribution to this commit, as I had to write all
those comments in order to understand the existing code and Arseny's
patch.

Reported-by: Arseny Sher <a.sher@postgrespro.ru>
Diagnosed-by: Arseny Sher <a.sher@postgrespro.ru>
Co-authored-by: Arseny Sher <a.sher@postgrespro.ru>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Antonin Houska <ah@cybertec.at>
Discussion: https://postgr.es/m/87lgdyz1wj.fsf@ars-thinkpad
2018-06-26 16:48:10 -04:00
..
adminpack adminpack: Revoke EXECUTE on pg_logfile_rotate() 2018-05-07 10:10:33 -04:00
amcheck Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
auth_delay
auto_explain Allow auto_explain.log_min_duration to go up to INT_MAX. 2018-02-23 14:39:17 -05:00
bloom Don't fall off the end of perl functions 2018-05-27 09:08:42 -04:00
btree_gin Clean up warnings from -Wimplicit-fallthrough. 2018-05-01 19:35:08 -04:00
btree_gist Fix assorted issues in convert_to_scalar(). 2018-03-03 20:31:35 -05:00
citext
cube Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
dblink Indexes with INCLUDE columns and their support in B-tree 2018-04-07 23:00:39 +03:00
dict_int Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
dict_xsyn Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
earthdistance Improve English wording of some other getObjectDescription() messages. 2018-05-24 14:01:10 -04:00
file_fdw Allow insert and update tuple routing and COPY for foreign tables. 2018-04-06 19:22:03 -04:00
fuzzystrmatch
hstore Fix assorted compiler warnings seen in the buildfarm. 2018-05-02 15:52:54 -04:00
hstore_plperl Fix contrib/hstore_plperl to look through scalar refs. 2018-06-18 15:55:06 -04:00
hstore_plpython Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-04-03 16:26:05 -04:00
intagg
intarray Don't fall off the end of perl functions 2018-05-27 09:08:42 -04:00
isn
jsonb_plperl Fix jsonb_plperl to convert Perl UV values correctly. 2018-06-18 17:39:57 -04:00
jsonb_plpython Fix memory leak in PLySequence_ToJsonbValue() 2018-06-15 15:01:46 +03:00
lo
ltree
ltree_plpython Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-04-03 16:26:05 -04:00
oid2name Switch client-side code to include catalog/pg_foo_d.h not pg_foo.h. 2018-04-08 13:59:52 -04:00
pageinspect printf("%lf") is not portable, so omit the "l". 2018-05-20 11:40:54 -04:00
passwordcheck
pg_buffercache
pg_freespacemap
pg_prewarm Avoid portability issues in autoprewarm.c. 2018-05-03 12:50:34 -04:00
pg_standby
pg_stat_statements Reorganize partitioning code 2018-04-14 21:12:14 -03:00
pg_trgm Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
pg_visibility
pgcrypto Fix a boatload of typos in C comments. 2018-04-01 15:01:28 -04:00
pgrowlocks Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
pgstattuple pgstatindex, pageinspect: handle partitioned indexes 2018-05-09 14:22:59 -03:00
postgres_fdw Improve English wording of some other getObjectDescription() messages. 2018-05-24 14:01:10 -04:00
seg
sepgsql Update sepgsql regression test output for getObjectDescription() changes. 2018-05-24 16:11:25 -04:00
spi Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-04-03 16:26:05 -04:00
sslinfo
start-scripts
tablefunc
tcn Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
test_decoding Fix "base" snapshot handling in logical decoding 2018-06-26 16:48:10 -04:00
tsm_system_rows
tsm_system_time
unaccent Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
uuid-ossp
vacuumlo Switch client-side code to include catalog/pg_foo_d.h not pg_foo.h. 2018-04-08 13:59:52 -04:00
xml2
contrib-global.mk
Makefile Transforms for jsonb to PL/Perl 2018-04-03 09:47:18 -04:00
README

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.