postgresql.git
8 months agoSpeed up Hash Join by making ExprStates support hashing
David Rowley [Tue, 20 Aug 2024 01:38:22 +0000 (13:38 +1200)]
Speed up Hash Join by making ExprStates support hashing

Here we add ExprState support for obtaining a 32-bit hash value from a
list of expressions.  This allows both faster hashing and also JIT
compilation of these expressions.  This is especially useful when hash
joins have multiple join keys as the previous code called ExecEvalExpr on
each hash join key individually and that was inefficient as tuple
deformation would have only taken into account one key at a time, which
could lead to walking the tuple once for each join key.  With the new
code, we'll determine the maximum attribute required and deform the tuple
to that point only once.

Some performance tests done with this change have shown up to a 20%
performance increase of a query containing a Hash Join without JIT
compilation and up to a 26% performance increase when JIT is enabled and
optimization and inlining were performed by the JIT compiler.  The
performance increase with 1 join column was less with a 14% increase
with and without JIT.  This test was done using a fairly small hash
table and a large number of hash probes.  The increase will likely be
less with large tables, especially ones larger than L3 cache as memory
pressure is more likely to be the limiting factor there.

This commit only addresses Hash Joins, but lays expression evaluation
and JIT compilation infrastructure for other hashing needs such as Hash
Aggregate.

Author: David Rowley
Reviewed-by: Alexey Dvoichenkov <[email protected]>
Reviewed-by: Tels <[email protected]>
Discussion: https://postgr.es/m/CAApHDvoexAxgQFNQD_GRkr2O_eJUD1-wUGm%3Dm0L%2BGc%3DT%3DkEa4g%40mail.gmail.com

8 months agodoc: improve create/alter sequence CYCLE syntax
Bruce Momjian [Tue, 20 Aug 2024 00:18:03 +0000 (20:18 -0400)]
doc:  improve create/alter sequence CYCLE syntax

Reported-by: Peter Smith
Discussion: https://postgr.es/m/CAHut+PtqwZwPfGq62xq2614_ce2ejDmbB9CfP+a1azxpneFRBQ@mail.gmail.com

Author: Peter Smith

Backpatch-through: master

8 months agodoc: mention of postpostgres_fdw INSERT ON CONFLICT limitation
Bruce Momjian [Mon, 19 Aug 2024 23:54:39 +0000 (19:54 -0400)]
doc: mention of postpostgres_fdw INSERT ON CONFLICT limitation

Reported-by: Fujii Masao
Discussion: https://postgr.es/m/47801526-d017-4c89-9f52-c02c449a139b@oss.nttdata.com

Author: Fujii Masao

Backpatch-through: master

8 months agodoc: clarify create database in start docs uses command line
Bruce Momjian [Mon, 19 Aug 2024 23:22:10 +0000 (19:22 -0400)]
doc:  clarify create database in start docs uses command line

Reported-by: [email protected]
Discussion: https://postgr.es/m/172251463564.915373.17748961617119647662@wrigleys.postgresql.org

Backpatch-through: master

8 months agodoc: Improve vague pg_createsubscriber description
Bruce Momjian [Mon, 19 Aug 2024 22:27:22 +0000 (18:27 -0400)]
doc:  Improve vague pg_createsubscriber description

Discussion: https://postgr.es/m/[email protected]

Author: Euler Taveira

Backpatch-through: 17

8 months agoAvoid failure to open dropped detached partition
Alvaro Herrera [Mon, 19 Aug 2024 20:09:10 +0000 (16:09 -0400)]
Avoid failure to open dropped detached partition

When a partition is detached and immediately dropped, a prepared
statement could try to compute a new partition descriptor that includes
it.  This leads to this kind of error:
ERROR:  could not open relation with OID 457639

Avoid this by skipping the partition in expand_partitioned_rtentry if it
doesn't exist.

Noted by me while investigating bug #18559.  Kuntal Gosh helped to
identify the exact failure.

Backpatch to 14, where DETACH CONCURRENTLY was introduced.

Author: Álvaro Herrera <[email protected]>
Reviewed-by: Kuntal Ghosh <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
Discussion: https://postgr.es/m/202408122233[email protected]

8 months agoDocument that search_path is reported by the server
Tomas Vondra [Mon, 19 Aug 2024 17:46:05 +0000 (19:46 +0200)]
Document that search_path is reported by the server

Commit 28a1121fd912 marked search_path as GUC_REPORT, but failed to
update the relevant places in docs. There are two places listing the GUC
options reported to the client, so update both.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/CAFh8B=k8s7WrcqhafmYhdN1+E5LVzZi_QaYDq8bKvrGJTAhY2Q@mail.gmail.com

8 months agoMark search_path as GUC_REPORT
Tomas Vondra [Mon, 19 Aug 2024 15:04:09 +0000 (17:04 +0200)]
Mark search_path as GUC_REPORT

Report search_path changes to the client. Multi-tenant applications
often map tenants to schemas, and use search_path to pick the tenant a
given connection works with. This breaks when a connection pool (like
PgBouncer), because the search_path may change unexpectedly.

There are other GUCs we might want reported (e.g. various timeouts), but
search_path is by far the biggest foot gun that can lead either to
puzzling failures during query execution (when objects are missing or
are defined differently), or even to accessing incorrect data.

Many existing tools modify search_path, pg_dump being a notable example.

Ideally, clients could specify which GUCs are interesting and should be
subject to this reporting, but we don't support that. GUC_REPORT is what
connection pools rely on for other interesting GUCs, so just use that.

When this change was initially proposed in 2014, one of the concerns was
impact on performance. But this was addressed by commit 2432b1a04087,
which ensures we report each GUC at most once per query, no matter how
many times it changed during execution.

Eventually, this might be replaced / superseded by allowing doing this
by making the protocol extensible in this direction, but it's unclear
when (or if) that happens. Until then, we can leverage GUC_REPORT.

Author: Alexander Kukushkin, Jelte Fennema-Nio
Discussion: https://postgr.es/m/CAFh8B=k8s7WrcqhafmYhdN1+E5LVzZi_QaYDq8bKvrGJTAhY2Q@mail.gmail.com

8 months agoExplain dropdb can't use syscache because of TOAST
Tomas Vondra [Mon, 19 Aug 2024 11:31:51 +0000 (13:31 +0200)]
Explain dropdb can't use syscache because of TOAST

Add a comment explaining dropdb() can't rely on syscache. The issue with
flattened rows was fixed by commit 0f92b230f88b, but better to have
a clear explanation why the systable scan is necessary. The other places
doing in-place updates on pg_database have the same comment.

Suggestion and patch by Yugo Nagata. Backpatch to 12, same as the fix.

Author: Yugo Nagata
Backpatch-through: 12
Discussion: https://postgr.es/m/CAJTYsWWNkCt+-UnMhg=BiCD3Mh8c2JdHLofPxsW3m2dkDFw8RA@mail.gmail.com

8 months agoFix regression in TLS session ticket disabling
Daniel Gustafsson [Mon, 19 Aug 2024 10:55:11 +0000 (12:55 +0200)]
Fix regression in TLS session ticket disabling

Commit 274bbced disabled session tickets for TLSv1.3 on top of the
already disabled TLSv1.2 session tickets, but accidentally caused
a regression where TLSv1.2 session tickets were incorrectly sent.
Fix by unconditionally disabling TLSv1.2 session tickets and only
disable TLSv1.3 tickets when the right version of OpenSSL is used.

Backpatch to all supported branches.

Reported-by: Cameron Vogt <[email protected]>
Reported-by: Fire Emerald <[email protected]>
Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://postgr.es/m/DM6PR16MB3145CF62857226F350C710D1AB852@DM6PR16MB3145.namprd16.prod.outlook.com
Backpatch-through: v12

8 months agoFix harmless LC_COLLATE[_MASK] confusion.
Thomas Munro [Mon, 19 Aug 2024 09:21:03 +0000 (21:21 +1200)]
Fix harmless LC_COLLATE[_MASK] confusion.

Commit ca051d8b101 called newlocale(LC_COLLATE, ...) instead of
newlocale(LC_COLLATE_MASK, ...), in code reached only on FreeBSD.  They
have the same value on that OS, explaining why it worked.  Fix.

Back-patch to 14, where ca051d8b101 landed.

8 months agoFix garbled process name on backend crash
Heikki Linnakangas [Mon, 19 Aug 2024 06:48:25 +0000 (09:48 +0300)]
Fix garbled process name on backend crash

The log message on backend crash used wrong variable, which could be
uninitialized. Introduced in commit 28a520c0b7.

Reported-by: Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/451b0797-83b8-cdbc-727f-8d7a7b0e3bca@gmail.com

