postgresql.git
20 months agoReport syncscan position at end of scan.
Heikki Linnakangas [Thu, 31 Aug 2023 10:02:15 +0000 (13:02 +0300)]
Report syncscan position at end of scan.

The comment in heapgettup_advance_block() says that it reports the
scan position before checking for end of scan, but that didn't match
the code. The code was refactored in commit 7ae0ab0ad9, which
inadvertently changed the order of the check and reporting. Change it
back.

This caused a few regression test failures with a small shared_buffers
setting like 10 MB. The 'portals' and 'cluster' tests perform seqscans
that are large enough that sync seqscans kick in. When the sync scan
position is not updated at end of scan, the next seq scan doesn't
start at the beginning of the table, and the test queries are
sensitive to that.

Reviewed-by: Melanie Plageman, David Rowley
Discussion: https://www.postgresql.org/message-id/6f991389-ae22-d844-a9d8-9aceb7c01a9a@iki.fi
Backpatch-through: 16

20 months agoCorrect ObjectProperty entry for transforms
Peter Eisentraut [Thu, 31 Aug 2023 09:11:59 +0000 (11:11 +0200)]
Correct ObjectProperty entry for transforms

There was some confusion in the ObjectProperty entry for transforms.
Some fields had values that were apparently meant for a different
field.  Also, some fields were not assigned, which is okay for most
fields, but not for all.  In particular, for .oid_catcache_id,
.name_catcache_id, and .objtype, zero is a valid value, so we need to
use -1 if not applicable.  It has apparently been like that from the
very beginning (commit cac7658205).  The faulty values were not
actually reachable, so it's not a big problem in practice, but we
should make it correct.

Discussion: https://www.postgresql.org/message-id/flat/75ae5875-3abc-dafc-8aec-73247ed41cde@eisentraut.org

20 months agogenbki.pl: Factor out boilerplate generation
Peter Eisentraut [Thu, 31 Aug 2023 08:21:34 +0000 (10:21 +0200)]
genbki.pl: Factor out boilerplate generation

Discussion: https://www.postgresql.org/message-id/flat/75ae5875-3abc-dafc-8aec-73247ed41cde@eisentraut.org

20 months agoRestructure DECLARE_INDEX arguments
Peter Eisentraut [Thu, 31 Aug 2023 06:14:57 +0000 (08:14 +0200)]
Restructure DECLARE_INDEX arguments

Separate the table name from the index declaration.  We need that
anyway later for the ALTER TABLE / USING INDEX commands, so we might
as well structure the declarations like that to begin with.

Discussion: https://www.postgresql.org/message-id/flat/75ae5875-3abc-dafc-8aec-73247ed41cde@eisentraut.org

20 months agoFix some shadow variables in src/backend/replication/
Michael Paquier [Wed, 30 Aug 2023 23:07:48 +0000 (08:07 +0900)]
Fix some shadow variables in src/backend/replication/

The code is able to compile already without warnings under
-Wshadow=compatible-local, which is itself already enabled in the tree,
and the ones fixed here showed up with the more restrictive -Wshadow.

There are more of these that we may want to look at, and the ones fixed
here made the code confusing.

Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+PuR0y4ofNOxi691VTVWmBfScHV9AaBMGSpeh8+DKp81Nw@mail.gmail.com

20 months agoUse actual backend IDs in pg_stat_get_backend_subxact().
Nathan Bossart [Wed, 30 Aug 2023 21:47:01 +0000 (14:47 -0700)]
Use actual backend IDs in pg_stat_get_backend_subxact().

Unlike the other pg_stat_get_backend* functions,
pg_stat_get_backend_subxact() looks up the backend entry by using
its integer argument as a 1-based index in an internal array.  The
other functions look for the entry with the matching session
backend ID.  These numbers often match, but that isn't reliably
true.

This commit resolves this discrepancy by introducing
pgstat_get_local_beentry_by_backend_id() and using it in
pg_stat_get_backend_subxact().  We cannot use
pgstat_get_beentry_by_backend_id() because it returns a
PgBackendStatus, which lacks the locally computed additions
available in LocalPgBackendStatus that are required by
pg_stat_get_backend_subxact().

Author: Ian Barwick
Reviewed-by: Sami Imseih, Michael Paquier, Robert Haas
Discussion: https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.com
Backpatch-through: 16

20 months agoRename some support functions for pgstat* views.
Nathan Bossart [Wed, 30 Aug 2023 21:46:52 +0000 (14:46 -0700)]
Rename some support functions for pgstat* views.

Presently, pgstat_fetch_stat_beentry() accepts a session's backend
ID as its argument, and pgstat_fetch_stat_local_beentry() accepts a
1-based index in an internal array as its argument.  The former is
typically used wherever a user must provide a backend ID, and the
latter is usually used internally when looping over all entries in
the array.  This difference was first introduced by d7e39d72ca.
Before that commit, both functions accepted a 1-based index to the
internal array.

This commit renames these two functions to make it clear whether
they use the backend ID or the 1-based index to look up the entry.
This is preparatory work for a follow-up change that will introduce
a function for looking up a LocalPgBackendStatus using a backend
ID.

Reviewed-by: Ian Barwick, Sami Imseih, Michael Paquier, Robert Haas
Discussion: https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.com
Backpatch-through: 16

20 months agoFix possible compiler warning
Peter Eisentraut [Wed, 30 Aug 2023 14:20:44 +0000 (16:20 +0200)]
Fix possible compiler warning

related to 1fa9241bdd

20 months agoDoc: Improve documentation for creating custom scan paths.
Etsuro Fujita [Wed, 30 Aug 2023 08:45:00 +0000 (17:45 +0900)]
Doc: Improve documentation for creating custom scan paths.

This improves the documentation related to parallel query a little bit.

Reviewed by Richard Guo.

Discussion: https://postgr.es/m/CAPmGK159eJShAR4ek4Db8oHD4%2BZ18zwJkisEWkqRN-80BdDGFQ%40mail.gmail.com

20 months agopostgres_fdw: Fix test for parameterized foreign scan.
Etsuro Fujita [Wed, 30 Aug 2023 08:15:00 +0000 (17:15 +0900)]
postgres_fdw: Fix test for parameterized foreign scan.

Commit e4106b252 should have updated this test, but did not; back-patch
to all supported branches.

Reviewed by Richard Guo.

Discussion: http://postgr.es/m/CAPmGK15nR0NXLSCKQAcqbZbTzrzd5MozowWnTnGfPkayndF43Q%40mail.gmail.com

20 months agoAdd bc6041b61f to .git-blame-ignore-revs.
Tatsuo Ishii [Wed, 30 Aug 2023 07:06:12 +0000 (16:06 +0900)]
Add bc6041b61f to .git-blame-ignore-revs.

20 months agoFix code indentation vioaltion introduced in commit 3c662643c4.
Tatsuo Ishii [Wed, 30 Aug 2023 06:56:22 +0000 (15:56 +0900)]
Fix code indentation vioaltion introduced in commit 3c662643c4.

Per buildfarm member koel

20 months agoFix misuse of PqMsg_Close.
Nathan Bossart [Wed, 30 Aug 2023 01:32:38 +0000 (18:32 -0700)]
Fix misuse of PqMsg_Close.

EndCommand() and EndReplicationCommand() should use
PqMsg_CommandComplete instead.  Oversight in commit f4b54e1ed9.

Reported-by: Pavel Stehule, Tatsuo Ishii
Author: Pavel Stehule
Reviewed-by: Aleksander Alekseev, Michael Paquier
Discussion: https://postgr.es/m/CAFj8pRAMDCJXjnwiCkCB1yO1f7NPggFY8PwwAJDnugu-Z2G-Cg%40mail.gmail.com

20 months agoAllow pgbench to exit immediately when any client is aborted.
Tatsuo Ishii [Wed, 30 Aug 2023 01:03:31 +0000 (10:03 +0900)]
Allow pgbench to exit immediately when any client is aborted.

