PostgreSQL Weekly News - November 22, 2020

Posted on 2020-11-23 by PWN

PostgreSQL Weekly News - November 22, 2020

Person of the week:

PostgreSQL Product News

PGroonga 2.2.7 a full text search platform for all languages, released.

PostGIS 3.0.3, the industry standard geographic information system package for PostgreSQL, released.

pgtt 2.2, an extension to implement global temporary tables, released.

pgAdmin4 4.28, a web- and native GUI control center for PostgreSQL, released.

pgbouncer 1.15.0, a connection pooler and more for PostgreSQL, released.

pitrery 3.2, a set of Bash scripts to manage PITR backups for PostgreSQL, released.

pg_statement_rollback v1.1, an extension that adds server side transaction with rollback at statement level, released.

PostgreSQL Jobs for November

PostgreSQL in the News

Planet PostgreSQL:

PostgreSQL Weekly News is brought to you this week by David Fetter

Submit news and announcements by Sunday at 3:00pm PST8PDT to

Applied Patches

Tom Lane pushed:

  • Fix fuzzy thinking about amcanmulticol versus amcaninclude. These flags should be independent: in particular an index AM should be able to say that it supports include columns without necessarily supporting multiple key columns. The included-columns patch got this wrong, possibly aided by the fact that it didn't bother to update the documentation. While here, clarify some text about amcanreturn, which was a little vague about what should happen when amcanreturn reports that only some of the index columns are returnable. Noted while reviewing the SP-GiST included-columns patch, which quite incorrectly (and unsafely) changed SP-GiST to claim amcanmulticol = true as a workaround for this bug. Backpatch to v11 where included columns were introduced.

  • Use "true" not "TRUE" in one ICU function call. This was evidently missed in commit 6337865f3, which generally did s/TRUE/true/ everywhere. It escaped notice up to now because ICU versions before ICU 68 provided definitions of "TRUE" and "FALSE" regardless. With ICU 68, it fails to compile. Per report from Condor. Back-patch to v11 where 6337865f3 came in. (I've not tested v10, where this call originated, but I imagine it's fine since we defined TRUE in c.h back then.) Discussion:

  • Do not return NULL for error cases in satisfies_hash_partition(). Since this function is used as a CHECK constraint condition, returning NULL is tantamount to returning TRUE, which would have the effect of letting in a row that doesn't satisfy the hash condition. Admittedly, the cases for which this is done should be unreachable in practice, but that doesn't make it any less a bad idea. It also seems like a dartboard was used to decide which error cases should throw errors as opposed to returning NULL. For the checks for NULL input values, I just switched it to returning false. There's some argument that an error would be better; but the case really should be can't-happen in a generated hash constraint, so it's likely not worth more code for. For the parent-relation-open-failure case, it seems like we might as well let relation_open throw an error, instead of having an impossible-to-diagnose constraint failure. Back-patch to v11 where this code came in. Discussion:

  • Don't Insert() a VFD entry until it's fully built. Otherwise, if FDDEBUG is enabled, the debugging output fails because it tries to read the fileName, which isn't set up yet (and should in fact always be NULL). AFAICT, this has been wrong since Berkeley. Before 96bf88d52, it would accidentally fail to crash on platforms where snprintf() is forgiving about being passed a NULL pointer for %s; but the file name intended to be included in the debug output wouldn't ever have shown up. Report and fix by Greg Nancarrow. Although this is only visibly broken in custom-made builds, it still seems worth back-patching to all supported branches, as the FDDEBUG code is pretty useless as it stands. Discussion:

  • Further fixes for CREATE TABLE LIKE: cope with self-referential FKs. Commit 502898192 was too careless about the order of execution of the additional ALTER TABLE operations generated by expandTableLikeClause. It just stuck them all at the end, which seems okay for most purposes. But it falls down in the case where LIKE is importing a primary key or unique index and the outer CREATE TABLE includes a FOREIGN KEY constraint that needs to depend on that index. Weird as that is, it used to work, so we ought to keep it working. To fix, make parse_utilcmd.c insert LIKE clauses between index-creation and FK-creation commands in the transformed list of commands, and change utility.c so that the commands generated by expandTableLikeClause are executed immediately not at the end. One could imagine scenarios where this wouldn't work either; but currently expandTableLikeClause only makes column default expressions, CHECK constraints, and indexes, and this ordering seems fine for those. Per bug #16730 from Sofoklis Papasofokli. Like the previous patch, back-patch to all supported branches. Discussion:

  • Remove undocumented IS [NOT] OF syntax. This feature was added a long time ago, in 7c1e67bd5 and eb121ba2c, but never documented in any user-facing way. (Documentation added in 6126d3e70 was commented out almost immediately, in 8272fc3f7.) That's because, while this syntax is defined by SQL:99, our implementation is only vaguely related to the standard's semantics. The standard appears to intend a run-time not parse-time test, and it definitely intends that the test should understand subtype relationships. No one has stepped up to fix that in the intervening years, but people keep coming across the code and asking why it's not documented. Let's just get rid of it: if anyone ever wants to make it work per spec, they can easily recover whatever parts of this code are still of value from our git history. If there's anyone out there who's actually using this despite its undocumented status, they can switch to using pg_typeof() instead, eg. "pg_typeof(something) = 'mytype'::regtype". That gives essentially the same semantics as what our IS OF code did. (We didn't have that function last time this was discussed, or we would have ripped out IS OF then.) Discussion: Discussion: Discussion:

  • On macOS, use -isysroot in link steps as well as compile steps. We previously put the -isysroot switch only into CPPFLAGS, theorizing that it was only needed to find the right copies of include files. However, it seems that we also need to use it while linking programs, to find the right stub ".tbd" files for libraries. We got away without that up to now, but apparently that was mostly luck. It may also be that failures are only observed when the Xcode version is noticeably out of sync with the host macOS version; the case that's prompting action right now is that builds fail when using latest Xcode (12.2) on macOS Catalina, even though it's fine on Big Sur. Hence, add -isysroot to LDFLAGS as well. (It seems that the more common practice is to put it in CFLAGS, whence it'd be included at both compile and link steps. However, we can't mess with CFLAGS in the platform template file without confusing configure's logic for choosing default CFLAGS.) This should be back-patched, but first let's see if the buildfarm likes it on HEAD. Report and patch by James Hilliard (some cosmetic mods by me) Discussion:

  • Extend the geometric regression test cases a little. Add another edge-case value to "point_tbl", and add a test for the line(point, point) function. Some of the behaviors exposed here are wrong, but the idea of committing this separately is to memorialize what we were getting, and to allow easier inspection of the behavior changes caused by upcoming patches. Kyotaro Horiguchi (line() test added by me) Discussion:

  • Fix FPeq() and friends to get the right answers for infinities. "FPeq(infinity, infinity)" returned false, on account of getting NaN when it subtracts the two inputs. Fix that by adding a separate check for exact equality. FPle() and FPge() similarly got the wrong answer for two like-signed infinities. In those cases, we can just rearrange the comparisons to avoid potentially subtracting infinities. While the sibling functions FPne() etc accidentally gave the right answers even with the internal NaN results, it seems best to make similar adjustments to them to avoid depending on this. FPeq() has to be converted to an inline function to avoid double evaluations of its arguments, and I did the same for the others just for consistency. In passing, make the handling of NaN cases in line_eq() and point_eq_point() simpler and easier to reason about, and perhaps faster. This results in just one visible regression test change: slope() now gives DBL_MAX for two inputs of (inf,1e300), which is consistent with what it does for (1e300,inf), so that seems like a bug fix. Discussion:

  • In geo_ops.c, represent infinite slope as Infinity, not DBL_MAX. Since we're assuming IEEE floats these days, there seems little reason not to do this. It has the advantage that when the slope is computed as infinite due to the presence of Inf coordinates, we get saner behavior than before from line_construct(), and thence also in some dependent operations such as finding the closest point. Also fix line_construct() to special-case slope zero. The previous coding got the right answer in most cases, but it could compute C as NaN when the point has Inf coordinates. Discussion:

Michaël Paquier pushed:

  • Relax INSERT privilege requirement for CTAS and matviews WITH NO DATA. When specified, WITH NO DATA does not insert any data into the relation created, so skip checking for the insert permissions. With WITH DATA or WITH NO DATA, it is always required for the user to have CREATE privileges on the schema targeted for the relation. Note that plain CREATE TABLE AS or CREATE MATERIALIZED VIEW queries have begun to work accidentally without INSERT privilege checks as of 874fe3ae, while using EXECUTE or EXPLAIN ANALYZE would fail with the ACL check, so this makes the behavior for all the command flavors consistent with each other. This is arguably a bug fix, but there have been no complaints about the current behavior either so stable branches are not changed. While on it, document properly the privileges requirements for each commands with more tests for all the scenarios possible, and avoid a useless bulk-insert allocation when using WITH NO DATA. Author: Bharath Rupireddy Reviewed-by: Anastasia Lubennikova, Michael Paquier Discussion:

  • Add tab completion for CREATE [OR REPLACE] TRIGGER in psql. 92bf7e2 has added support for this grammar. Author: Noriyoshi Shinoda Discussion:

  • Improve failure detection with array parsing in pg_dump. Similarly to 3636efa, the checks done in pg_dump when parsing array values from catalogs have been too lax. Under memory pressure, it could be possible, though very unlikely, to finish with dumps that miss some data like: - Statistics for indexes - Run-time configuration of functions - Configuration of extensions - Publication list for a subscription No backpatch is done as this is not going to be a problem in practice. For example, if an OOM causes an array parsing to fail, a follow-up code path of pg_dump would most likely complain with an allocation failure due to the memory pressure. Author: Michael Paquier Reviewed-by: Daniel Gustafsson Discussion:

  • Remove INSERT privilege check at table creation of CTAS and matview. As per discussion with Peter Eisentraunt, the SQL standard specifies that any tuple insertion done as part of CREATE TABLE AS happens without any extra ACL check, so it makes little sense to keep a check for INSERT privileges when using WITH DATA. Materialized views are not part of the standard, but similarly, this check can be confusing as this refers to an access check on a table created within the same command as the one that would insert data into this table. This commit removes the INSERT privilege check for WITH DATA, the default, that 846005e removed partially, but only for WITH NO DATA. Author: Bharath Rupireddy Discussion:

Alexander Korotkov pushed:

Fujii Masao pushed:

  • Make the standby server promptly handle interrupt signals. This commit changes the startup process in the standby server so that it handles the interrupt signals after waiting for wal_retrieve_retry_interval on the latch and resetting it, before entering another wait on the latch. This change causes the standby server to promptly handle interrupt signals. Otherwise, previously, there was the case where the standby needs to wait extra five seconds to shutdown when the shutdown request arrived while the startup process was waiting for wal_retrieve_retry_interval on the latch. Author: Fujii Masao, but implementation idea is from Soumyadeep Chakraborty Reviewed-by: Soumyadeep Chakraborty Discussion:

  • Emit log when restore_command succeeds but archived file faills to be restored. Previously, when restore_command claimed to succeed but failed to restore the file with the right name, for example, due to mis-configuration of restore_command, no log message was reported. Then the recovery failed later with an error message not directly related to the issue. This commit changes the recovery so that a log message is emitted in this error case. This would enable us to investigate what happened in this case more easily. Author: Jeff Janes, Fujii Masao Reviewed-by: Pavel Borisov, Kyotaro Horiguchi Discussion:

Peter Eisentraut pushed:

Álvaro Herrera pushed:

Bruce Momjian pushed:

Amit Kapila pushed:

Peter Geoghegan pushed:

  • nbtree: Rename nbtinsert.c variables for consistency. Stop naming special area/opaque pointer variables 'lpageop' in contexts where it doesn't make sense. This is a holdover from a time when logic that performs tasks that are now spread across _bt_insertonpg(), _bt_findinsertloc(), and _bt_split() was more centralized. 'lpageop' denotes "left page", which doesn't make sense outside of contexts in which there isn't also a right page. Also acquire page flag variables up front within _bt_insertonpg(). This makes it closer to _bt_split() following refactoring commit bc3087b626d. This allows the page split and retail insert paths to both make use of the same variables.

  • Deprecate nbtree's BTP_HAS_GARBAGE flag. Streamline handling of the various strategies that we have to avoid a page split in nbtinsert.c. When it looks like a leaf page is about to overflow, we now perform deleting LP_DEAD items and deduplication in one central place. This greatly simplifies _bt_findinsertloc(). This has an independently useful consequence: nbtree no longer relies on the BTP_HAS_GARBAGE page level flag/hint for anything important. We still set and unset the flag in the same way as before, but it's no longer treated as a gating condition when considering if we should check for already-set LP_DEAD bits. This happens at the point where the page looks like it might have to be split anyway, so simply checking the LP_DEAD bits in passing is practically free. This avoids missing LP_DEAD bits just because the page-level hint is unset, which is probably reasonably common (e.g. it happens when VACUUM unsets the page-level flag without actually removing index tuples whose LP_DEAD-bit was set recently, after the VACUUM operation began but before it reached the leaf page in question). Note that this isn't a big behavioral change compared to PostgreSQL 13. We were already checking for set LP_DEAD bits regardless of whether the BTP_HAS_GARBAGE page level flag was set before we considered doing a deduplication pass. This commit only goes slightly further by doing the same check for all indexes, even indexes where deduplication won't be performed. We don't completely remove the BTP_HAS_GARBAGE flag. We still rely on it as a gating condition with pg_upgrade'd indexes from before B-tree version 4/PostgreSQL 12. That makes sense because we sometimes have to make a choice among pages full of duplicates when inserting a tuple with pre version 4 indexes. It probably still pays to avoid accessing the line pointer array of a page there, since it won't yet be clear whether we'll insert on to the page in question at all, let alone split it as a result. Author: Peter Geoghegan Reviewed-By: Victor Yegorov Discussion:

Heikki Linnakangas pushed:

Thomas Munro pushed:

Magnus Hagander pushed:

  • Remove ability to independently select random number generator. Remove the ability to select random number generator independently from SSL library. Instead, use the random number generator from the SSL library (today only OpenSSL supported) if one is configured. If no SSL library is configured, use the platform default (which means use CryptoAPI on Win32 and /dev/urandom on Linux). This also restructures pg_strong_random.c to have three clearly separate sections, one for each implementation, with two functions in each, instead of a scattered set of ifdefs throughout the whole file. Author: Daniel Gustafsson, Magnus Hagander, Michael Paquier Discussion:

Pending Patches

Atsushi Torikoshi sent in another revision of a patch to Enabled pg_get_backend_memory_contexts() to collect arbitrary backend process's memory contexts. Previously, pg_get_backend_memory_contexts() could only get the local memory contexts. This patch enables to get memory contexts of the arbitrary backend process which PID is specified by the argument.

Tomáš Vondra sent in two revisions of a patch to support extended statistics on expressions.

Seino Yuki and Fujii Masao traded patches to add a new pg_stat_statements_info view to the pg_stat_statements extension.

Jacob Champion and Daniel Gustafsson traded patches to support NSS as a TLS backend for libpq.

Alexandra Pervushina sent in two more revisions of a patch to make it possible to make async replicas wait for lsn to be replayed.

Álvaro Herrera and Dmitry Dolgov traded patches to remove a spurious wait from CREATE INDEX CONCURRENTLY.

Thomas Munro sent in two revisions of a patch to track relation sizes in shared memory, and provide a lock-free fast path for smgrnblocks().

Masahiro Ikeda sent in another revision of a patch to add a track_wal_io_timing GUC and a matching pg_stat_wal view to back it.

Li Japin sent in four more revisions of a patch to make it possible to terminate idle sessions using a new GUC, idle_session_timeout, and in passing, call setitimer() less often.

Masahiko Sawada and Bertrand Drouvot traded patches to add information during standby recovery conflicts, controlled with a new GUC, log_recovery_conflict_waits.

Takamichi Osumi sent in two more revisions of a patch to make it possible to disallow WAL logging during data loads.

Simon Riggs sent in five revisions of a patch to fix a situation where the documented behavior of DISABLE_PAGE_SKIPPING doesn't match the current behavior.

Ajin Cherian and Amit Kapila traded patches to implement logical decoding of two-phase transactions.

Tatsuro Yamada sent in two more revisions of a patch to add a psql command for extended statistics, \dX.

Daniel Gustafsson sent in another revision of a patch to support enabling and disabling page checksums in a running cluster.

Justin Pryzby sent in a patch to allow composite types in bootstrap and add a column to pg_statistic_ext_data, stxdexpr.

Peter Geoghegan sent in another revision of a patch to delete older versions in unique indexes to avoid page splits.

Heikki Linnakangas sent in another revision of a patch to split copy.c into four files: copy.c, which now contains the functions that are common to COPY FROM and COPY TO, copyto.c, which contains code for COPY TO, copyfrom.c which contains code for initilizing COPY FROM, and routing tuples to the correct table, and copyfromparse.c, which contains code for reading from the client/file/program, and parsing the input text/CSV/binary format into tuples.

David G. Johnston sent in another revision of a patch to clarify the fact that signal functions have no feedback.

Simon Riggs sent in a patch to add a wal_sessioninfo GUC which when turned on adds information about the user's session onto every commit or abort record.

David G. Johnston sent in a patch to clarify the documentation for batch/pipelining support in libpq.

Dean Rasheed sent in another revision of a patch to improve estimation of OR clauses.

Heikki Linnakangas sent in a patch to make the ResourceOwner implementation more efficient and expose handier interfaces to it to external code.

Aleksey Kondratov sent in a patch to add a custom GUC to the PostgreSQL FDW which controls whether it tries to keep connections, with the surprising name of keep_connections.

Takayuki Tsunakawa and Tomáš Vondra traded patches to implement INSERT batching for the PostgreSQL FDW.

Justin Pryzby and Pavel Stěhule traded patches to add a --filter option to pg_dump, which draws from a file which specifies the filters to be used, and makes argument parsing available both to the command line and to files so described.

Bharath Rupireddy sent in another revision of a patch to use standard SIGHUP and SIGTERM handlers in the autoprewarm module.

Etsuro Fujita sent in another revision of a patch to enable Asynchronous Append on postgres_fdw nodes.

Tomáš Vondra sent in a patch to fix a bug that manifested as incremental sort changing query behavior by adding a check for is_parallel_safe to get_useful_pathkeys_for_relation().

David Pirotte sent in another revision of a patch to add xid to messages when streaming, and add a "messages" option to the pgoutput output plugin. When "messages" is true, logical decoding messages (i.e. generated via pg_logical_emit_message) are sent to the slot consumer.

Junfeng (Jerome) Yang sent in another revision of a patch to fix vacuum freeze with pg_database toast attribute by changing vac_update_datfrozenxid()'s source for the pg_database tuple for current database from the disk heap table instead of system cache.

Dmitry Dolgov sent in a patch to prevent jumbling of every element in ArrayExpr. The motivation for this is that pg_stat_statements produces multiple entries for queries like SELECT something FROM table WHERE col IN (1, 2, 3, ...) depending on number of parameters, because every element of ArrayExpr is jumbled. Make Consts contribute nothing to the jumble hash if they're part of a series and at position further that specified threshold. Do the same for similar queries with VALUES as well.

Thomas Munro sent in another revision of a patch to implement WAL prefetch.

Andrew Dunstan sent in another revision of a patch to allow matching the whole DN from a client certificate.

Pavel Stěhule sent in two revisions of a patch to add shorthand for argument and local variable references to PL/pgsql.

Atsushi Torikoshi sent in two revisions of a patch to document the fact that cached plans are invalidated when statistics used to create them are updated.

Atsushi Torikoshi sent in two revisions of a patch to update the PREPARE documentation to note that pg_prepared_statements now shows how many times each prepared statement chose generic and custom plan cumulatively in the current session.

Vigneshwaran C sent in another revision of a patch to parallelize COPY.

Thomas Munro sent in another revision of a patch to minimize latch signals.

Masahiro Ikeda sent in another revision of a patch to add statistics to pg_stat_wal view for wal related parameter tuning.

Craig Ringer sent in a patch to detect and report when a LWLockAcquire() results in a simple self-deadlock due to the caller already holding the LWLock..

Craig Ringer sent in a patch to Remove bogus lwlock__acquire tracepoint from LWLockWaitForVar, pass the target LWLock* and tranche ID to LWLock tracepoint, and add to the tracepoints in LWLock routines.

Heikki Linnakangas sent in another revision of a patch to move peragg and pertrans duplicate finding to prepagg.c.

Craig Ringer sent in a patch atop the resource owner refactoring patch above which adds some systemtap/dtrace tracepoints and provides a demo systemtap script that shows some basic stats collection done using them.

Surafel Temesgen sent in another revision of a patch to implement system versioned temporal tables.

Justin Pryzby sent in two more revisions of a patch to avoid errors in brin summarization, which can happen if an index is reindexed concurrently.

Li Japin sent in a patch to use macros for calculating LWLock offset.

Kyotaro HORIGUCHI sent in another revision of a patch to implement CatCache expiration.

Peter Eisentraut sent in another revision of a patch to add support for writing CREATE FUNCTION and CREATE PROCEDURE statements for language SQL with a function body that conforms to the SQL standard.

Greg Nancarrow sent in another revision of a patch to enable parallel SELECT for "INSERT INTO ... SELECT ..." along with parallel INSERT and/or SELECT for "INSERT INTO ... SELECT ...", where it is safe to do so.

Amit Langote sent in a patch to create foreign key triggers in partitioned tables too in order to allow subsequent commit(s) to make the foreign key related events to be fired in some cases using the parent table triggers instead of those of partitions', and enforce foreign key correctly during cross-partition updates.

Laurenz Albe sent in another revision of a patch to add session statistics to pg_stat_database.

Justin Pryzby sent in another revision of a patch to pg_restore so it parses and runs separately SQL commands, and allow child partitions to be independently restored even if the parent doesn't exist, or has missing/incompatible columns.

Peter Eisentraut sent in another revision of a patch to pause recovery for insufficient parameter settings.

Peter Eisentraut sent in another revision of a patch to add support for abstract Unix-domain sockets, and make the error hint from bind() failure more accurate by showing that hint only when errno == EADDRINUSE.

Matthias van de Meent sent in a patch to Fix CLUSTER progress reporting of number of blocks scanned.

Stephen Frost sent in a patch to replace the somewhat inaccurate "default role" term with the more precise "predefined role."

Erik Rijkers sent in a patch atop the patch to add a tutorial chapter on architecture to fix some typos and do other wordsmithing.

Bharath Rupireddy sent in another revision of a patch to avoid checking INSERT privilege in CTAS and MatView in order to comply with the standard.

Gilles Darold sent in two revisions of a patch to add a hook for plugins to get control of at end of AbortCurrentTransaction, and an extension to enable statement-level rollback based on same.

Krasiyan Andreev sent in another revision of a patch to implement <null treatment> for window functions.

Álvaro Herrera sent in a patch to fix a bug in pageinspect which manifests as messages along the lines of ERROR: invalid memory alloc request size 18446744073709551451 when pages are sufficiently broken. The fix is not to attempt to print the data rather than dying.

Justin Pryzby sent in another revision of a patch to retire pg_standby.

Michaël Paquier sent in two more revisions of a patch to remove currtid() and currtid2(), cleaning up some table AMs in the process.

James Coleman sent in a patch to enforce parallel safety of pathkeys in generate_useful_gather_paths, and ensure that generate_useful_gather_paths doesn't skip unsorted subpaths.

Vigneshwaran C sent in a PoC patch to which would make it possible to get the call stack of a PostgreSQL process by connecting to the server.

Tom Lane sent in a patch to make the "cannot insert" message be more precise about the fact that the reason is that non-default values can never be inserted.