8 months agoFix more holes with SLRU code in need of int64 for segment numbers
Michael Paquier [Mon, 19 Aug 2024 03:34:18 +0000 (12:34 +0900)]
Fix more holes with SLRU code in need of int64 for segment numbers

This is a continuation of c9e24573905b, containing changes included into
the proposed patch that have been missed in the actual commit.  I have
managed to miss these diffs while doing a rebase of the original patch.

Thanks to Noah Misch, Peter Eisentraut and Alexander Korotkov for the
pokes.

Discussion: https://postgr.es/m/92fe572d-638e-4162-aef6-1c42a2936f25@eisentraut.org
Discussion: https://postgr.es/m/20240810175055[email protected]
Backpatch-through: 17

8 months agoSearch for SLRU page only in its own bank
Alvaro Herrera [Mon, 19 Aug 2024 00:49:57 +0000 (20:49 -0400)]
Search for SLRU page only in its own bank

One of the two slot scans in SlruSelectLRUPage was not walking only the
slots in the specific bank where the buffer could be; change it to do
that.

Oversight in 53c2a97a9266.

Author: Sergey Sargsyan <[email protected]>
Discussion: https://postgr.es/m/18582-5f301dd30ba91a38@postgresql.org

8 months agoinjection_points: Add stats for point caching and loading
Michael Paquier [Mon, 19 Aug 2024 00:03:52 +0000 (09:03 +0900)]
injection_points: Add stats for point caching and loading

This adds two counters to the fixed-numbered stats of injection points
to track the number of times injection points have been cached and
loaded from the cache, as of the additions coming from a0a5869a8598 and
4b211003ecc2.

These should have been part of f68cd847fa40, but I have lacked time and
energy back then, and it did not prevent the code to be a useful
template.

While on it, this commit simplifies the description of a few tests while
adding coverage for the new stats data.

Author: Yogesh Sharma
Discussion: https://postgr.es/m/3a6977f7-54ab-43ce-8806-11d5e15526a2@catprosystems.com

8 months agoci: Upgrade MacPorts version to 2.10.1.
Thomas Munro [Sun, 18 Aug 2024 23:47:37 +0000 (11:47 +1200)]
ci: Upgrade MacPorts version to 2.10.1.

MacPorts version 2.9.3 started failing in our ci_macports_packages.sh
script, for reasons not fully determined, but plausibly linked to the
release of 2.10.1.  2.10.1 seems to work, so let's switch to it.

Back-patch to 15, where CI began.

Reported-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/81f104e8-f0a9-43c0-85bd-2bbbf590a5b8%40eisentraut.org

8 months agodoc: Fix typo in section for custom pgstats
Michael Paquier [Sun, 18 Aug 2024 22:53:47 +0000 (07:53 +0900)]
doc: Fix typo in section for custom pgstats

Per offline report from Erik Rijkers.

8 months agoFix DROP DATABASE for databases with many ACLs
Tomas Vondra [Sun, 18 Aug 2024 22:04:41 +0000 (00:04 +0200)]
Fix DROP DATABASE for databases with many ACLs

Commit c66a7d75e652 modified DROP DATABASE so that if interrupted, the
database is known to be in an invalid state and can only be dropped.
This is done by setting a flag using an in-place update, so that it's
not lost in case of rollback.

For databases with many ACLs, this may however fail like this:

  ERROR:  wrong tuple length

This happens because with many ACLs, the pg_database.datacl attribute
gets TOASTed. The dropdb() code reads the tuple from the syscache, which
means it's detoasted. But the in-place update expects the tuple length
to match the on-disk tuple.

Fixed by reading the tuple from the catalog directly, not from syscache.

Report and fix by Ayush Tiwari. Backpatch to 12. The DROP DATABASE fix
was backpatched to 11, but 11 is EOL at this point.

Reported-by: Ayush Tiwari
Author: Ayush Tiwari
Reviewed-by: Tomas Vondra
Backpatch-through: 12
Discussion: https://postgr.es/m/CAJTYsWWNkCt+-UnMhg=BiCD3Mh8c2JdHLofPxsW3m2dkDFw8RA@mail.gmail.com

8 months agoFix cpluspluscheck for pg_verifybackup.h.
Thomas Munro [Sun, 18 Aug 2024 19:59:16 +0000 (07:59 +1200)]
Fix cpluspluscheck for pg_verifybackup.h.

simplehash.h references pg_fatal(), which cpluspluscheck says is
undeclared, causing the CI CompilerWarnings task to fail since commit
aa2d6b15.  Include the header it needs.

Discussion: https://postgr.es/m/CA%2BhUKGJC3d4PXkErpfOWrzQqcq6MLiCv0%2BAH0CMQnB6hdLUFEw%40mail.gmail.com

8 months agoFix comments on wal_level=minimal, CREATE TABLESPACE and CREATE DATABASE.
Noah Misch [Sun, 18 Aug 2024 19:03:59 +0000 (12:03 -0700)]
Fix comments on wal_level=minimal, CREATE TABLESPACE and CREATE DATABASE.

Commit 97ddda8a82ac470ae581d0eb485b6577707678bc removed the rmtree()
behavior from XLOG_TBLSPC_CREATE, obsoleting that part of the comment.
The comment's point about XLOG_DBASE_CREATE was wrong when commit
fa0f466d5329e10b16f3b38c8eaf5306f7e234e8 introduced the point.  (It
would have been accurate if that commit had predated commit
fbcbc5d06f53aea412130deb52e216aa3883fb8d introducing the second
checkpoint of CREATE DATABASE.)  Nothing can skip log_smgrcreate() on
the basis of wal_level=minimal, so don't comment on that.

Commit c6b92041d38512a4176ed76ad06f713d2e6c01a8 expanded WAL skipping
from five specific operations to relfilenodes generally, hence the
CreateDatabaseUsingFileCopy() comment change.

Discussion: https://postgr.es/m/20231008022204[email protected]

8 months agodocs: fix incorrect plpgsql error message
Bruce Momjian [Sat, 17 Aug 2024 02:50:54 +0000 (22:50 -0400)]
docs:  fix incorrect plpgsql error message

Change "$1" to "username".

Reported-by: [email protected]
Discussion: https://postgr.es/m/172112109590.736590.12219129462878821880@wrigleys.postgresql.org

Backpatch-through: 12

8 months agoC comment: fix for commit b5a9b18cd0b
Bruce Momjian [Sat, 17 Aug 2024 01:11:55 +0000 (21:11 -0400)]
C comment:  fix for commit b5a9b18cd0b

The commit was "Provide API for streaming relation data.".

Reported-by: Nazir Bilal Yavuz
Discussion: https://postgr.es/m/CAN55FZ3KsZ2faZs1sK5J0W+_8B3myB232CfLYGie4u4BBMwP3g@mail.gmail.com

Backpatch-through: master

8 months agoRelocate a badly placed Assert in COPY FROM code
David Rowley [Fri, 16 Aug 2024 22:36:23 +0000 (10:36 +1200)]
Relocate a badly placed Assert in COPY FROM code

There's not much point in asserting a pointer isn't NULL after some code
has already dereferenced that pointer.

Adjust the code so that the Assert occurs before the pointer dereference.

The Assert probably has questionable value in the first place, but it
seems worth keeping around to document the contract between
CopyMultiInsertInfoNextFreeSlot() and its callers.

Author: Amul Sul <[email protected]>
Discussion: https://postgr.es/m/CAAJ_b94hXQzXaJxTLShkxQUgezf_SUxhzX9TH2f-g6gP7bne7g@mail.gmail.com

8 months agoFurther reduce dependence on -fwrapv semantics in jsonb.
Nathan Bossart [Fri, 16 Aug 2024 20:06:40 +0000 (15:06 -0500)]
Further reduce dependence on -fwrapv semantics in jsonb.

Commit 108d2adb9e missed updating a few places in the jsonb code
that rely on signed integer wrapping for correctness.  These can
also be fixed by using pg_abs_s32() to negate a signed integer
(that is known to be negative) for comparison with an unsigned
integer.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/bfff906f-300d-81ea-83b7-f2c93845e7f2%40gmail.com

8 months agopg_verifybackup: Move some declarations to new pg_verifybackup.h
Robert Haas [Fri, 16 Aug 2024 19:09:42 +0000 (15:09 -0400)]
pg_verifybackup: Move some declarations to new pg_verifybackup.h

This is in preparation for adding a second source file to this
directory.

Amul Sul, reviewed by Sravan Kumar and revised a bit by me.

Discussion: http://postgr.es/m/CAAJ_b95mcGjkfAf1qduOR97CokW8-_i-dWLm3v6x1w2-OW9M+A@mail.gmail.com