Previously when client was aborted due to some error during
benchmarking, other clients continued their run until certain number
of transactions specified -t was reached or the time specified by -T
was expired. At the end, the results are printed with caution: "Run
was aborted; the above results are incomplete" shows.

New option "--exit-on-abort" allows pgbench to exit immediately in
this case so that users could quickly fix the cause of the failure and
try again another round of benchmarking.

Author: Yugo Nagata
Reviewed-by: Fabien COELHO, Tatsuo Ishii
Discussion: https://postgr.es/m/flat/20230804130325.df32e60879c38c92bca64207%40sraoss.co.jp

20 months agoFix comment of PQputCopyEnd()
Michael Paquier [Tue, 29 Aug 2023 23:29:08 +0000 (08:29 +0900)]
Fix comment of PQputCopyEnd()

The comment describing the error codes of this routine mentioned 0 as a
possible value, but this error code has never been used.

Author: Junwang Zhao
Reviewed-by: Aleksander Alekseev
Discussion: https://postgr.es/m/CAEG8a3Jt5KwMNr+_S6VN68rog4HeoG6ELvPQO8kZNQTeJeQ=rQ@mail.gmail.com

20 months agoAvoid possible overflow with ltsGetFreeBlock() in logtape.c
Michael Paquier [Tue, 29 Aug 2023 23:03:42 +0000 (08:03 +0900)]
Avoid possible overflow with ltsGetFreeBlock() in logtape.c

nFreeBlocks, defined as a long, stores the number of free blocks in a
logical tape.  ltsGetFreeBlock() has been using an int to store the
value of nFreeBlocks, which could lead to overflows on platforms where
long and int are not the same size (in short everything except Windows
where long is 4 bytes).

The problematic intermediate variable is switched to be a long instead
of an int.

Issue introduced by c02fdc9223015, so backpatch down to 13.

Author: Ranier vilela
Reviewed-by: Peter Geoghegan, David Rowley
Discussion: https://postgr.es/m/CAEudQApLDWCBR_xmwNjGBrDo+f+S4E87x3s7-+hoaKqYdtC4JQ@mail.gmail.com
Backpatch-through: 13

20 months agoDisallow changing NO INHERIT status of a not-null constraint
Alvaro Herrera [Tue, 29 Aug 2023 17:19:24 +0000 (19:19 +0200)]
Disallow changing NO INHERIT status of a not-null constraint

It makes no sense to add a NO INHERIT not-null constraint to a child
table that already has one in that column inherited from its parent.
Disallow that, and add tests for the relevant cases.

Per complaint from Kyotaro Horiguchi.  I also used part of his proposed
patch.

Co-authored-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/20230828.161658.1184657435220765047.horikyota.ntt@gmail.com

20 months agoPerl: Remove useless lines
Alvaro Herrera [Tue, 29 Aug 2023 16:25:09 +0000 (18:25 +0200)]
Perl: Remove useless lines

20 months agopsql/t/001_basic: use locale-aware decimals in new test
Alvaro Herrera [Tue, 29 Aug 2023 16:13:11 +0000 (18:13 +0200)]
psql/t/001_basic: use locale-aware decimals in new test

As cd82e5c79d14 did.  Otherwise, the test fails in locales that use
decimal separators other than ".".

20 months agoGenerate a locale-agnostic initdb template
Alvaro Herrera [Tue, 29 Aug 2023 16:06:55 +0000 (18:06 +0200)]
Generate a locale-agnostic initdb template

Fixup for 252dcb32397f.

Without this, the "template" data directory created in the initial test
steps uses a non-C locale, upsetting numerous tests that rely on parsing
English error messages.

Discussion: https://postgr.es/m/CAFj8pRB=XVWC0orWu0FbjrmyOpAMLqJiau80YyQOYQPfMj8Xxw@mail.gmail.com

20 months agoRename logical_replication_mode to debug_logical_replication_streaming
Peter Eisentraut [Tue, 29 Aug 2023 13:15:54 +0000 (15:15 +0200)]
Rename logical_replication_mode to debug_logical_replication_streaming

The logical_replication_mode GUC is intended for testing and debugging
purposes, but its current name may be misleading and encourage users to make
unnecessary changes.

To avoid confusion, renaming the GUC to a less misleading name
debug_logical_replication_streaming that casual users are less likely to mistakenly
assume needs to be modified in a regular logical replication setup.

Author: Hou Zhijie <houzj.fnst@cn.fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/d672d774-c44b-6fec-f993-793e744f169a%40eisentraut.org

20 months agoAllow \watch queries to stop on minimum rows returned
Daniel Gustafsson [Tue, 29 Aug 2023 09:30:11 +0000 (11:30 +0200)]
Allow \watch queries to stop on minimum rows returned

When running a repeat query with \watch in psql, it can be
helpful to be able to stop the watch process when the query
no longer returns the expected amount of rows.  An example
would be to watch for the presence of a certain event in
pg_stat_activity and stopping when the event is no longer
present, or to watch an index creation and stop when the
index is created.

This adds a min_rows=MIN parameter to \watch which can be
set to a non-negative integer, and the watch query will
stop executing when it returns less than MIN rows.

Author: Greg Sabino Mullane <htamfids@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CAKAnmmKStATuddYxP71L+p0DHtp9Rvjze3XRoy0Dyw67VQ45UA@mail.gmail.com

20 months agoReword user-facing message for "power of two"
Daniel Gustafsson [Tue, 29 Aug 2023 09:21:10 +0000 (11:21 +0200)]
Reword user-facing message for "power of two"

While there are numerous instances of using "power of 2" in the code,
translated user-facing messages use "power of two". Fix two instances
which used "power of 2" instead.

Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/20230829.175615.682972421946735863.horikyota.ntt@gmail.com

20 months agoRemove useless if condition
Peter Eisentraut [Tue, 29 Aug 2023 06:58:56 +0000 (08:58 +0200)]
Remove useless if condition

We can call GetAttributeCompression() with a NULL argument.  It
handles that internally already.  This change makes all the callers of
GetAttributeCompression() uniform.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org

20 months agoRemove useless if condition
Peter Eisentraut [Tue, 29 Aug 2023 06:52:22 +0000 (08:52 +0200)]
Remove useless if condition

This is useless because these fields are not set anywhere before, so
we can assign them unconditionally.  This also makes this more
consistent with ATExecAddColumn().

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org

20 months agoMake more use of makeColumnDef()
Peter Eisentraut [Tue, 29 Aug 2023 06:41:04 +0000 (08:41 +0200)]
Make more use of makeColumnDef()

Since we already have it, we might as well make full use of it,
instead of assembling ColumnDef by hand in several places.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org

20 months agoAdd some const decorations
Peter Eisentraut [Tue, 29 Aug 2023 06:30:45 +0000 (08:30 +0200)]
Add some const decorations

Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da@eisentraut.org

20 months agoInitialize ListenSocket array earlier.
Heikki Linnakangas [Tue, 29 Aug 2023 06:09:40 +0000 (09:09 +0300)]
Initialize ListenSocket array earlier.

After commit b0bea38705, syslogger prints 63 warnings about failing to
close a listen socket at postmaster startup. That's because the
syslogger process forks before the ListenSockets array is initialized,
so ClosePostmasterPorts() calls "close(0)" 64 times. The first call
succeeds, because fd 0 is stdin.

This has been like this since commit 9a86f03b4e in version 13, which
moved the SysLogger_Start() call to before initializing ListenSockets.
We just didn't notice until commit b0bea38705 added the LOG message.

Reported by Michael Paquier and Jeff Janes.

Author: Michael Paquier
Discussion: https://www.postgresql.org/message-id/ZOvvuQe0rdj2slA9%40paquier.xyz
Discussion: https://www.postgresql.org/message-id/ZO0fgDwVw2SUJiZx@paquier.xyz#482670177eb4eaf4c9f03c1eed963e5f
Backpatch-through: 13