8 months agopg_verifybackup: Move skip_checksums into verifier_context.
Robert Haas [Fri, 16 Aug 2024 18:52:52 +0000 (14:52 -0400)]
pg_verifybackup: Move skip_checksums into verifier_context.

This is in preparation for adding a second source file to this
directory. It will need access to this value. Also, fewer global
variables is usually a good thing.

Amul Sul, reviewed by Sravan Kumar and revised a bit by me.

Discussion: http://postgr.es/m/CAAJ_b95mcGjkfAf1qduOR97CokW8-_i-dWLm3v6x1w2-OW9M+A@mail.gmail.com

8 months agoImprove more comments in astreamer_gzip.c.
Robert Haas [Fri, 16 Aug 2024 17:34:18 +0000 (13:34 -0400)]
Improve more comments in astreamer_gzip.c.

Duplicate the comment from astreamer_plain_writer_new instead of just
referring to it. Add a further note to mention that there are dangers
if anything else is written to the same FILE. Also add a comment where
we dup() the filehandle, referring to the existing comment in
astreamer_gzip_writer_finalize(), because the dup() looks wrong on
first glance without that comment to clarify.

Per concerns expressed by Tom Lane on pgsql-security, and using
some wording suggested by him.

Discussion: http://postgr.es/m/CA+TgmoYTFAD0YTh4HC1Nuhn0YEyoQi0_CENFgVzAY_YReiSksQ@mail.gmail.com

8 months agolibpq: Trace all messages received from the server
Alvaro Herrera [Fri, 16 Aug 2024 17:23:18 +0000 (13:23 -0400)]
libpq: Trace all messages received from the server

Not all messages that libpq received from the server would be sent
through our message tracing logic.  This commit tries to fix that by
introducing a new function pqParseDone which make it harder to forget
about doing so.

The messages that we now newly send through our tracing logic are:

- CopyData (received by COPY TO STDOUT)
- Authentication requests
- NegotiateProtocolVersion
- Some ErrorResponse messages during connection startup
- ReadyForQuery when received after a FunctionCall message

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoFix extraction of week and quarter fields from intervals.
Tom Lane [Fri, 16 Aug 2024 16:35:50 +0000 (12:35 -0400)]
Fix extraction of week and quarter fields from intervals.

"EXTRACT(WEEK FROM interval_value)" formerly threw an error.
Define it as "tm->tm_mday / 7".  (With C99 division semantics,
this gives consistent results for negative intervals.)

"EXTRACT(QUARTER FROM interval_value)" has been implemented
all along, but it formerly gave extremely strange results for
negative intervals.  Fix it so that the output for -N months
is the negative of the output for N months.

Per bug #18348 from Michael Bondarenko and subsequent discussion.

Discussion: https://postgr.es/m/18348-b097a3587dfde8a4@postgresql.org

8 months agoRemove dependence on -fwrapv semantics in jsonb.
Nathan Bossart [Fri, 16 Aug 2024 16:24:44 +0000 (11:24 -0500)]
Remove dependence on -fwrapv semantics in jsonb.

This commit updates a couple of places in the jsonb code to no
longer rely on signed integer wrapping for correctness.  Like
commit 9e9a2b7031, this is intended to move us closer towards
removing -fwrapv, which may enable some compiler optimizations.
However, there is presently no plan to actually remove that
compiler option in the near future.

This commit makes use of the newly introduced pg_abs_s32() routine
to negate a signed integer (that is known to be negative) for
comparison with an unsigned integer.  In passing, change one use of
INT_MIN to the more portable PG_INT32_MIN.

Reported-by: Alexander Lakhin
Author: Joseph Koshakow
Reviewed-by: Jian He
Discussion: https://postgr.es/m/CAAvxfHdBPOyEGS7s%2Bxf4iaW0-cgiq25jpYdWBqQqvLtLe_t6tw%40mail.gmail.com

8 months agoRemove incidental md5() function use from test
Peter Eisentraut [Fri, 16 Aug 2024 15:14:32 +0000 (17:14 +0200)]
Remove incidental md5() function use from test

To allow test to pass in OpenSSL FIPS mode, similar to 657f5f223e, for
a new test that has been added since.

Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/86763810-70a1-4872-8ba7-1676f788e5a2@eisentraut.org

8 months agoRelax fsyncing at end of a bulk load that was not WAL-logged
Heikki Linnakangas [Fri, 16 Aug 2024 11:45:37 +0000 (14:45 +0300)]
Relax fsyncing at end of a bulk load that was not WAL-logged

And improve the comments.

Backpatch to v17 where this was introduced.

Reviewed-by: Noah Misch
Discussion: https://www.postgresql.org/message-id/cac7d1b6-8358-40be-af0b-21bc9b27d34c@iki.fi

8 months agoRefactor CopyOneRowTo
Heikki Linnakangas [Fri, 16 Aug 2024 10:48:10 +0000 (13:48 +0300)]
Refactor CopyOneRowTo

The handling of binary and text formats are quite different here, so
it's more clear to check for the format first and have two separate
loops.

Author: jian he <[email protected]>
Reviewed-by: Ilia Evdokimov, Junwang Zhao
Discussion: https://www.postgresql.org/message-id/CACJufxFzHCeFBQF0M%[email protected]

8 months agoRemove unused 'cur_skey' argument from IndexScanOK()
Heikki Linnakangas [Fri, 16 Aug 2024 10:13:43 +0000 (13:13 +0300)]
Remove unused 'cur_skey' argument from IndexScanOK()

Commit a78fcfb51243 removed the last use of it.

Author: Hugo Zhang, Aleksander Alekseev
Reviewed-by: Daniel Gustafsson
Discussion: https://www.postgresql.org/message-id/NT0PR01MB129459E243721B954611938F9CDD2%40NT0PR01MB1294.CHNPR01.prod.partner.outlook.cn

8 months agolibpq: Fix minor TOCTOU violation
Peter Eisentraut [Fri, 16 Aug 2024 04:41:17 +0000 (06:41 +0200)]
libpq: Fix minor TOCTOU violation

libpq checks the permissions of the password file before opening it.
The way this is done in two separate operations, a static analyzer
would flag as a time-of-check-time-of-use violation.  In practice, you
can't do anything with that, but it still seems better style to fix
it.

To fix it, open the file first and then check the permissions on the
opened file handle.

Reviewed-by: Aleksander Alekseev <[email protected]>
Reviewed-by: Andreas Karlsson <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/a3356054-14ae-4e7a-acc6-249d19dac20b%40eisentraut.org

8 months agoAdd missing wait_for_catchup() to pg_visibility tap test
Alexander Korotkov [Thu, 15 Aug 2024 21:58:32 +0000 (00:58 +0300)]
Add missing wait_for_catchup() to pg_visibility tap test

e2ed7e32271a introduced check of pg_visibility on standby.  This commit adds
missing wait_for_catchup() to synchronize standby before querying it.

8 months agoFix GetStrictOldestNonRemovableTransactionId() on standby
Alexander Korotkov [Thu, 15 Aug 2024 21:17:59 +0000 (00:17 +0300)]
Fix GetStrictOldestNonRemovableTransactionId() on standby

e85662df44 implemented GetStrictOldestNonRemovableTransactionId() function
for computation of xid horizon that avoid reporting of false errors.
However, GetStrictOldestNonRemovableTransactionId() uses
GetRunningTransactionData() even on standby leading to an assertion failure.

Given that we decided to ignore KnownAssignedXids and standby can't have
own running xids, we switch to use TransamVariables->nextXid as a xid horizon.

Also, revise the comment regarding ignoring KnownAssignedXids with more
detailed reasoning provided by Heikki.

Reported-by: Heikki Linnakangas
Discussion: https://postgr.es/m/42218c4f-2c8d-40a3-8743-4d34dd0e4cce%40iki.fi
Reviewed-by: Heikki Linnakangas
8 months agoRemove dependence on -fwrapv semantics in a few places.
Nathan Bossart [Thu, 15 Aug 2024 20:47:31 +0000 (15:47 -0500)]
Remove dependence on -fwrapv semantics in a few places.

This commit attempts to update a few places, such as the money,
numeric, and timestamp types, to no longer rely on signed integer
wrapping for correctness.  This is intended to move us closer
towards removing -fwrapv, which may enable some compiler
optimizations.  However, there is presently no plan to actually
remove that compiler option in the near future.

Besides using some of the existing overflow-aware routines in
int.h, this commit introduces and makes use of some new ones.
Specifically, it adds functions that accept a signed integer and
return its absolute value as an unsigned integer with the same
width (e.g., pg_abs_s64()).  It also adds functions that accept an
unsigned integer, store the result of negating that integer in a
signed integer with the same width, and return whether the negation
overflowed (e.g., pg_neg_u64_overflow()).

Finally, this commit adds a couple of tests for timestamps near
POSTGRES_EPOCH_JDATE.

Author: Joseph Koshakow
Reviewed-by: Tom Lane, Heikki Linnakangas, Jian He
Discussion: https://postgr.es/m/CAAvxfHdBPOyEGS7s%2Bxf4iaW0-cgiq25jpYdWBqQqvLtLe_t6tw%40mail.gmail.com

8 months agoAdd 97add39c0 to .git-blame-ignore-revs.
Tom Lane [Thu, 15 Aug 2024 15:43:55 +0000 (11:43 -0400)]
Add 97add39c0 to .git-blame-ignore-revs.

8 months agoClean up indentation and whitespace inconsistencies in ecpg.
Tom Lane [Thu, 15 Aug 2024 15:41:46 +0000 (11:41 -0400)]
Clean up indentation and whitespace inconsistencies in ecpg.

ecpg's lexer and parser files aren't normally processed by
pgindent, and unsurprisingly there's a lot of code in there
that doesn't really match project style.  I spent some time
running pgindent over the fragments of these files that are
C code, and this is the result.  This is in the same spirit
as commit 30ed71e42, though apparently Peter used a different
method for that one, since it didn't find these problems.

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

8 months agoDo not hardcode PG_PROTOCOL_LATEST in NegotiateProtocolVersion
Robert Haas [Thu, 15 Aug 2024 14:44:15 +0000 (10:44 -0400)]
Do not hardcode PG_PROTOCOL_LATEST in NegotiateProtocolVersion

We shouldn't ask the client to use a protocol version later than the
one that they requested. To avoid that, if the client requests a
version newer than the latest one we support, set FrontendProtocol
to the latest version we support, not the requested version. Then,
use that value when building the NegotiateProtocolVersion message.
(It seems good on general principle to avoid setting FrontendProtocol
to a version we don't support, anyway.)

None of this really matters right now, because we only support a
single protocol version, but if that ever changes, we'll need this.

Jelte Fennema-Nio, reviewed by me and incorporating some of my
proposed wording

Discussion: https://postgr.es/m/CAGECzQTyXDNtMXdq2L-Wp=OvOCPa07r6+U_MGb==h90MrfT+fQ@mail.gmail.com

8 months agoOptimise numeric multiplication using base-NBASE^2 arithmetic.
Dean Rasheed [Thu, 15 Aug 2024 09:36:17 +0000 (10:36 +0100)]
Optimise numeric multiplication using base-NBASE^2 arithmetic.

Currently mul_var() uses the schoolbook multiplication algorithm,
which is O(n^2) in the number of NBASE digits. To improve performance
for large inputs, convert the inputs to base NBASE^2 before
multiplying, which effectively halves the number of digits in each
input, theoretically speeding up the computation by a factor of 4. In
practice, the actual speedup for large inputs varies between around 3
and 6 times, depending on the system and compiler used. In turn, this
significantly reduces the runtime of the numeric_big regression test.

For this to work, 64-bit integers are required for the products of
base-NBASE^2 digits, so this works best on 64-bit machines, on which
it is faster whenever the shorter input has more than 4 or 5 NBASE
digits. On 32-bit machines, the additional overheads, especially
during carry propagation and the final conversion back to base-NBASE,
are significantly higher, and it is only faster when the shorter input
has more than around 50 NBASE digits. When the shorter input has more
than 6 NBASE digits (so that mul_var_short() cannot be used), but
fewer than around 50 NBASE digits, there may be a noticeable slowdown
on 32-bit machines. That seems to be an acceptable tradeoff, given the
performance gains for other inputs, and the effort that would be
required to maintain code specifically targeting 32-bit machines.

Joel Jacobson and Dean Rasheed.

Discussion: https://postgr.es/m/9d8a4a42-c354-41f3-bbf3-199e1957db97%40app.fastmail.com

8 months agoExtend mul_var_short() to 5 and 6-digit inputs.
Dean Rasheed [Thu, 15 Aug 2024 09:33:12 +0000 (10:33 +0100)]
Extend mul_var_short() to 5 and 6-digit inputs.

Commit ca481d3c9a introduced mul_var_short(), which is used by
mul_var() whenever the shorter input has 1-4 NBASE digits and the
exact product is requested. As speculated on in that commit, it can be
extended to work for more digits in the shorter input. This commit
extends it up to 6 NBASE digits (up to 24 decimal digits), for which
it also gives a significant speedup. This covers more cases likely to
occur in real-world queries, for which using base-NBASE^2 arithmetic
provides little benefit.

To avoid code bloat and duplication, refactor it a bit using macros
and exploiting the fact that some portions of the code are shared
between the different cases.

Dean Rasheed, reviewed by Joel Jacobson.

Discussion: https://postgr.es/m/9d8a4a42-c354-41f3-bbf3-199e1957db97%40app.fastmail.com

8 months agoVariable renaming in dbcommands.c
Peter Eisentraut [Thu, 15 Aug 2024 05:08:12 +0000 (07:08 +0200)]
Variable renaming in dbcommands.c

There were several sets of very similar local variable names, such as
"downer" and "dbowner", which was very confusing and error-prone.
Rename the former to "ownerEl" and so on, similar to collationcmds.c
and typecmds.c.

Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e5bce225-ee04-40c7-a280-ea7214318048%40eisentraut.org

8 months agoFix doc typo: unicode_assigned() return type.
Jeff Davis [Thu, 15 Aug 2024 02:05:39 +0000 (19:05 -0700)]
Fix doc typo: unicode_assigned() return type.

Reported-by: Hironobu SUZUKI
Discussion: https://postgr.es/m/5dd88820-bb00-4b90-904b-738ea2e4ee2e@interdb.jp
Backpatch-through: 17

8 months agoImprove ALTER PUBLICATION validation and error messages
David Rowley [Thu, 15 Aug 2024 01:10:25 +0000 (13:10 +1200)]
Improve ALTER PUBLICATION validation and error messages

Attempting to add a system column for a table to an existing publication
would result in the not very intuitive error message of:

ERROR:  negative bitmapset member not allowed

Here we improve that to have it display the same error message as a user
would see if they tried adding a system column for a table when adding
it to the publication in the first place.

Doing this requires making the function which validates the list of
columns an extern function.  The signature of the static function wasn't
an ideal external API as it made the code more complex than it needed to be.
Here we adjust the function to have it populate a Bitmapset of attribute
numbers.  Doing it this way allows code simplification.

There was no particular bug here other than the weird error message, so
no backpatch.

Bug: #18558
Reported-by: Alexander Lakhin <[email protected]>
Author: Peter Smith, David Rowley
Discussion: https://postgr.es/m/18558-411bc81b03592125@postgresql.org

8 months agoAdd a couple of recent commits to .git-blame-ignore-revs.
Nathan Bossart [Wed, 14 Aug 2024 19:25:54 +0000 (14:25 -0500)]
Add a couple of recent commits to .git-blame-ignore-revs.

8 months agolibpq: Trace responses to SSLRequest and GSSENCRequest
Alvaro Herrera [Wed, 14 Aug 2024 18:53:55 +0000 (14:53 -0400)]
libpq: Trace responses to SSLRequest and GSSENCRequest

Since these are single bytes instead of v2 or v3 messages they need
custom tracing logic.  These "messages" don't even have official names
in the protocol specification, so I (Jelte) called them SSLResponse and
GSSENCResponse here.

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoApply PGDLLIMPORT markings to some GUC variables
Peter Eisentraut [Wed, 14 Aug 2024 09:36:12 +0000 (11:36 +0200)]
Apply PGDLLIMPORT markings to some GUC variables

According to the commit message in 8ec569479, we must have all variables
in header files marked with PGDLLIMPORT. In commit d3cc5ffe81f6 some
variables were moved from launch_backend.c file to several header files.

This adds PGDLLIMPORT to moved variables.

Author: Sofia Kopikova <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0b17014-5319-4dd6-91cd-93d9c8fc9539%40postgrespro.ru

8 months agoRemove TRACE_SORT macro
Peter Eisentraut [Wed, 14 Aug 2024 06:02:32 +0000 (08:02 +0200)]
Remove TRACE_SORT macro

The TRACE_SORT macro guarded the availability of the trace_sort GUC
setting.  But it has been enabled by default ever since it was
introduced in PostgreSQL 8.1, and there have been no reports that
someone wanted to disable it.  So just remove the macro to simplify
things.  (For the avoidance of doubt: The trace_sort GUC is still
there.  This only removes the rarely-used macro guarding it.)

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/be5f7162-7c1d-44e3-9a78-74dcaa6529f2%40eisentraut.org

8 months agoHarmonize MinGW CODESET lookup with MSVC.
Thomas Munro [Wed, 14 Aug 2024 03:02:12 +0000 (15:02 +1200)]
Harmonize MinGW CODESET lookup with MSVC.

Historically, MinGW environments lacked some Windows API calls, so we
took a different code path in win32_langinfo().  Somehow, the code
change in commit 35eeea62 (removing setlocale() calls) caused one
particular 001_initdb.pl test to fail on MinGW + ICU builds, because
pg_import_system_collations() found no collations.  It might take a
MinGW user to discover the exact reason.

Updating that function to use the same code as MSVC seems to fix that
test, so lets do that.  (There are plenty more places that test for MSVC
unnecessarily, to be investigated later.)

While here, also rename the helper function win32_langinfo() to
win32_get_codeset(), to explain what it does less confusingly; it's not
really a general langinfo() substitute.

Noticed by triggering the optional MinGW CI task; no build farm animals
failed.

Discussion: https://postgr.es/m/CA%2BhUKGKBWfhXQ3J%2B2Lj5PhKvQnGD%3DsywA0XQcb7boTCf%3DerVLg%40mail.gmail.com

8 months agoAdd resource statistics reporting to ANALYZE VERBOSE.
Masahiko Sawada [Wed, 14 Aug 2024 02:23:56 +0000 (19:23 -0700)]
Add resource statistics reporting to ANALYZE VERBOSE.

Previously, log_autovacuum_min_duration utilized dedicated code for
logging resource statistics, such as system and buffer usage during
autoanalyze. However, this logging functionality was not utilized by
ANALYZE VERBOSE.

This commit adds resource statistics reporting to ANALYZE VERBOSE by
reusing the same logging code as autoanalyze.

Author: Anthonin Bonnefoy
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com

8 months agoUse pgBufferUsage for buffer usage tracking in analyze.
Masahiko Sawada [Wed, 14 Aug 2024 01:49:45 +0000 (18:49 -0700)]
Use pgBufferUsage for buffer usage tracking in analyze.

Previously, (auto)analyze used global variables VacuumPageHit,
VacuumPageMiss, and VacuumPageDirty to track buffer usage. However,
pgBufferUsage provides a more generic way to track buffer usage with
support functions.

This change replaces those global variables with pgBufferUsage in
analyze. Since analyze was the sole user of those variables, it
removes their declarations. Vacuum previously used those variables but
replaced them with pgBufferUsage as part of a bug fix, commit
5cd72cc0c.

Additionally, it adjusts the buffer usage message in both vacuum and
analyze for better consistency.

Author: Anthonin Bonnefoy
Reviewed-by: Masahiko Sawada, Michael Paquier
Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com

8 months agoInclude <xlocale.h> for macOS, take II.
Thomas Munro [Tue, 13 Aug 2024 11:42:58 +0000 (23:42 +1200)]
Include <xlocale.h> for macOS, take II.

Fix typo in macro name.

Discussion: https://postgr.es/m/CA%2BhUKG%2Bk-o3N_SyNJNJpAcdtMo_HheN30miAeXehk9yw%3D9WYzA%40mail.gmail.com

8 months agoInclude <xlocale.h> for older macOS.
Thomas Munro [Tue, 13 Aug 2024 11:02:05 +0000 (23:02 +1200)]
Include <xlocale.h> for older macOS.

Commit 35eeea62 forgot to include <xlocale.h> when using locale_t
(which didn't seem to be required on newer Apple SDK as used by CI,
hence mistake).  Let's see if this fixes build farm animals longfin and
sifika.

8 months agoUse thread-safe nl_langinfo_l(), not nl_langinfo().
Thomas Munro [Tue, 13 Aug 2024 10:27:16 +0000 (22:27 +1200)]
Use thread-safe nl_langinfo_l(), not nl_langinfo().

This gets rid of some setlocale() calls.  The remaining call to
setlocale() in pg_get_encoding_from_locale() is a query of the name
of the current locale when none was provided (in a multi-threaded future
that would need more work).

All known non-Windows targets have nl_langinfo_l(), from POSIX 2008, and
for Windows we already do something thread-safe.

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJqVe0%2BPv9dvC9dSums_PXxGo9SWcxYAMBguWJUGbWz-A%40mail.gmail.com

8 months agoAll POSIX systems have langinfo.h and CODESET.
Thomas Munro [Tue, 13 Aug 2024 10:13:52 +0000 (22:13 +1200)]
All POSIX systems have langinfo.h and CODESET.

We don't need configure probes for HAVE_LANGINFO_H (it is implied by
!WIN32), and we don't need to consider systems that have it but don't
define CODESET (that was for OpenBSD in commit 81cca218, but it has now
had it for 19 years).

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJqVe0%2BPv9dvC9dSums_PXxGo9SWcxYAMBguWJUGbWz-A%40mail.gmail.com