20 months agoTweak pg_promote() to report failures on kill() or postmaster failures
Michael Paquier [Mon, 28 Aug 2023 23:45:04 +0000 (08:45 +0900)]
Tweak pg_promote() to report failures on kill() or postmaster failures

Since its introduction in 10074651e335, pg_promote() has been returning
a false status in three cases:
- SIGUSR1 not sent to the postmaster process.
- Postmaster death during standby promotion.
- Standby not promoted within the specified wait time.

An application calling this function will have a hard time understanding
what a false state returned actually means.

Per discussion, this switches the two first states to fail rather than
return a "false" status, making the second case more consistent with the
existing CHECK_FOR_INTERRUPTS in the wait loop.  False is only returned
when the promotion is not completed within the specified time (60s by
default).

Author: Ashutosh Sharma
Reviewed-by: Fujii Masao, Laurenz Albe, Michael Paquier
Discussion: https://postgr.es/m/CAE9k0P=QTrwptL0t4J0fuBRDDjgsT-0PVKd-ikd96i1hyL7Bcg@mail.gmail.com

20 months agoMake error messages about WAL segment size more consistent
Peter Eisentraut [Mon, 28 Aug 2023 13:15:20 +0000 (15:15 +0200)]
Make error messages about WAL segment size more consistent

Make the primary messages more compact and make the detail messages
uniform.  In initdb.c and pg_resetwal.c, use the newish
option_parse_int() to simplify some of the option parsing.  For the
backend GUC wal_segment_size, add a GUC check hook to do the
verification instead of coding it in bootstrap.c.  This might be
overkill, but that way the check is in the right place and it becomes
more self-documenting.

In passing, make pg_controldata use the logging API for warning
messages.

Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://www.postgresql.org/message-id/flat/9939aa8a-d7be-da2c-7715-0a0b5535a1f7@eisentraut.org

20 months agoFix some typos in wait_event_names.txt
Michael Paquier [Mon, 28 Aug 2023 08:09:12 +0000 (17:09 +0900)]
Fix some typos in wait_event_names.txt

Noticed in passing, while hacking on a different patch touching this
area.

20 months agoConvert encrypted SSL test keys to PKCS#8 format
Peter Eisentraut [Tue, 22 Aug 2023 07:26:36 +0000 (09:26 +0200)]
Convert encrypted SSL test keys to PKCS#8 format

OpenSSL in FIPS mode rejects several encrypted private keys used in
the test suites ssl and ssl_passphrase_callback.  This is because they
are in a "traditional" OpenSSL format that uses MD5 for key
generation.  The fix is to convert them to the more standard PKCS#8
format that uses SHA1 for key derivation.

This commit contains the converted keys, with the conversion done like
this:

openssl pkcs8 -topk8 -in src/test/modules/ssl_passphrase_callback/server.key -passin pass:FooBaR1 -out src/test/modules/ssl_passphrase_callback/server.key.new -passout pass:FooBaR1
mv src/test/modules/ssl_passphrase_callback/server.key.new src/test/modules/ssl_passphrase_callback/server.key

etc., as well as updated build rules to generate the keys in the new
format if they need to be regenerated.

Reviewed-by: Jacob Champion <jchampion@timescale.com>
Discussion: https://www.postgresql.org/message-id/flat/64de784b-8833-e055-3bd4-7420e6675351%40eisentraut.org

20 months agoTighten unit parsing in internal values
Michael Paquier [Mon, 28 Aug 2023 05:27:17 +0000 (14:27 +0900)]
Tighten unit parsing in internal values

Interval values now generate an error when the user has multiple
consecutive units or a unit without a value.  Previously, it was
possible to specify multiple units consecutively which is contrary to
what the documentation allows, so it was possible to finish with
confusing interval values.

This is a follow-up of the work done in 165d581f146b.

Author: Joseph Koshakow
Reviewed-by: Jacob Champion, Gurjeet Singh, Reid Thompson
Discussion: https://postgr.es/m/CAAvxfHd-yNO+XYnUxL=GaNZ1n+eE0V-oE0+-cC1jdjdU0KS3iw@mail.gmail.com

20 months agoTighten handling of "ago" in interval values
Michael Paquier [Mon, 28 Aug 2023 04:49:55 +0000 (13:49 +0900)]
Tighten handling of "ago" in interval values

This commit Restrict the unit "ago" to only appear at the end of the
interval.  According to the documentation, a direction can only be
defined at the end of an interval, but it was possible to define it in
the middle of the string or define it multiple times.

In spirit, this is similar to the error handling improvements done in
5b3c5953553b or bcc704b524904.

Author: Joseph Koshakow
Reviewed-by: Jacob Champion, Gurjeet Singh, Reid Thompson
Discussion: https://postgr.es/m/CAAvxfHd-yNO+XYnUxL=GaNZ1n+eE0V-oE0+-cC1jdjdU0KS3iw@mail.gmail.com

20 months agoFormat list of catalog files in makefile vertically
Peter Eisentraut [Mon, 28 Aug 2023 04:18:39 +0000 (06:18 +0200)]
Format list of catalog files in makefile vertically

This makes it easier to compare the lists visually with the
corresponding meson lists.

In passing, copy over some relevant comments from the makefiles to
meson.build.

Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/a306be82-ee71-4554-d499-49a45a654396%40eisentraut.org

20 months agoRemove dead code in DecodeInterval()
Michael Paquier [Mon, 28 Aug 2023 03:53:41 +0000 (12:53 +0900)]
Remove dead code in DecodeInterval()

This commit removes some dead code related to the unit type RESERV,
whose last use has been removed from the unit lookup table used for
intervals ("deltatktbl" in datetime.c) in 666cbae16da4.  Before that,
RESERV was used as an equivalent of "invalid", but that's now
unreachable.

Author: Joseph Koshakow
Reviewed-by: Jacob Champion, Gurjeet Singh, Reid Thompson
Discussion: https://postgr.es/m/CAAvxfHd-yNO+XYnUxL=GaNZ1n+eE0V-oE0+-cC1jdjdU0KS3iw@mail.gmail.com

20 months agoShow names of DEALLOCATE as constants in pg_stat_statements
Michael Paquier [Sun, 27 Aug 2023 08:27:44 +0000 (17:27 +0900)]
Show names of DEALLOCATE as constants in pg_stat_statements

This commit switches query jumbling so as prepared statement names are
treated as constants in DeallocateStmt.  A boolean field is added to
DeallocateStmt to make a distinction between ALL and named prepared
statements, as "name" was used to make this difference before, NULL
meaning DEALLOCATE ALL.

Prior to this commit, DEALLOCATE was not tracked in pg_stat_statements,
for the reason that it was not possible to treat its name parameter as a
constant.  Now that query jumbling applies to all the utility nodes,
this reason does not apply anymore.

Like 638d42a3c520, this can be a huge advantage for monitoring where
prepared statement names are randomly generated, preventing bloat in
pg_stat_statements.  A couple of tests are added to track the new
behavior.

Author: Dagfinn Ilmari Mannsåker, Michael Paquier
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/ZMhT9kNtJJsHw6jK@paquier.xyz

20 months agoGenerate new LOG for "trust" connections under log_connections
Michael Paquier [Sat, 26 Aug 2023 11:11:19 +0000 (20:11 +0900)]
Generate new LOG for "trust" connections under log_connections

Adding an extra LOG for connections that have not set an authn ID, like
when the "trust" authentication method is used, is useful for audit
purposes.

A couple of TAP tests for SSL and authentication need to be tweaked to
adapt to this new LOG generated, as some scenarios expected no logs but
they now get a hit.

Reported-by: Shaun Thomas
Author: Jacob Champion
Reviewed-by: Robert Haas, Michael Paquier
Discussion: https://postgr.es/m/CAFdbL1N7-GF-ZXKaB3XuGA+CkSmnjFvqb8hgjMnDfd+uhL2u-A@mail.gmail.com

20 months agoAvoid non-POSIX cp flags
Andres Freund [Fri, 25 Aug 2023 13:43:37 +0000 (06:43 -0700)]
Avoid non-POSIX cp flags