8 months agoUse errmsg_internal for debug messages
Peter Eisentraut [Tue, 13 Aug 2024 08:01:49 +0000 (10:01 +0200)]
Use errmsg_internal for debug messages

Some newer code was applying this inconsistently.

8 months agoRename C23 keyword
Peter Eisentraut [Tue, 13 Aug 2024 04:15:28 +0000 (06:15 +0200)]
Rename C23 keyword

constexpr is a keyword in C23.  Rename a conflicting identifier for
future-proofing.

Reviewed-by: Robert Haas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/08abc832-1384-4aca-a535-1a79765b565e%40eisentraut.org

8 months agolibpq: Trace frontend authentication challenges
Alvaro Herrera [Mon, 12 Aug 2024 23:12:54 +0000 (19:12 -0400)]
libpq: Trace frontend authentication challenges

If tracing was enabled during connection startup, these messages would
previously be listed in the trace output as something like this:

F 54 Unknown message: 70
mismatched message length: consumed 4, expected 54

With this commit their type and contents are now correctly listed:

F 36 StartupMessage  3 0 "user" "foo" "database" "alvherre"
F 54 SASLInitialResponse  "SCRAM-SHA-256" 32 'n,,n=,r=nq5zEPR/VREHEpOAZzH8Rujm'
F 108 SASLResponse  'c=biws,r=nq5zEPR/VREHEpOAZzH8RujmVtWZDQ8glcrvy9OMNw7ZqFUn,p=BBwAKe0WjSvigB6RsmmArAC+hwucLeuwJrR5C/HQD5M='

Author: Jelte Fennema-Nio <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoFix nls.mk to reflect astreamer files relocation
Alvaro Herrera [Mon, 12 Aug 2024 22:42:18 +0000 (18:42 -0400)]
Fix nls.mk to reflect astreamer files relocation

In the recent commit f80b09bac8, astreamer files were moved to another
directory, but this change was not reflected in nls.mk.  This commit
corrects that oversight.

Author: Kyotaro Horiguchi <[email protected]>
Discussion: https://postgr.es/m/20240806.102123.648178476296575604[email protected]

8 months agoFix creation of partition descriptor during concurrent detach+drop
Alvaro Herrera [Mon, 12 Aug 2024 22:17:56 +0000 (18:17 -0400)]
Fix creation of partition descriptor during concurrent detach+drop

If a partition undergoes DETACH CONCURRENTLY immediately followed by
DROP, this could cause a problem for a concurrent transaction
recomputing the partition descriptor when running a prepared statement,
because it tries to dereference a pointer to a tuple that's not found in
a catalog scan.

The existing retry logic added in commit dbca3469ebf8 is sufficient to
cope with the overall problem, provided we don't try to dereference a
non-existant heap tuple.

Arguably, the code in RelationBuildPartitionDesc() has been wrong all
along, since no check was added in commit 898e5e3290a7 against receiving
a NULL tuple from the catalog scan; that bug has only become
user-visible with DETACH CONCURRENTLY which was added in branch 14.
Therefore, even though there's no known mechanism to cause a crash
because of this, backpatch the addition of such a check to all supported
branches.  In branches prior to 14, this would cause the code to fail
with a "missing relpartbound for relation XYZ" error instead of
crashing; that's okay, because there are no reports of such behavior
anyway.

Author: Kuntal Ghosh <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/18559-b48286d2eacd9a4e@postgresql.org

8 months agoRemove unnecessary check for NULL locale, per Coverity.
Jeff Davis [Mon, 12 Aug 2024 19:26:23 +0000 (12:26 -0700)]
Remove unnecessary check for NULL locale, per Coverity.

Discussion: https://postgr.es/m/3804933.1723394010@sss.pgh.pa.us
Reported-by: Tom Lane
8 months agoGive nbtree move right function internal linkage.
Peter Geoghegan [Mon, 12 Aug 2024 18:36:55 +0000 (14:36 -0400)]
Give nbtree move right function internal linkage.