Commit 252dcb32 used cp -a, but apparently Solaris doesn't like that.  Use cp
-RPp instead.

Author: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CA+hUKGL10AoQVMMqgOJ8CTjoz9MLidD8ik2e8PibzLNMz0+aRg@mail.gmail.com

20 months agoRename test table to avoid cs_CZ locale problem
Alvaro Herrera [Fri, 25 Aug 2023 12:06:13 +0000 (14:06 +0200)]
Rename test table to avoid cs_CZ locale problem

Per buildfarm member Hippopotamus

20 months agoCatalog not-null constraints
Alvaro Herrera [Fri, 25 Aug 2023 11:31:24 +0000 (13:31 +0200)]
Catalog not-null constraints

We now create contype='n' pg_constraint rows for not-null constraints.

We propagate these constraints to other tables during operations such as
adding inheritance relationships, creating and attaching partitions and
creating tables LIKE other tables.  We also spawn not-null constraints
for inheritance child tables when their parents have primary keys.
These related constraints mostly follow the well-known rules of
conislocal and coninhcount that we have for CHECK constraints, with some
adaptations: for example, as opposed to CHECK constraints, we don't
match not-null ones by name when descending a hierarchy to alter it,
instead matching by column name that they apply to.  This means we don't
require the constraint names to be identical across a hierarchy.

For now, we omit them for system catalogs.  Maybe this is worth
reconsidering.  We don't support NOT VALID nor DEFERRABLE clauses
either; these can be added as separate features later (this patch is
already large and complicated enough.)

psql shows these constraints in \d+.

pg_dump requires some ad-hoc hacks, particularly when dumping a primary
key.  We now create one "throwaway" not-null constraint for each column
in the PK together with the CREATE TABLE command, and once the PK is
created, all those throwaway constraints are removed.  This avoids
having to check each tuple for nullness when the dump restores the
primary key creation.

pg_upgrading from an older release requires a somewhat brittle procedure
to create a constraint state that matches what would be created if the
database were being created fresh in Postgres 17.  I have tested all the
scenarios I could think of, and it works correctly as far as I can tell,
but I could have neglected weird cases.

This patch has been very long in the making.  The first patch was
written by Bernd Helmle in 2010 to add a new pg_constraint.contype value
('n'), which I (Álvaro) then hijacked in 2011 and 2012, until that one
was killed by the realization that we ought to use contype='c' instead:
manufactured CHECK constraints.  However, later SQL standard
development, as well as nonobvious emergent properties of that design
(mostly, failure to distinguish them from "normal" CHECK constraints as
well as the performance implication of having to test the CHECK
expression) led us to reconsider this choice, so now the current
implementation uses contype='n' again.  During Postgres 16 this had
already been introduced by commit e056c557aef4, but there were some
problems mainly with the pg_upgrade procedure that couldn't be fixed in
reasonable time, so it was reverted.

In 2016 Vitaly Burovoy also worked on this feature[1] but found no
consensus for his proposed approach, which was claimed to be closer to
the letter of the standard, requiring an additional pg_attribute column
to track the OID of the not-null constraint for that column.
[1] https://postgr.es/m/CAKOSWNkN6HSyatuys8xZxzRCR-KL1OkHS5-b9qd9bf1Rad3PLA@mail.gmail.com

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Author: Bernd Helmle <mailings@oopsware.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
20 months agoReset the logical worker type while cleaning up other worker info.
Amit Kapila [Fri, 25 Aug 2023 03:27:55 +0000 (08:57 +0530)]
Reset the logical worker type while cleaning up other worker info.

Commit 2a8b40e36 introduces the worker type field for logical replication
workers, but forgot to reset the type when the worker exits. This can lead
to recognizing a stopped worker as a valid logical replication worker.

Fix it by resetting the worker type and additionally adding the safeguard
to not use LogicalRepWorker until ->in_use is verified.

Reported-by: Thomas Munro based on cfbot reports.
Author: Hou Zhijie, Alvaro Herrera
Reviewed-by: Amit Kapila
Discussion: http://postgr.es/m/CA+hUKGK2RQh4LifVgBmkHsCYChP-65UwGXOmnCzYVa5aAt4GWg@mail.gmail.com

20 months agoUse "template" data directory in tests
Andres Freund [Thu, 24 Aug 2023 21:17:03 +0000 (14:17 -0700)]
Use "template" data directory in tests

When running all (or just many) of our tests, a significant portion of both
CPU time and IO is spent running initdb. Most of those initdb runs don't
specify any options influencing properties of the created data directory.

Avoid most of that overhead by creating a "template" data directory, alongside
the temporary installation. Instead of running initdb, pg_regress and tap
tests can copy that data directory. When a tap test specifies options to
initdb, the template data directory is not used. That could be relaxed for
some options, but it's not clear it's worth the effort.

There unfortunately is some duplication between pg_regress.c and Cluster.pm,
but there are no easy ways of sharing that code without introducing additional
complexity.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/20220120021859.3zpsfqn4z7ob7afz@alap3.anarazel.de

20 months agopg_upgrade: Bump MESSAGE_WIDTH.
Nathan Bossart [Thu, 24 Aug 2023 17:13:31 +0000 (10:13 -0700)]
pg_upgrade: Bump MESSAGE_WIDTH.

Commit 7b378237aa added a status message to pg_upgrade that is 60
characters wide.  Since the MESSAGE_WIDTH macro is currently set to
60, there is no space between this new status message and the "ok"
or "failed" indicator appended when the step completes.  To fix
this problem, this commit increases the value of MESSAGE_WIDTH to
62.

Suggested-by: Bharath Rupireddy
Reviewed-by: Peter Eisentraut
Discussion: https://postgr.es/m/CALj2ACVVvk1cYLtWVxHv%3DZ1Ubq%3DUES9fhKbUU4c9k4W%2BfEDnbw%40mail.gmail.com
Backpatch-through: 16

20 months agoAvoid unnecessary plancache revalidation of utility statements.
Tom Lane [Thu, 24 Aug 2023 16:02:40 +0000 (12:02 -0400)]
Avoid unnecessary plancache revalidation of utility statements.

Revalidation of a plancache entry (after a cache invalidation event)
requires acquiring a snapshot.  Normally that is harmless, but not
if the cached statement is one that needs to run without acquiring a
snapshot.  We were already aware of that for TransactionStmts,
but for some reason hadn't extrapolated to the other statements that
PlannedStmtRequiresSnapshot() knows mustn't set a snapshot.  This can
lead to unexpected failures of commands such as SET TRANSACTION
ISOLATION LEVEL.  We can fix it in the same way, by excluding those
command types from revalidation.

However, we can do even better than that: there is no need to
revalidate for any statement type for which parse analysis, rewrite,
and plan steps do nothing interesting, which is nearly all utility
commands.  To mechanize this, invent a parser function
stmt_requires_parse_analysis() that tells whether parse analysis does
anything beyond wrapping a CMD_UTILITY Query around the raw parse
tree.  If that's what it does, then rewrite and plan will just
skip the Query, so that it is not possible for the same raw parse
tree to produce a different plan tree after cache invalidation.

stmt_requires_parse_analysis() is basically equivalent to the
existing function analyze_requires_snapshot(), except that for
obscure reasons that function omits ReturnStmt and CallStmt.
It is unclear whether those were oversights or intentional.
I have not been able to demonstrate a bug from not acquiring a
snapshot while analyzing these commands, but at best it seems mighty
fragile.  It seems safer to acquire a snapshot for parse analysis of
these commands too, which allows making stmt_requires_parse_analysis
and analyze_requires_snapshot equivalent.

In passing this fixes a second bug, which is that ResetPlanCache
would exclude ReturnStmts and CallStmts from revalidation.
That's surely *not* safe, since they contain parsable expressions.

Per bug #18059 from Pavel Kulakov.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18059-79c692f036b25346@postgresql.org

20 months agoAdd test for inherited CHECK constraint drop
Alvaro Herrera [Thu, 24 Aug 2023 14:51:43 +0000 (16:51 +0200)]
Add test for inherited CHECK constraint drop

This code is insufficiently covered by tests, so add a few small test
cases to immortalize its behavior before it gets rewritten completely by
the project to catalog NOT NULL constraints.

20 months agoUse FD_CLOEXEC on ListenSockets
Heikki Linnakangas [Thu, 24 Aug 2023 14:03:05 +0000 (17:03 +0300)]
Use FD_CLOEXEC on ListenSockets

It's good hygiene if e.g. an extension launches a subprogram when
being loaded. We went through some effort to close them in the child
process in EXEC_BACKEND mode, but it's better to not hand them down to
the child process in the first place. We still need to close them
after fork when !EXEC_BACKEND, but it's a little simpler.

In the passing, LOG a message if closing the client connection or
listen socket fails. Shouldn't happen, but if it does, would be nice
to know.

Reviewed-by: Tristan Partin, Andres Freund, Thomas Munro
Discussion: https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi

20 months agoFix lack of message pluralization
Peter Eisentraut [Thu, 24 Aug 2023 12:22:02 +0000 (14:22 +0200)]
Fix lack of message pluralization

20 months agoUpdate DECLARE_INDEX documentation
Peter Eisentraut [Thu, 24 Aug 2023 11:59:40 +0000 (13:59 +0200)]
Update DECLARE_INDEX documentation

Update source code comment changes belonging to the changes in
6a6389a08b.

Discussion: https://www.postgresql.org/message-id/flat/75ae5875-3abc-dafc-8aec-73247ed41cde@eisentraut.org

20 months agoRename hook functions for debug_io_direct to match variable name.
Peter Eisentraut [Tue, 22 Aug 2023 12:12:45 +0000 (14:12 +0200)]
Rename hook functions for debug_io_direct to match variable name.

Commit 319bae9a renamed the GUC.  Rename the check and assign functions
to match, and alphabetize.

Back-patch to 16.

Author: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/2769341e-fa28-c2ee-3e4b-53fdcaaf2271%40eisentraut.org

20 months agoAdd proargnames to multi-argument aggregate functions
Daniel Gustafsson [Thu, 24 Aug 2023 09:53:42 +0000 (11:53 +0200)]
Add proargnames to multi-argument aggregate functions

Having argument names makes it easier to understand how to use the
aggregate functions when inspecting them with \dfa or similar.

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Discussion: https://postgr.es/m/877cw3jl8y.fsf@wibble.ilmari.org

20 months agoFix the error message when failing to restore the snapshot.
Amit Kapila [Thu, 24 Aug 2023 09:07:29 +0000 (14:37 +0530)]
Fix the error message when failing to restore the snapshot.

The SnapBuildRestoreContents() used a const value in the error message to
indicate the size in bytes it was expecting to read from the serialized
snapshot file. Fix it by reporting the size that was actually passed.

Author: Hou Zhijie
Reviewed-by: Amit Kapila
Backpatch-through: 16
Discussion: http://postgr.es/m/OS0PR01MB5716D408364F7DF32221C08D941FA@OS0PR01MB5716.jpnprd01.prod.outlook.com

20 months agoFix translation markers
Peter Eisentraut [Thu, 24 Aug 2023 08:24:38 +0000 (10:24 +0200)]
Fix translation markers

Conditionals cannot be inside gettext trigger functions, they must be
applied outside.

20 months agopg_upgrade: Improve one log message
Peter Eisentraut [Thu, 24 Aug 2023 06:23:43 +0000 (08:23 +0200)]
pg_upgrade: Improve one log message

The parenthesized plural is unnecessary here and inconsistent with
nearby similar messages.

20 months agoMeson: check for pg_config_paths.h left over from make
David Rowley [Wed, 23 Aug 2023 22:33:53 +0000 (10:33 +1200)]
Meson: check for pg_config_paths.h left over from make

The meson build scripts attempt to find files left over from configure
and fail, mentioning that "make maintainer-clean" should be run to remove
these.  This seems to have been done for files generated from configure.
pg_config_paths.h is generated during the actual make build, so seems to
have been missed.  This would result in compilation using the wrong
pg_config_paths.h file.

Here we just add this file to generated_sources_ac so that meson errors
out if pg_config_paths.h exists.

Likely this wasn't noticed before because make maintainer-clean will
remove pg_config_paths.h, however, people using the MSVC build scripts
are more likely to run into issues and they have to manually remove
these files and pg_config_paths.h wasn't listed as a conflicting file to
remove in the meson log.

Backpatch-through: 16, where meson support was added
Discussion: https://postgr.es/m/CAApHDvqjYOxZfmLKAOWKFEE7LOr9_E6UA6YNmx9r8nxStcS3gg@mail.gmail.com

20 months agoci: Make compute resources for CI configurable
Andres Freund [Wed, 23 Aug 2023 22:15:28 +0000 (15:15 -0700)]
ci: Make compute resources for CI configurable

See prior commit for an explanation for the goal of the change and why it had
to be split into two commits.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de
Backpatch: 15-, where CI support was added

20 months agoci: Prepare to make compute resources for CI configurable
Andres Freund [Wed, 23 Aug 2023 22:15:28 +0000 (15:15 -0700)]
ci: Prepare to make compute resources for CI configurable

cirrus-ci will soon restrict the amount of free resources every user gets (as
have many other CI providers). For most users of CI that should not be an
issue. But e.g. for cfbot it will be an issue.

To allow configuring different resources on a per-repository basis, introduce
infrastructure for overriding the task execution environment. Unfortunately
this is not entirely trivial, as yaml anchors have to be defined before their
use, and cirrus-ci only allows injecting additional contents at the end of
.cirrus.yml.

To deal with that, move the definition of the CI tasks to
.cirrus.tasks.yml. The main .cirrus.yml is loaded first, then, if defined, the
file referenced by the REPO_CI_CONFIG_GIT_URL variable, will be added,
followed by the contents of .cirrus.tasks.yml. That allows
REPO_CI_CONFIG_GIT_URL to override the yaml anchors defined in .cirrus.yml.

Unfortunately git's default merge / rebase strategy does not handle copied
files, just renamed ones. To avoid painful rebasing over this change, this
commit just renames .cirrus.yml to .cirrus.tasks.yml, without adding a new
.cirrus.yml. That's done in the followup commit, which moves the relevant
portion of .cirrus.tasks.yml to .cirrus.yml.  Until that is done,
REPO_CI_CONFIG_GIT_URL does not fully work.

The subsequent commit adds documentation for how to configure custom compute
resources to src/tools/ci/README

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de
Backpatch: 15-, where CI support was added

20 months agoBump catversion for to_bin() and to_oct().
Nathan Bossart [Wed, 23 Aug 2023 21:19:58 +0000 (14:19 -0700)]
Bump catversion for to_bin() and to_oct().

Missed in 260a1f18da.

20 months agoci: Use VMs for SanityCheck and CompilerWarnings
Andres Freund [Wed, 23 Aug 2023 19:25:56 +0000 (12:25 -0700)]
ci: Use VMs for SanityCheck and CompilerWarnings

The main reason for this change is to reduce different ways of executing
tasks, making it easier to use custom compute resources for cfbot. A secondary
benefit is that the tasks seem slightly faster this way, apparently the
increased startup overhead is outweighed by reduced runtime overhead.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de
Backpatch: 15-, where CI support was added

20 months agoci: Move execution method of tasks into yaml templates
Andres Freund [Wed, 23 Aug 2023 19:25:56 +0000 (12:25 -0700)]
ci: Move execution method of tasks into yaml templates

This is done in preparation for making the compute resources for CI
configurable. It also looks cleaner.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de
Backpatch: 15-, where CI support was added

20 months agoci: Don't specify amount of memory
Andres Freund [Wed, 23 Aug 2023 19:25:56 +0000 (12:25 -0700)]
ci: Don't specify amount of memory