Declare _bt_moveright() static.  This is a minor modularity win; the
routine was already private to nbtsearch.c for all practical purposes.

Author: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAEze2WgWVzCNEXQB_op5MMZMDgJ3fg3AhVm6bq2iZPpJNXGhWw@mail.gmail.com

8 months agoLog more info when wait-for-catchup tests time out.
Tom Lane [Mon, 12 Aug 2024 17:18:36 +0000 (13:18 -0400)]
Log more info when wait-for-catchup tests time out.

Cluster.pm's wait_for_catchup and allied subroutines don't provide
enough information to diagnose the problem when a wait times out.
In hopes of debugging some intermittent buildfarm failures, let's
dump the ending state of the relevant system view when that happens.

Add this to v17 too, but not stable branches.

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

8 months agoAdd user-callable CRC functions.
Nathan Bossart [Mon, 12 Aug 2024 15:35:06 +0000 (10:35 -0500)]
Add user-callable CRC functions.

We've had code for CRC-32 and CRC-32C for some time (for WAL
records, etc.), but there was no way for users to call it, despite
apparent popular demand.  The new crc32() and crc32c() functions
accept bytea input and return bigint (to avoid returning negative
values).

Bumps catversion.

Author: Aleksander Alekseev
Reviewed-by: Peter Eisentraut, Tom Lane
Discussion: https://postgr.es/m/CAJ7c6TNMTGnqnG%3DyXXUQh9E88JDckmR45H2Q%2B%3DucaCLMOW1QQw%40mail.gmail.com

8 months agoFix outdated comments
David Rowley [Mon, 12 Aug 2024 11:41:13 +0000 (23:41 +1200)]
Fix outdated comments

A few fields in ResultRelInfo are now also used for MERGE.  Update the
comments to mention that.

Reported-by: jian he <[email protected]>
Discussion: https://postgr.es/m/CACJufxH8-NvFhLcSZZTTW+1M9AfS4+SOTKmyPG7ZhzNvN=+NkA@mail.gmail.com:wq

8 months agoFix a series of typos and outdated references
David Rowley [Mon, 12 Aug 2024 11:27:09 +0000 (23:27 +1200)]
Fix a series of typos and outdated references

Author: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/c1d63754-cb85-2d8a-8409-bde2c4d2d04b@gmail.com

8 months agoFix bad indentation introduced in commit f011e82c2c
Heikki Linnakangas [Mon, 12 Aug 2024 07:57:03 +0000 (10:57 +0300)]
Fix bad indentation introduced in commit f011e82c2c

8 months agoConsolidate postmaster code to launch background processes
Heikki Linnakangas [Mon, 12 Aug 2024 07:04:26 +0000 (10:04 +0300)]
Consolidate postmaster code to launch background processes

Much of the code in process_pm_child_exit() to launch replacement
processes when one exits or when progressing to next postmaster state
was unnecessary, because the ServerLoop will launch any missing
background processes anyway. Remove the redundant code and let
ServerLoop handle it.

In ServerLoop, move the code to launch all the processes to a new
subroutine, to group it all together.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/8f2118b9-79e3-4af7-b2c9-bd5818193ca4@iki.fi

8 months agoRemove dead code
Peter Eisentraut [Mon, 12 Aug 2024 06:43:47 +0000 (08:43 +0200)]
Remove dead code

After e9931bfb751, the locale argument of SB_lower_char() is never
NULL, so the branch that deals with NULL can be removed (similar to
how e9931bfb751 for example removed those branches in str_tolower()).

Reviewed-by: Jeff Davis <[email protected]>
Discussion: https://www.postgresql.org/message-id/4f562d84-87f4-44dc-8946-01d6c437936f@eisentraut.org

8 months agoRemove fe_memutils from libpgcommon_shlib
Peter Eisentraut [Mon, 12 Aug 2024 06:30:39 +0000 (08:30 +0200)]
Remove fe_memutils from libpgcommon_shlib

libpq must not use palloc/pfree. It's not allowed to exit on allocation
failure, and mixing the frontend pfree with malloc is architecturally
unsound.

Remove fe_memutils from the shlib build entirely, to keep devs from
accidentally depending on it in the future.

Author: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/CAOYmi+=pg=W5L1h=3MEP_EB24jaBu2FyATrLXqQHGe7cpuvwyg@mail.gmail.com

8 months agoRemove support for old realpath() API
Peter Eisentraut [Mon, 12 Aug 2024 05:59:40 +0000 (07:59 +0200)]
Remove support for old realpath() API

The now preferred way to call realpath() is by passing NULL as the
second argument and get a malloc'ed result.  We still supported the
old way of providing our own buffer as a second argument, for some
platforms that didn't support the new way yet.  Those were only
Solaris less than version 11 and some older AIX versions (7.1 and
newer appear to support the new variant).  We don't support those
platforms versions anymore, so we can remove this extra code.

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/9e638b49-5c3f-470f-a392-2cbedb2f7855%40eisentraut.org

8 months agoRemove "parent" column from pg_backend_memory_contexts
David Rowley [Mon, 12 Aug 2024 03:42:16 +0000 (15:42 +1200)]
Remove "parent" column from pg_backend_memory_contexts

32d3ed816 added the "path" column to pg_backend_memory_contexts to allow
a stable method of obtaining the parent MemoryContext of a given row in
the view.  Using the "path" column is now the preferred method of
obtaining the parent row.

Previously, any queries which were self-joining to this view using the
"name" and "parent" columns could get incorrect results due to the fact
that names are not unique.  Here we aim to explicitly break such queries
so that they can be corrected and use the "path" column instead.

It is possible that there are more innocent users of the parent column
that just need an indication of the parent and having to write out a
self-joining CTE may be an unnecessary hassle for those cases.  Let's
remove the column for now and see if anyone comes back with any
complaints.  This does seem like a good time to attempt to get rid of
the column as we still have around 1 year to revert this if someone comes
back with a valid complaint.  Plus this view is new to v14 and is quite
niche, so perhaps not many people will be affected.

Author: Melih Mutlu <[email protected]>
Discussion: https://postgr.es/m/CAGPVpCT7NOe4fZXRL8XaoxHpSXYTu6GTpULT_3E-HT9hzjoFRA@mail.gmail.com

8 months agoAvoid unneeded nbtree backwards scan buffer locks.
Peter Geoghegan [Sun, 11 Aug 2024 19:42:52 +0000 (15:42 -0400)]
Avoid unneeded nbtree backwards scan buffer locks.

Teach nbtree backwards scans to avoid relocking a just-read leaf page to
read its current left sibling link when it isn't truly necessary.  This
happened inside _bt_readnextpage whenever _bt_readpage had already
determined that there'll be no further matches to the left (or at least
none for the current primitive index scan, for a scan with array keys).

A new precheck inside _bt_readnextpage is all that we need to avoid
these useless lock acquisitions.  Arguably, using a precheck like this
was a missed opportunity for commit 2ed5b87f96, which taught nbtree to
drop leaf page pins early to avoid blocking cleanup by VACUUM.  Forwards
scans already managed to avoid relocking the page like this.

The optimization added by this commit is particularly helpful with
backwards scans that use array keys where the scan must perform multiple
primitive index scans.  Such backwards scans will now avoid a useless
leaf page re-lock at the end of each primitive index scan.

Note that this commit does not attempt to avoid needlessly re-locking a
leaf page that was just read when the scan must follow the leaf page's
left link.  That more ambitious optimization could work by stashing the
left link when the page is first read by a backwards scan, allowing the
subsequent _bt_readnextpage call to optimistically skip re-reading the
original page just to get a new copy of its left link.  For now we only
address cases where we don't care about our original page's left link.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=xgs7PojG=EUvhgadwENzu_mY_riNh-w9wFPsaS717ew@mail.gmail.com

8 months agoInitialize HASHCTL differently, to suppress Coverity warning
Heikki Linnakangas [Sun, 11 Aug 2024 17:21:16 +0000 (20:21 +0300)]
Initialize HASHCTL differently, to suppress Coverity warning

Coverity complained that the hash_create() call might access
hash_table_ctl->hctl. That's a false alarm, hash_create() only
accesses that field when passed the HASH_SHARED_MEM flag. Try to
silence it by using a plain local variable instead of a const. That's
how the HASHCTL is initialized in all the other hash_create() calls.

8 months agoSuppress Coverity warnings about Asserts in get_name_for_var_field.
Tom Lane [Sun, 11 Aug 2024 16:24:56 +0000 (12:24 -0400)]
Suppress Coverity warnings about Asserts in get_name_for_var_field.

Coverity thinks dpns->plan could be null at these points.  That
shouldn't really be possible, but it's easy enough to modify the
Asserts so they'd not core-dump if it were true.