The number of CPUs is the cost-determining factor. Most instance types that
run tests have more memory/core than what we specified, there's no real
benefit in wasting that.

Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de
Backpatch: 15-, where CI support was added

20 months agoAvoid use of Perl getprotobyname
Peter Eisentraut [Wed, 23 Aug 2023 18:48:48 +0000 (20:48 +0200)]
Avoid use of Perl getprotobyname

getprotobyname returns undefined on some CI machines.  It's not clear
why.  The code overall still works, but it raises a warning.

In PostgreSQL C code, we always call socket() with 0 for the protocol
argument, so we should be able to do the same in Perl (since the Perl
documentation says that the arguments of the socket function are the
same as in C).  So do that, to avoid the issue.

Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://www.postgresql.org/message-id/flat/06f899fd-1826-05ab-42d6-adeb1fd5e200%40eisentraut.org

20 months agoFix _bt_allequalimage() call within critical section.
Heikki Linnakangas [Wed, 23 Aug 2023 15:08:40 +0000 (18:08 +0300)]
Fix _bt_allequalimage() call within critical section.

_bt_allequalimage() does complicated things, so it's not OK to call it
in a critical section. Per buildfarm failure on 'prion', which uses
-DRELCACHE_FORCE_RELEASE -DCATCACHE_FORCE_RELEASE options.

Discussion: https://www.postgresql.org/message-id/6e5bbc08-cdfc-b2b3-9e23-1a914b9850a9@iki.fi
Backpatch-through: 16, like commit ccadf73163 that introduced this

20 months agoAdd to_bin() and to_oct().
Nathan Bossart [Wed, 23 Aug 2023 14:49:03 +0000 (07:49 -0700)]
Add to_bin() and to_oct().

This commit introduces functions for converting numbers to their
equivalent binary and octal representations.  Also, the base
conversion code for these functions and to_hex() has been moved to
a common helper function.

Co-authored-by: Eric Radman
Reviewed-by: Ian Barwick, Dag Lem, Vignesh C, Tom Lane, Peter Eisentraut, Kirk Wolak, Vik Fearing, John Naylor, Dean Rasheed
Discussion: https://postgr.es/m/Y6IyTQQ/TsD5wnsH%40vm3.eradman.com

20 months agoUse the buffer cache when initializing an unlogged index.
Heikki Linnakangas [Wed, 23 Aug 2023 14:21:31 +0000 (17:21 +0300)]
Use the buffer cache when initializing an unlogged index.

Some of the ambuildempty functions used smgrwrite() directly, followed
by smgrimmedsync(). A few small problems with that:

Firstly, one is supposed to use smgrextend() when extending a
relation, not smgrwrite(). It doesn't make much difference in
production builds. smgrextend() updates the relation size cache, so
you miss that, but that's harmless because we never use the cached
relation size of an init fork. But if you compile with
CHECK_WRITE_VS_EXTEND, you get an assertion failure.

Secondly, the smgrwrite() calls were performed before WAL-logging, so
the page image written to disk had 0/0 as the LSN, not the LSN of the
WAL record. That's also harmless in practice, but seems sloppy.

Thirdly, it's better to use the buffer cache, because then you don't
need to smgrimmedsync() the relation to disk, which adds latency.
Bypassing the cache makes sense for bulk operations like index
creation, but not when you're just initializing an empty index.
Creation of unlogged tables is hardly performance bottleneck in any
real world applications, but nevertheless.

Backpatch to v16, but no further. These issues should be harmless in
practice, so better to not rock the boat in older branches.

Reviewed-by: Robert Haas
Discussion: https://www.postgresql.org/message-id/6e5bbc08-cdfc-b2b3-9e23-1a914b9850a9@iki.fi

20 months agodoc: Replace list of drivers and PLs with wiki link
Daniel Gustafsson [Wed, 23 Aug 2023 12:13:07 +0000 (14:13 +0200)]
doc: Replace list of drivers and PLs with wiki link

The list of external language drivers and procedural languages was
never complete or exhaustive, and rather than attempting to manage
it the content has migrated to the wiki.  This replaces the tables
altogether with links to the wiki as we regularly get requests for
adding various projects,  which we reject without any clear policy
for why or how the content should be managed.

The threads linked to below are the most recent discussions about
this, the archives contain many more.

Backpatch to all supported branches since the list on the wiki
applies to all branches.

Author: Jonathan Katz <jkatz@postgresql.org>
Discussion: https://postgr.es/m/169165415312.635.10247434927885764880@wrigleys.postgresql.org
Discussion: https://postgr.es/m/169177958824.635.11087800083040275266@wrigleys.postgresql.org
Backpatch-through: v11

20 months agodoc: Add more ICU rules examples
Peter Eisentraut [Wed, 23 Aug 2023 09:23:42 +0000 (11:23 +0200)]
doc: Add more ICU rules examples

In particular, add an example EBCDIC collation.

Author: Daniel Verite <daniel@manitou-mail.org>
Discussion: https://www.postgresql.org/message-id/flat/35cc1684-e516-4a01-a256-351632d47066@manitou-mail.org

20 months agoFix wording in comment
Daniel Gustafsson [Wed, 23 Aug 2023 08:22:55 +0000 (10:22 +0200)]
Fix wording in comment

The comment for the DSM_OP_CREATE paramater read "the a new handle"
which is confusing. Fix by rewording to indicate what the parameter
means for DSM_OP_CREATE.

Reported-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://postgr.es/m/CAEG8a3J2bc197ym-M_ykOXb9ox2eNn-QNKNeoSAoHYSw2NCOnw@mail.gmail.com

20 months agopg_upgrade: Avoid shadowing global var in function
Daniel Gustafsson [Wed, 23 Aug 2023 07:41:22 +0000 (09:41 +0200)]
pg_upgrade: Avoid shadowing global var in function

The new_cluster parameter in check_for_new_tablespace_dir was
shadowing the globally defined new_cluster variable, causing
compiler warnings when running with -Wshadow. The function is
only applicable to the new cluster, so remove the parameter
rather than rename to match check_new_cluster_is_empty which
also only applies to the new cluster.

Author: Peter Smith <peter.b.smith@fujitsu.com>
Discussion: https://postgr.es/m/CAHut+PvS_PHLntWy1yTgXv0O1tWm4iVcKBQFzpoQRDsm2Ce_Fg@mail.gmail.com

20 months agodoc: Improve ICU external link
Peter Eisentraut [Wed, 23 Aug 2023 06:25:56 +0000 (08:25 +0200)]
doc: Improve ICU external link

It previously pointed to the collation API documentation, which our
users don't need, but the containing chapter seems useful.

20 months agoImprove vertical spacing of documentation markup
Peter Eisentraut [Wed, 23 Aug 2023 06:12:50 +0000 (08:12 +0200)]
Improve vertical spacing of documentation markup

20 months agoSome vertical reformatting
Peter Eisentraut [Wed, 23 Aug 2023 04:14:11 +0000 (06:14 +0200)]
Some vertical reformatting

Remove some line breaks that have become unnecessary after some
variable renaming.

Discussion: https://www.postgresql.org/message-id/flat/5ed89c69-f4e6-5dab-4003-63bde7460e5e%40eisentraut.org

20 months agoRename some function arguments for better clarity
Peter Eisentraut [Wed, 23 Aug 2023 04:14:11 +0000 (06:14 +0200)]
Rename some function arguments for better clarity

Especially make sure that array arguments have plural names.

Discussion: https://www.postgresql.org/message-id/flat/5ed89c69-f4e6-5dab-4003-63bde7460e5e%40eisentraut.org

20 months agoAdd const decorations
Peter Eisentraut [Wed, 23 Aug 2023 04:14:11 +0000 (06:14 +0200)]
Add const decorations

in index.c and indexcmds.c and some adjacent places.  This especially
makes it easier to understand for some complicated function signatures
which are the input and the output arguments.

Discussion: https://www.postgresql.org/message-id/flat/5ed89c69-f4e6-5dab-4003-63bde7460e5e%40eisentraut.org

20 months agoIntroduce macros for protocol characters.
Nathan Bossart [Wed, 23 Aug 2023 02:16:12 +0000 (19:16 -0700)]
Introduce macros for protocol characters.

This commit introduces descriptively-named macros for the
identifiers used in wire protocol messages.  These new macros are
placed in a new header file so that they can be easily used by
third-party code.

Author: Dave Cramer
Reviewed-by: Alvaro Herrera, Tatsuo Ishii, Peter Smith, Robert Haas, Tom Lane, Peter Eisentraut, Michael Paquier
Discussion: https://postgr.es/m/CADK3HHKbBmK-PKf1bPNFoMC%2BoBt%2BpD9PH8h5nvmBQskEHm-Ehw%40mail.gmail.com

20 months agoExtendBufferedWhat -> BufferManagerRelation.
Thomas Munro [Wed, 23 Aug 2023 00:10:18 +0000 (12:10 +1200)]
ExtendBufferedWhat -> BufferManagerRelation.

Commit 31966b15 invented a way for functions dealing with relation
extension to accept a Relation in online code and an SMgrRelation in
recovery code.  It seems highly likely that future bufmgr.c interfaces
will face the same problem, and need to do something similar.
Generalize the names so that each interface doesn't have to re-invent
the wheel.

Back-patch to 16.  Since extension AM authors might start using the
constructor macros once 16 ships, we agreed to do the rename in 16
rather than waiting for 17.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKG%2B6tLD2BhpRWycEoti6LVLyQq457UL4ticP5xd8LqHySA%40mail.gmail.com

20 months agoFix pg_dump assertion failure when dumping pg_catalog.
Jeff Davis [Tue, 22 Aug 2023 18:21:36 +0000 (11:21 -0700)]
Fix pg_dump assertion failure when dumping pg_catalog.

Commit 396d348b04 did not account for the default collation.

Also, use pg_log_warning() instead of Assert().

Discussion: https://postgr.es/m/ce071503fee88334aa70f360e6e4ea14d48305ee.camel%40j-davis.com
Reviewed-by: Michael Paquier
Backpatch-through: 15

20 months agoCache by-reference missing values in a long lived context
Andrew Dunstan [Tue, 22 Aug 2023 15:57:08 +0000 (11:57 -0400)]
Cache by-reference missing values in a long lived context

Attribute missing values might be needed past the lifetime of the tuple
descriptors from which they are extracted. To avoid possibly using
pointers for by-reference values which might thus be left dangling, we
cache a datumCopy'd version of the datum in the TopMemoryContext. Since
we first search for the value this only needs to be done once per
session for any such value.

Original complaint from Tom Lane, idea for mitigation by Andrew Dunstan,
tweaked by Tom Lane.

Backpatch to version 11 where missing values were introduced.

Discussion: https://postgr.es/m/1306569.1687978174@sss.pgh.pa.us

20 months agoAdd comment missing in a4a232b1e702
Alvaro Herrera [Tue, 22 Aug 2023 10:22:03 +0000 (12:22 +0200)]
Add comment missing in a4a232b1e702

Noticed while studying nearby code

20 months agoSimplify the logical worker type checks by using the switch on worker type.
Amit Kapila [Tue, 22 Aug 2023 03:14:09 +0000 (08:44 +0530)]
Simplify the logical worker type checks by using the switch on worker type.

The current code uses if/else statements at various places to take worker
specific actions. Change those to use the switch on worker type added by
commit 2a8b40e368. This makes code easier to read and understand.

Author: Peter Smith
Reviewed-by: Amit Kapila, Hou Zhijie
Discussion: http://postgr.es/m/CAHut+PttPSuP0yoZ=9zLDXKqTJ=d0bhxwKaEaNcaym1XqcvDEg@mail.gmail.com

20 months agoFix pg_stat_reset_single_table_counters() for shared relations
Michael Paquier [Mon, 21 Aug 2023 04:32:14 +0000 (13:32 +0900)]
Fix pg_stat_reset_single_table_counters() for shared relations

This commit fixes the function of $subject for shared relations.  This
feature has been added by e042678.  Unfortunately, this new behavior got
removed by 5891c7a when moving statistics to shared memory.

Reported-by: Mitsuru Hinata
Author: Masahiro Ikeda
Reviewed-by: Kyotaro Horiguchi, Masahiko Sawada
Discussion: https://postgr.es/m/7cc69f863d9b1bc677544e3accd0e4b4@oss.nttdata.com
Backpatch-through: 15

20 months agoBump catalog version for pg_wait_events
Michael Paquier [Sun, 20 Aug 2023 06:44:48 +0000 (15:44 +0900)]
Bump catalog version for pg_wait_events

Missed in 1e68e43, because I cannot correctly merge a branch.

20 months agoAdd system view pg_wait_events
Michael Paquier [Sun, 20 Aug 2023 06:35:02 +0000 (15:35 +0900)]
Add system view pg_wait_events

This new view, wrapped around a SRF, shows some information known about
wait events, as of:
- Name.
- Type (Activity, I/O, Extension, etc.).
- Description.

All the information retrieved comes from wait_event_names.txt, and the
description is the same as the documentation with filters applied to
remove any XML markups.  This view is useful when joined with
pg_stat_activity to get the description of a wait event reported.

Custom wait events for extensions are included in the view.

Original idea by Yves Colin.

Author: Bertrand Drouvot
Reviewed-by: Kyotaro Horiguchi, Masahiro Ikeda, Tom Lane, Michael
Paquier
Discussion: https://postgr.es/m/0e2ae164-dc89-03c3-cf7f-de86378053ac@gmail.com

20 months agoci: macos: use cached macports install
Andres Freund [Sat, 19 Aug 2023 19:40:45 +0000 (12:40 -0700)]
ci: macos: use cached macports install

A significant chunk of the time on the macos CI task is spent installing
packages using homebrew. The downloads of the packages are cached, but the
installation needs to happen every time. We can't cache the whole homebrew
installation, because it is too large due to pre-installed packages.

Speed this up by installing packages using macports and caching the
installation as .dmg. That's a lot faster than unpacking a tarball.

In addition, don't install llvm - it wasn't enabled when building, so it's
just a waste of time/space.

This substantially speeds up the mac CI time, both in the cold cache and in
the warm cache case (the latter from ~1m20s to ~5s).

It doesn't seem great to have diverging sources of packages for CI between
branches, so backpatch to 15 (where CI was added).

Discussion: https://postgr.es/m/20230805202539.r3umyamsnctysdc7@awork3.anarazel.de
Backpatch: 15-, where CI was added

21 months agoRemove dubious warning message from SQL/JSON functions
Peter Eisentraut [Fri, 18 Aug 2023 05:41:14 +0000 (07:41 +0200)]
Remove dubious warning message from SQL/JSON functions

There was a warning that FORMAT JSON has no effect on json/jsonb
types, which is true, but it's not clear why we should issue a warning
about it.  The SQL standard does not say anything about this, which
should generally govern the behavior here.  So remove it.

Discussion: https://www.postgresql.org/message-id/flat/dfec2cae-d17e-c508-6d16-c2dba82db486%40eisentraut.org

21 months agopg_upgrade: Improve style of a few verbose messages
Michael Paquier [Fri, 18 Aug 2023 00:39:55 +0000 (09:39 +0900)]
pg_upgrade: Improve style of a few verbose messages

Author: Peter Smith
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CAHut+PuOB4bUwkYAjA_NkTrYaocKy6W3ZYK5Pin305R7mNSLgA@mail.gmail.com

21 months agoFix format if entry in wait_event_names.txt
Michael Paquier [Thu, 17 Aug 2023 23:11:10 +0000 (08:11 +0900)]
Fix format if entry in wait_event_names.txt

The entry LockManager had two successive whitespaces between two words.
This is not an actual bug, but let's be clean.  Thinko in fa88928.