These are new in b919a97a6.  Back-patch to v13; the v12 version
of the patch didn't have these Asserts.

8 months agoAllow adjusting session_authorization and role in parallel workers.
Tom Lane [Sat, 10 Aug 2024 19:51:28 +0000 (15:51 -0400)]
Allow adjusting session_authorization and role in parallel workers.

The code intends to allow GUCs to be set within parallel workers
via function SET clauses, but not otherwise.  However, doing so fails
for "session_authorization" and "role", because the assign hooks for
those attempt to set the subsidiary "is_superuser" GUC, and that call
falls foul of the "not otherwise" prohibition.  We can't switch to
using GUC_ACTION_SAVE for this, so instead add a new GUC variable
flag GUC_ALLOW_IN_PARALLEL to mark is_superuser as being safe to set
anyway.  (This is okay because is_superuser has context PGC_INTERNAL
and thus only hard-wired calls can change it.  We'd need more thought
before applying the flag to other GUCs; but maybe there are other
use-cases.)  This isn't the prettiest fix perhaps, but other
alternatives we thought of would be much more invasive.

While here, correct a thinko in commit 059de3ca4: when rejecting
a GUC setting within a parallel worker, we should return 0 not -1
if the ereport doesn't longjmp.  (This seems to have no consequences
right now because no caller cares, but it's inconsistent.)  Improve
the comments to try to forestall future confusion of the same kind.

Despite the lack of field complaints, this seems worth back-patching.
Thanks to Nathan Bossart for the idea to invent a new flag,
and for review.

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

8 months agoAdd tests for pg_wal_replay_wait() errors
Alexander Korotkov [Sat, 10 Aug 2024 18:43:14 +0000 (21:43 +0300)]
Add tests for pg_wal_replay_wait() errors

Improve test coverage for pg_wal_replay_wait() procedure by adding test
cases when it errors out.

8 months agoImprove header comment for WaitLSNSetLatches()
Alexander Korotkov [Sat, 10 Aug 2024 18:43:09 +0000 (21:43 +0300)]
Improve header comment for WaitLSNSetLatches()

Reflect the fact that we remove waiters from the heap, not just set their
latches.

8 months agoAdjust pg_wal_replay_wait() procedure behavior on promoted standby
Alexander Korotkov [Sat, 10 Aug 2024 18:43:02 +0000 (21:43 +0300)]
Adjust pg_wal_replay_wait() procedure behavior on promoted standby

pg_wal_replay_wait() is intended to be called on standby.  However, standby
can be promoted to primary at any moment, even concurrently with the
pg_wal_replay_wait() call.  If recovery is not currently in progress
that doesn't mean the wait was unsuccessful.  Thus, we always need to recheck
if the target LSN is replayed.

Reported-by: Kevin Hale Boyes
Discussion: https://postgr.es/m/CAPpHfdu5QN%2BZGACS%2B7foxmr8_nekgA2PA%2B-G3BuOUrdBLBFb6Q%40mail.gmail.com
Author: Alexander Korotkov

8 months agoLower minimum maintenance_work_mem to 64kB
John Naylor [Tue, 6 Aug 2024 13:38:33 +0000 (20:38 +0700)]
Lower minimum maintenance_work_mem to 64kB

Since the introduction of TID store, vacuum uses far less memory in
the common case than in versions 16 and earlier. Invoking multiple
rounds of index vacuuming in turn requires a much larger table. It'd
be a good idea anyway to cover this case in regression testing, and a
lower limit is less painful for slow buildfarm animals. The reason to
do it now is to re-enable coverage of the bugfix in commit 83c39a1f7f.

For consistency, give autovacuum_work_mem the same treatment.

Suggested by Andres Freund
Tested by Melanie Plageman
Backpatch to v17, where TID store was introduced

Discussion: https://postgr.es/m/20240516205458[email protected]
Discussion: https://postgr.es/m/20240722164745.fvaoh6g6zprisqgp%40awork3.anarazel.de

8 months agoFix inappropriate uses of atol()
Peter Eisentraut [Sat, 10 Aug 2024 06:12:44 +0000 (08:12 +0200)]
Fix inappropriate uses of atol()

Some code using atol() would not work correctly if sizeof(long)==4:

- src/bin/pg_basebackup/pg_basebackup.c: Would miscount size of a
  tablespace over 2 TB.

- src/bin/pg_basebackup/streamutil.c: Would truncate a timeline ID
  beyond INT32_MAX.

- src/bin/pg_rewind/libpq_source.c: Would miscount size of files
  larger than 2 GB (but this currently cannot happen).

Replace these with atoll().

In one case, the use of atol() did not result in incorrect behavior
but seems inconsistent with related code:

- src/interfaces/ecpg/ecpglib/execute.c: Gratuitous, since it
  processes a value from pg_type.typlen, which is int16.

Replace this with atoi().

Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/a52738ad-06bc-4d45-b59f-b38a8a89de49%40eisentraut.org

8 months agolibpq: Trace StartupMessage/SSLRequest/GSSENCRequest correctly
Alvaro Herrera [Fri, 9 Aug 2024 21:55:01 +0000 (17:55 -0400)]
libpq: Trace StartupMessage/SSLRequest/GSSENCRequest correctly

libpq tracing via PQtrace would uselessly print the wrong thing for
these types of messages.  With this commit, their type and contents
would be correctly listed.  (This can be verified with PQconnectStart(),
but we don't use that in libpq_pipeline, so I (Álvaro) haven't bothered
to add any tests.)

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoFix comment on processes being kept over a restart
Heikki Linnakangas [Fri, 9 Aug 2024 21:06:19 +0000 (00:06 +0300)]
Fix comment on processes being kept over a restart

All child processes except the syslogger are killed on a restart. The
archiver might be already running though, if it was started during
recovery.

The split in the comments between "other special children" and the
first group of "background tasks" seemed really arbitrary, so I just
merged them all into one group.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/8f2118b9-79e3-4af7-b2c9-bd5818193ca4@iki.fi

8 months agoRefactor code to handle death of a backend or bgworker in postmaster
Heikki Linnakangas [Fri, 9 Aug 2024 21:04:43 +0000 (00:04 +0300)]
Refactor code to handle death of a backend or bgworker in postmaster

Currently, when a child process exits, the postmaster first scans
through BackgroundWorkerList, to see if it the child process was a
background worker. If not found, then it scans through BackendList to
see if it was a regular backend. That leads to some duplication
between the bgworker and regular backend cleanup code, as both have an
entry in the BackendList that needs to be cleaned up in the same way.
Refactor that so that we scan just the BackendList to find the child
process, and if it was a background worker, do the additional
bgworker-specific cleanup in addition to the normal Backend cleanup.

Change HandleChildCrash so that it doesn't try to handle the cleanup
of the process that already exited, only the signaling of all the
other processes. When called for any of the aux processes, the caller
had already cleared the *PID global variable, so the code in
HandleChildCrash() to do that was unused.

On Windows, if a child process exits with ERROR_WAIT_NO_CHILDREN, it's
now logged with that exit code, instead of 0. Also, if a bgworker
exits with ERROR_WAIT_NO_CHILDREN, it's now treated as crashed and is
restarted. Previously it was treated as a normal exit.

If a child process is not found in the BackendList, the log message
now calls it "untracked child process" rather than "server process".
Arguably that should be a PANIC, because we do track all the child
processes in the list, so failing to find a child process is highly
unexpected. But if we want to change that, let's discuss and do that
as a separate commit.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agoMake BackgroundWorkerList doubly-linked
Heikki Linnakangas [Fri, 9 Aug 2024 19:44:20 +0000 (22:44 +0300)]
Make BackgroundWorkerList doubly-linked

This allows ForgetBackgroundWorker() and ReportBackgroundWorkerExit()
to take a RegisteredBgWorker pointer as argument, rather than a list
iterator. That feels a little more natural. But more importantly, this
paves the way for more refactoring in the next commit.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi

8 months agodoc: Standardize use of dashes in references to CRC and SHA.
Nathan Bossart [Fri, 9 Aug 2024 18:16:33 +0000 (13:16 -0500)]
doc: Standardize use of dashes in references to CRC and SHA.

Presently, we inconsistently use dashes in references to these
algorithms (e.g., CRC32C versus CRC-32C).  Some popular web sources
appear to prefer dashes, and with this commit, we will, too.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/ZrUFpLP-w2zTAHqq%40nathan

8 months agodoc: Fix name of CRC algorithm in "Reliability" section.
Nathan Bossart [Fri, 9 Aug 2024 15:52:37 +0000 (10:52 -0500)]
doc: Fix name of CRC algorithm in "Reliability" section.