Reported-by: Masahiro Ikeda
Author: Bertrand Drouvot
Discussion: https://postgr.es/m/dd836027-2e9e-4df9-9fd9-7527cd1757e1@gmail.com

21 months agoAdd a few recent commits to .git-blame-ignore-revs.
Nathan Bossart [Thu, 17 Aug 2023 14:25:18 +0000 (07:25 -0700)]
Add a few recent commits to .git-blame-ignore-revs.

Reviewed-by: Peter Geoghegan
Discussion: https://postgr.es/m/20230815203109.GA2596919%40nathanxps13

21 months agoRemove traces of Sun -lposix4.
Thomas Munro [Thu, 17 Aug 2023 04:16:43 +0000 (16:16 +1200)]
Remove traces of Sun -lposix4.

This was a library on ancient Solaris systems, which was eventually
replaced by -lrt, itself now redundant on that OS.

Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/CA%2BhUKGLLVx4drdvXats9PxH3eeB%2BE2NkJReJ%2BRGmaOpU%3D9rgEA%40mail.gmail.com

21 months agoDon't probe extra libraries for fdatasync.
Thomas Munro [Thu, 17 Aug 2023 04:11:41 +0000 (16:11 +1200)]
Don't probe extra libraries for fdatasync.

Commit d2e15083 got rid of the main configure probe and HAVE_FDATASYNC
macro, but we still searched -lrt and -lposix4 for old Solaris systems.
It's in the C library on modern Solaris, as on other supported systems.

Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/CA%2BhUKGLLVx4drdvXats9PxH3eeB%2BE2NkJReJ%2BRGmaOpU%3D9rgEA%40mail.gmail.com

21 months agoInvalidate smgr_targblock in smgrrelease().
Thomas Munro [Thu, 17 Aug 2023 03:45:13 +0000 (15:45 +1200)]
Invalidate smgr_targblock in smgrrelease().

In rare circumstances involving relfilenode reuse, it might have been
possible for smgr_targblock to finish up pointing past the end.

Oversight in b74e94dc.  Back-patch to 15.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/CA%2BhUKGJ8NTvqLHz6dqbQnt2c8XCki4r2QvXjBQcXpVwxTY_pvA%40mail.gmail.com

21 months agosepgsql: Adjust regression expected output
Michael Paquier [Thu, 17 Aug 2023 01:51:26 +0000 (10:51 +0900)]
sepgsql: Adjust regression expected output

Oversight in 352ea3a, where support for these subcommands has been
added.

Per buildfarm member rhinoceros.

21 months agoAdd OAT hook calls for more subcommands of ALTER TABLE
Michael Paquier [Wed, 16 Aug 2023 23:54:17 +0000 (08:54 +0900)]
Add OAT hook calls for more subcommands of ALTER TABLE

The OAT hooks are added in ALTER TABLE for the following subcommands:
- { ENABLE | DISABLE | [NO] FORCE } ROW LEVEL SECURITY
- { ENABLE | DISABLE } TRIGGER
- { ENABLE | DISABLE } RULE.  Note that there was hook for pg_rewrite,
but not for relation ALTER'ed in pg_class.

Tests are added to test_oat_hook for all the subcommand patterns gaining
hooks here.  Based on an ask from Legs Mansion.

Discussion: https://postgr.es/m/tencent_083B3850655AC6EE04FA0A400766D3FE8309@qq.com

21 months agoUnify some error messages
Peter Eisentraut [Wed, 16 Aug 2023 14:17:00 +0000 (16:17 +0200)]
Unify some error messages

We had essentially the same error in several different wordings.
Unify that.

21 months agoImproved CREATE SUBSCRIPTION message for clarity
Peter Eisentraut [Wed, 16 Aug 2023 13:09:50 +0000 (15:09 +0200)]
Improved CREATE SUBSCRIPTION message for clarity

Discussion: https://www.postgresql.org/message-id/CAHut+PtfzQ7JRkb0-Y_UejAxaLQ17-bGMvV4MJJHcPoP3ML2bg@mail.gmail.com

21 months agoRemove incorrect field from information schema
Peter Eisentraut [Wed, 16 Aug 2023 11:46:26 +0000 (13:46 +0200)]
Remove incorrect field from information schema

The source code comment already said that the presence of the field
element_types.domain_default might be a bug in the standard, since it
never made sense there.  Indeed, the field is gone in newer versions
of the standard.  So just remove it.

21 months agoSplit out tiebreaker comparisons from comparetup_* functions
John Naylor [Wed, 16 Aug 2023 10:15:07 +0000 (17:15 +0700)]
Split out tiebreaker comparisons from comparetup_* functions

Previously, if a specialized comparator found equal datum1 keys,
the "comparetup" function would repeat the comparison on the
datum before proceeding with the unabbreviated first key
and/or additional sort keys.

Move comparing additional sort keys into "tiebreak" functions so
that specialized comparators can call these directly if needed,
avoiding duplicate work.

Reviewed by David Rowley

Discussion: https://postgr.es/m/CAFBsxsGaVfUrjTghpf%3DkDBYY%3DjWx1PN-fuusVe7Vw5s0XqGdGw%40mail.gmail.com

21 months agoFix code indentation vioaltion introduced in commit 9e9931d2b.
Etsuro Fujita [Tue, 15 Aug 2023 08:45:00 +0000 (17:45 +0900)]
Fix code indentation vioaltion introduced in commit 9e9931d2b.

Per buildfarm member koel

21 months agoRe-allow FDWs and custom scan providers to replace joins with pseudoconstant quals.
Etsuro Fujita [Tue, 15 Aug 2023 07:45:00 +0000 (16:45 +0900)]
Re-allow FDWs and custom scan providers to replace joins with pseudoconstant quals.

This was disabled in commit 6f80a8d9c due to the lack of support for
handling of pseudoconstant quals assigned to replaced joins in
createplan.c.  To re-allow it, this patch adds the support by 1)
modifying the ForeignPath and CustomPath structs so that if they
represent foreign and custom scans replacing a join with a scan, they
store the list of RestrictInfo nodes to apply to the join, as in
JoinPaths, and by 2) modifying create_scan_plan() in createplan.c so
that it uses that list in that case, instead of the baserestrictinfo
list, to get pseudoconstant quals assigned to the join, as mentioned in
the commit message for that commit.

Important item for the release notes: this is non-backwards-compatible
since it modifies the ForeignPath and CustomPath structs, as mentioned
above, and changes the argument lists for FDW helper functions
create_foreignscan_path(), create_foreign_join_path(), and
create_foreign_upper_path().

Richard Guo, with some additional changes by me, reviewed by Nishant
Sharma, Suraj Kharage, and Richard Guo.

Discussion: https://postgr.es/m/CADrsxdbcN1vejBaf8a%2BQhrZY5PXL-04mCd4GDu6qm6FigDZd6Q%40mail.gmail.com

21 months agoDe-pessimize ConditionVariableCancelSleep().
Thomas Munro [Mon, 14 Aug 2023 22:20:11 +0000 (10:20 +1200)]
De-pessimize ConditionVariableCancelSleep().

Commit b91dd9de was concerned with a theoretical problem with our
non-atomic condition variable operations.  If you stop sleeping, and
then cancel the sleep in a separate step, you might be signaled in
between, and that could be lost.  That doesn't matter for callers of
ConditionVariableBroadcast(), but callers of ConditionVariableSignal()
might be upset if a signal went missing like this.

Commit bc971f4025c interacted badly with that logic, because it doesn't
use ConditionVariableSleep(), which would normally put us back in the
wait list.  ConditionVariableCancelSleep() would be confused and think
we'd received an extra signal, and try to forward it to another backend,
resulting in wakeup storms.

New idea: ConditionVariableCancelSleep() can just return true if we've
been signaled.  Hypothetical users of ConditionVariableSignal() would
then still have a way to deal with rare lost signals if they are
concerned about that problem.

Back-patch to 16, where bc971f4025c arrived.

Reported-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/2840876b-4cfe-240f-0a7e-29ffd66711e7%40enterprisedb.com