This section claims we use CRC-32 for WAL records and two-phase
state files, but we've actually used CRC-32C since v9.5 (commit
5028f22f6e).  Fix that.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/ZrUFpLP-w2zTAHqq%40nathan
Backpatch-through: 12

8 months agoFix "failed to find plan for subquery/CTE" errors in EXPLAIN.
Tom Lane [Fri, 9 Aug 2024 15:21:39 +0000 (11:21 -0400)]
Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.

To deparse a reference to a field of a RECORD-type output of a
subquery, EXPLAIN normally digs down into the subquery's plan to try
to discover exactly which anonymous RECORD type is meant.  However,
this can fail if the subquery has been optimized out of the plan
altogether on the grounds that no rows could pass the WHERE quals,
which has been possible at least since 3fc6e2d7f.  There isn't
anything remaining in the plan tree that would help us, so fall back
to printing the field name as "fN" for the N'th column of the record.
(This will actually be the right thing some of the time, since it
matches the column names we assign to RowExprs.)

In passing, fix a comment typo in create_projection_plan, which
I noticed while experimenting with an alternative fix for this.

Per bug #18576 from Vasya B.  Back-patch to all supported branches.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/18576-9feac34e132fea9e@postgresql.org

8 months agoRemove obsolete RECHECK keyword completely
Peter Eisentraut [Fri, 9 Aug 2024 05:17:15 +0000 (07:17 +0200)]
Remove obsolete RECHECK keyword completely

This used to be part of CREATE OPERATOR CLASS and ALTER OPERATOR
FAMILY, but it has done nothing (except issue a NOTICE) since
PostgreSQL 8.4.  Commit 30e7c175b81 removed support for dumping from
pre-9.2 servers, so this no longer serves any need.

This now removes it completely, and you'd get a normal parse error if
you used it.

Reviewed-by: Aleksander Alekseev <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/113ef2d2-3657-4353-be97-f28fceddbca1%40eisentraut.org

8 months agoChange the misleading local end_lsn for prepared transactions.
Amit Kapila [Fri, 9 Aug 2024 04:53:57 +0000 (10:23 +0530)]
Change the misleading local end_lsn for prepared transactions.

The apply worker was using XactLastCommitEnd as local end_lsn for applying
prepare and rollback_prepare. The XactLastCommitEnd value is the end lsn
of the last commit applied before the prepare transaction which makes no
sense. This LSN is used to decide whether we can send the acknowledgment
of the corresponding remote LSN to the server.

It is okay not to set the local_end LSN with the actual WAL position for
the prepare because we always flush the prepare record. So, we can send
the acknowledgment of the remote_end LSN as soon as prepare is finished.

The current code is misleading but as such doesn't create any problem, so
decided not to backpatch.

Author: Hayato Kuroda
Reviewed-by: Shveta Malik, Amit Kapila
Discussion: https://postgr.es/m/TYAPR01MB5692FA4926754B91E9D7B5F0F5AA2@TYAPR01MB5692.jpnprd01.prod.outlook.com

8 months agolibpq: Add suppress argument to pqTraceOutputNchar
Alvaro Herrera [Fri, 9 Aug 2024 00:35:12 +0000 (20:35 -0400)]
libpq: Add suppress argument to pqTraceOutputNchar

In future commits we're going to trace authentication related messages.
Some of these messages contain challenge bytes as part of a
challenge-response flow.  Since these bytes are different for every
connection, we want to normalize them when the PQTRACE_REGRESS_MODE
trace flag is set.  This commit modifies pqTraceOutputNchar to take a
suppress argument, which makes it possible to do so.

Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com

8 months agoRefuse ATTACH of a table referenced by a foreign key
Alvaro Herrera [Thu, 8 Aug 2024 23:35:13 +0000 (19:35 -0400)]
Refuse ATTACH of a table referenced by a foreign key

Trying to attach a table as a partition which is already on the
referenced side of a foreign key on the partitioned table that it is
being attached to, leads to strange behavior: we try to clone the
foreign key from the parent to the partition, but this new FK points to
the partition itself, and the mix of pg_constraint rows and triggers
doesn't behave well.

Rather than trying to untangle the mess (which might be possible given
sufficient time), I opted to forbid the ATTACH.  This doesn't seem a
problematic restriction, given that we already fail to create the
foreign key if you do it the other way around, that is, having the
partition first and the FK second.

Backpatch to all supported branches.

Reported-by: Alexander Lakhin <[email protected]>
Reviewed-by: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/18541-628a61bc267cd2d3@postgresql.org

8 months agoRefactor error messages to reduce duplication
Alvaro Herrera [Thu, 8 Aug 2024 19:17:11 +0000 (15:17 -0400)]
Refactor error messages to reduce duplication

I also took the liberty of changing

errmsg("COPY DEFAULT only available using COPY FROM")
to
errmsg("COPY %s cannot be used with %s", "DEFAULT", "COPY TO")

because the original wording is unlike all other messages that indicate
option incompatibility.  This message was added by commit 9f8377f7a279
(16-era), in whose development thread there was no discussion on this
point.

Backpatch to 17.

8 months agoAdd a caveat to hash_seq_init_with_hash_value() header comment
Alexander Korotkov [Thu, 8 Aug 2024 08:48:57 +0000 (11:48 +0300)]
Add a caveat to hash_seq_init_with_hash_value() header comment

The typical use-case for hash_seq_init_with_hash_value() is syscache
callback.  Add a caveat that the default hash function doesn't match syscache
hash function.  So, one needs to define a custom hash function.

Reported-by: Pavel Stehule
Discussion: https://postgr.es/m/CAFj8pRAXmv6eyYx%3DE_BTfyK%3DO_%2ByOF8sXB%3D0bn9eOBt90EgWRA%40mail.gmail.com
Reviewed-by: Pavel Stehule
8 months agoFix pg_rewind debug output to print the source timeline history
Heikki Linnakangas [Thu, 8 Aug 2024 07:20:25 +0000 (10:20 +0300)]
Fix pg_rewind debug output to print the source timeline history

getTimelineHistory() is called twice, to read the source and the
target timeline history files. However, the loop to print the file
with the --debug option used the wrong variable when dealing with the
source. As a result, the source's history was always printed as empty.

Spotted while debugging bug #18575, but this does not fix that bug,
just the debugging output. Backpatch to all supported versions.

Discussion: https://www.postgresql.org/message-id/092dd515-b7b4-4fd0-8407-ceca2f02f6ec@iki.fi

8 months agoFix names of "Visual Studio" and Meson in a documentation sentence.
Noah Misch [Wed, 7 Aug 2024 18:43:08 +0000 (11:43 -0700)]
Fix names of "Visual Studio" and Meson in a documentation sentence.

Commit 3cffe7946c268be91a340ec9a27081cb93d67d35 missed this.  Back-patch
to v17, which introduced this.

Discussion: https://postgr.es/m/CAJ7c6TM7ct0EjoCQaLSVYoxxnEw4xCUFebWj77GktWsqEdyCtQ@mail.gmail.com

8 months agoFix edge case in plpgsql's make_callstmt_target().
Tom Lane [Wed, 7 Aug 2024 16:54:39 +0000 (12:54 -0400)]
Fix edge case in plpgsql's make_callstmt_target().

If the plancache entry for the CALL statement is already stale,
it's possible for us to fetch an old procedure OID out of it,
and then fail with "cache lookup failed for function NNN".
In ordinary usage this never happens because make_callstmt_target
is called just once immediately after building the plancache
entry.  It can be forced however by setting up an erroneous CALL
(that causes make_callstmt_target itself to report an error),
then dropping/recreating the target procedure, then repeating
the erroneous CALL.

To fix, use SPI_plan_get_cached_plan() to fetch the plancache's
plan, rather than assuming we can use SPI_plan_get_plan_sources().
This shouldn't add any noticeable overhead in the normal case,
and in the stale-plan case we'd have had to replan anyway a little
further down.

The other callers of SPI_plan_get_plan_sources() seem OK, because
either they don't need up-to-date plans or they know that the
query was just (re) planned.  But add some commentary in hopes
of not falling into this trap again.

Per bug #18574 from Song Hongyu.  Back-patch to v14 where this coding
was introduced.  (Older branches have comparable code, but it's run
after any required replanning, so there's no issue.)

Discussion: https://postgr.es/m/18574-2ce7ba3249221389@postgresql.org

8 months agoRefactor/reword some error messages to avoid duplicates
Alvaro Herrera [Wed, 7 Aug 2024 15:30:36 +0000 (11:30 -0400)]
Refactor/reword some error messages to avoid duplicates

Also, remove brackets around "EMPTY [ ARRAY ]".  An error message is
not the place to state that a keyword is optional.

Backpatch to 17.