]> git.ipfire.org Git - thirdparty/postgresql.git/log
thirdparty/postgresql.git
4 months agoDoc: fix prompt in psql crosstabview example
Daniel Gustafsson [Wed, 24 Apr 2024 11:09:50 +0000 (13:09 +0200)] 
Doc: fix prompt in psql crosstabview example

The prompt in the crosstabview example was incorrectly indicating
an open parenthesis where there is none in the example query. Fix
by changing to the normal multi-line prompt.

Reported-by: y.saburov@gmail.com
Discussion: https://postgr.es/m/171369707837.684.8207966689229976474@wrigleys.postgresql.org

4 months agodoc: Fix up spacing around verbatim DocBook elements
Peter Eisentraut [Wed, 24 Apr 2024 10:26:19 +0000 (12:26 +0200)] 
doc: Fix up spacing around verbatim DocBook elements

4 months agopg_combinebackup: Add --version to --help output
Peter Eisentraut [Wed, 24 Apr 2024 10:12:57 +0000 (12:12 +0200)] 
pg_combinebackup: Add --version to --help output

(It was already on the man page.)

4 months agodoc: Correct jsonpath string literal escapes description
Peter Eisentraut [Wed, 24 Apr 2024 09:31:47 +0000 (11:31 +0200)] 
doc: Correct jsonpath string literal escapes description

The paragraph describing the JavaScript string literals allowed in
jsonpath expressions unnecessarily mentions JSON by erroneously
listing \v as allowed by JSON and mentioning the \xNN and \u{N...}
backslash escapes as deviations from JSON when in fact both are
accepted by ECMAScript/JavaScript.  Fix this by only referring to
JavaScript.

Author: Erik Wienhold <ewie@ewie.name>
Discussion: https://www.postgresql.org/message-id/flat/1EB17DF9-2636-484B-9DD0-3CAB19C4F5C4@justatheory.com

4 months agopg_combinebackup: Put newer options in consistent order in --help and man page
Peter Eisentraut [Wed, 24 Apr 2024 08:47:35 +0000 (10:47 +0200)] 
pg_combinebackup: Put newer options in consistent order in --help and man page

4 months agoSupport SSL_R_VERSION_TOO_LOW when using LibreSSL
Daniel Gustafsson [Wed, 24 Apr 2024 08:54:50 +0000 (10:54 +0200)] 
Support SSL_R_VERSION_TOO_LOW when using LibreSSL

The SSL_R_VERSION_TOO_LOW error reason is supported in LibreSSL since
LibreSSL 3.6.3, shipped in OpenBSD 7.2.  SSL_R_VERSION_TOO_HIGH is on
the other hand not supported in any version of LibreSSL.  Previously
we only checked for SSL_R_VERSION_TOO_HIGH and then applied both under
that guard since OpenSSL has only ever supported both at the same time.
This breaks the check into one per reason to allow SSL_R_VERSION_TOO_LOW
to work when using LibreSSL.

Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/eac70d46-e61c-4d71-a1e1-78e2bfa19485@eisentraut.org

4 months agoSupport disallowing SSL renegotiation when using LibreSSL
Daniel Gustafsson [Wed, 24 Apr 2024 08:54:42 +0000 (10:54 +0200)] 
Support disallowing SSL renegotiation when using LibreSSL

LibreSSL doesn't support the SSL_OP_NO_RENEGOTIATION macro which is
used by OpenSSL, instead it has invented a similar one for client-
side renegotiation: SSL_OP_NO_CLIENT_RENEGOTIATION. This has been
supported since LibreSSL 2.5.1 which by now can be considered well
below the minimum requirement.

Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/eac70d46-e61c-4d71-a1e1-78e2bfa19485@eisentraut.org

4 months agoDoc: Use past tense for things which happened in the past
Daniel Gustafsson [Wed, 24 Apr 2024 08:54:36 +0000 (10:54 +0200)] 
Doc: Use past tense for things which happened in the past

The paragraph on SSL compression is largely describing events which
took place many years ago, so reword with past tense.

Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/eac70d46-e61c-4d71-a1e1-78e2bfa19485@eisentraut.org

4 months agopg_dump: Put new options in consistent order in --help and man page
Peter Eisentraut [Wed, 24 Apr 2024 08:00:58 +0000 (10:00 +0200)] 
pg_dump: Put new options in consistent order in --help and man page

4 months agodoc: Fix order of options on pg_createsubscriber man page
Peter Eisentraut [Wed, 24 Apr 2024 07:19:59 +0000 (09:19 +0200)] 
doc: Fix order of options on pg_createsubscriber man page

Some options were listed in an order that was inconsistent with the
--help output and everything else.

4 months agopg_walsummary: Document --version option
Peter Eisentraut [Wed, 24 Apr 2024 06:56:21 +0000 (08:56 +0200)] 
pg_walsummary: Document --version option

It was working, but it was not shown in the --help output or on the
man page.

4 months agoRemove obsolete symbol from ecpg_config.h.in
Peter Eisentraut [Wed, 24 Apr 2024 06:27:25 +0000 (08:27 +0200)] 
Remove obsolete symbol from ecpg_config.h.in

HAVE_LONG_LONG_INT was not added to ecpg_config.h.in by the meson
build system, but rather than add it there, we decided to remove it
from the makefile build system, to make both consistent that way.

There is no documentation or examples that suggest that the presence
of this symbol was publicly advertised, and of course the feature is
required by C99 (but we don't necessarily require C99 for ecpg user
code).  ecpg core code and ecpg tests use the symbol
HAVE_LONG_LONG_INT_64 instead, which is still there.

Discussion: https://www.postgresql.org/message-id/flat/bf35d032-02fc-4173-9f4f-840999cc3ef3%40eisentraut.org

4 months agoTry again to add test coverage for pg_combinebackup w/tablespaces.
Robert Haas [Tue, 23 Apr 2024 20:33:19 +0000 (16:33 -0400)] 
Try again to add test coverage for pg_combinebackup w/tablespaces.

My previous attempt to add this had to be reverted in commit
82023d47de9e262730b1f9b4ea77fae201a89d0a. I've revised the problematic
code a bit; hopefully it is OK now.

Discussion: http://postgr.es/m/CA+Tgmobiv1QJR5PEJoDKeZDrJHZFRmi4XmWOqufN49DJj-3e2g@mail.gmail.com

4 months agoPost review fixes for test_json_parser test module
Andrew Dunstan [Tue, 23 Apr 2024 19:27:40 +0000 (15:27 -0400)] 
Post review fixes for test_json_parser test module

. Add missing copytight notices
. improve code coverage
. put work files in a temp directory in the standard location
. improve error checking in C code
. indent perl files with perltidy
. add some comments

per comments from Michael Paquier

Discussion: https://postgr.es/m/ZiC3-cdFys4-6xSk@paquier.xyz

4 months agoRemove some unnecessary fields from executor nodes.
Tom Lane [Tue, 23 Apr 2024 16:55:26 +0000 (12:55 -0400)] 
Remove some unnecessary fields from executor nodes.

JsonExprState.input_finfo is only assigned to, never read, and
it's really fairly useless since the value can be gotten out of
the adjacent input_fcinfo field.  Let's remove it before someone
starts to depend on it.

While here, also remove TidScanState.tss_htup and AggState.combinedproj,
which are referenced nowhere.  Those should have been removed by the
commits that caused them to become disused, but were not.

I don't think a catversion bump is necessary here, since plan trees
are never stored on disk.

Matthias van de Meent

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

4 months agoFix code for probing availability of AVX-512.
Nathan Bossart [Tue, 23 Apr 2024 15:54:04 +0000 (10:54 -0500)] 
Fix code for probing availability of AVX-512.

This commit fixes a few things:
* Instead of checking for CPU support of the "xsave" extension, we
  need to check for OS support of XGETBV instructions via the
  "osxsave" flag.
* We must check that additional XCR0 bits are set to be sure the
  ZMM registers are fully enabled.
* We should use the recommended ordering of steps.  Specifically,
  we need to check that the ZMM registers are enabled prior to
  checking for AVX-512 via CPUID.

In passing, split this code into separate functions to improve
readability.

Reported-by: Andrew Kane
Reviewed-by: Akash Shankaran, Raghuveer Devulapalli
Discussion: https://postgr.es/m/20240418024459.GA3385227%40nathanxps13

4 months agoImprove "out of range" error messages for GUCs.
Tom Lane [Tue, 23 Apr 2024 15:52:40 +0000 (11:52 -0400)] 
Improve "out of range" error messages for GUCs.

If the GUC has a unit, label the minimum and maximum values
with the unit explicitly.  Per suggestion from Jian He.

Discussion: https://postgr.es/m/CACJufxFJo6FyVg9W8yvNAxbjP+EJ9wieE9d9vw5LpPzyLnLLOQ@mail.gmail.com

4 months agoFix the handling of the failover option in subscription commands.
Amit Kapila [Tue, 23 Apr 2024 06:44:57 +0000 (12:14 +0530)] 
Fix the handling of the failover option in subscription commands.

Do not allow ALTER SUBSCRIPTION ... SET (failover = on|off) in a
transaction block as the changed failover option of the slot can't be
rolled back. For the same reason, we refrain from altering the replication
slot's failover property if the subscription is created with a valid
slot_name and create_slot=false.

Reprted-by: Kuroda Hayato
Author: Hou Zhijie
Reviewed-by: Shveta Malik, Bertrand Drouvot, Kuroda Hayato
Discussion: https://postgr.es/m/OS0PR01MB57165542B09DFA4943830BF294082@OS0PR01MB5716.jpnprd01.prod.outlook.com

5 months agoRemove unneeded nbtree array preprocessing assert.
Peter Geoghegan [Mon, 22 Apr 2024 17:58:06 +0000 (13:58 -0400)] 
Remove unneeded nbtree array preprocessing assert.

Certain cases involving the use of cursors had assertion failures within
_bt_preprocess_keys's recently added no-op return path.  The assertion
in question made the faulty assumption that a second or third call to
_bt_preprocess_keys (within the same btrescan) could only happen when
another scheduled primitive index scan was just about to begin.

It would be possible to address the problem by only allowing scans that
have array keys to take the new no-op path, forcing affected cases to
perform redundant preprocessing work.  It seems simpler to just remove
the assertion, and reframe the no-op path as a more general mechanism.
Take this simpler approach.

The important underlying principle is that we only need to perform
preprocessing once per btrescan (at most).  This is expected regardless
of whether or not the scan happens to have array keys.

Oversight in commit 1b134ca5, which enhanced nbtree ScalarArrayOp
execution.

Reported-By: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/ef0f7c8b-a6fa-362e-6fd6-054950f947ca@gmail.com

5 months agoUpdate src/common/unicode/.gitignore
Peter Eisentraut [Sun, 21 Apr 2024 16:41:57 +0000 (18:41 +0200)] 
Update src/common/unicode/.gitignore

for new downloaded files and new build results.

5 months agoUpdate Unicode data to CLDR 45
Peter Eisentraut [Sun, 21 Apr 2024 16:40:21 +0000 (18:40 +0200)] 
Update Unicode data to CLDR 45

No actual changes result.

5 months agoFix dumps of partitioned tables with table AMs
Michael Paquier [Mon, 22 Apr 2024 06:15:36 +0000 (15:15 +0900)] 
Fix dumps of partitioned tables with table AMs

pg_dump/restore failed to properly set the table access method for
partitioned tables, as it relies on SET queries that would change
default_table_access_method.  However, SET affects only tables and
materialized views, not partitioned tables which would always be
restored with their pg_class.relam set to 0, losing their table AM set
by either a CREATE TABLE .. USING or by a ALTER TABLE .. SET ACCESS
METHOD.

Appending a USING clause to the definition of CREATE TABLE is not
possible as users may specify --no-table-access-method at restore or for
a dump, meaning that the table AM portions may have to be skipped.
Rather than SET, the solution used by this commit is to generate an
extra ALTER TABLE .. SET ACCESS METHOD when restoring a partitioned
table, based on the table AM set in its TOC entry.  The choice of using
a SET query or an ALTER TABLE query for a relation requires the addition
of the relkind to the TOC entry to be able to choose between one or the
other.  Note that using ALTER TABLE SET ACCESS METHOD on a relation with
physical storage would require a full rewrite, which would be costly for
one.  This also creates problems with binary upgrades where the rewrite
would not be able to keep the OID of the relation consistent across the
upgrade.

This commit would normally require a protocol bump, but a45c78e3284b has
already done one for this release cycle.

Regression tests are adjusted with the new expected output, with some
tweaks for the table AMs of the partitions to make the output more
readable.

Issue introduced by 374c7a229042, that has added support for table AMs
in partitioned tables.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/Zh4JLSvvtQgBJZkZ@paquier.xyz

5 months agoRemove overzealous array element type assertion.
Peter Geoghegan [Mon, 22 Apr 2024 02:51:56 +0000 (22:51 -0400)] 
Remove overzealous array element type assertion.

This led to spurious assertion failures in certain scenarios involving
pseudo types.

Oversight in commit 5bf748b8, which enhanced nbtree ScalarArrayOp
execution.

Reported-By: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48f5rDOwxaT76Zd40m7n9iGZQcjEk7vG_5p3YWNh6oPfA@mail.gmail.com

5 months agocreatedb: compare strategy case-insensitive
Tomas Vondra [Sun, 21 Apr 2024 19:21:26 +0000 (21:21 +0200)] 
createdb: compare strategy case-insensitive

When specifying the createdb strategy, the documentation suggests valid
options are FILE_COPY and WAL_LOG, but the code does case-sensitive
comparison and accepts only "file_copy" and "wal_log" as valid.

Fixed by doing a case-insensitive comparison using pg_strcasecmp(), same
as for other string parameters nearby.

While at it, apply fmtId() to a nearby "locale_provider". This already
did the comparison in case-insensitive way, but the value would not be
double-quoted, confusing the parser and the error message.

Backpatch to 15, where the strategy was introduced.

Backpatch-through: 15
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/90c6913a-1dd2-42b4-8365-ce3b09c39b17@enterprisedb.com

5 months agoMake postgres_fdw request remote time zone 'GMT' not 'UTC'.
Tom Lane [Sun, 21 Apr 2024 17:46:20 +0000 (13:46 -0400)] 
Make postgres_fdw request remote time zone 'GMT' not 'UTC'.

This should have the same results for all practical purposes.
The advantage of selecting 'GMT' is that it's guaranteed to work
even when the remote system's timezone database is missing
entries, because pg_tzset() hard-wires handling of that,
at least in 9.2 and later.

(It seems like it would be a good idea to similarly hard-wire
correct handling of 'UTC', but that'll be a little more invasive
than I want to consider back-patching.  Leave that for another
day when we're not in feature freeze.)

Per trouble report from Adnan Dautovic.  Back-patch to all
supported branches.

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

5 months agocreatedb: Correct parameter name in SGML docs
Tomas Vondra [Sat, 20 Apr 2024 16:54:09 +0000 (18:54 +0200)] 
createdb: Correct parameter name in SGML docs

Commit 9c08aea6a309 introduced -S/--strategy option, but forgot to
rename the parameter when copying the -T/--template bit.

5 months agoRemove resowner_private.h
Michael Paquier [Sat, 20 Apr 2024 09:01:03 +0000 (18:01 +0900)] 
Remove resowner_private.h

This header is not used since the refactoring of resource owners done in
b8bff07daa85, and all the functions declared in it became (well, mostly)
static inline local to each resowner kind's code path.

Author: Xing Guo
Discussion: https://postgr.es/m/CACpMh+BFmtK5Z=b6PvH4HLKhUpWa_VtRTZSrB4-yK-tQejpWGw@mail.gmail.com

5 months agoDoc: document cases where queryid is stable
David Rowley [Sat, 20 Apr 2024 01:53:35 +0000 (13:53 +1200)] 
Doc: document cases where queryid is stable

The documents were clear that queryid should not be assumed to be stable
between major versions but said nothing about minor versions and left
the reader to guess if that was implied by the mention of the
instability of queryid between major versions.

Here we give minor versions an explicit mention to indicate queryid can
generally be assumed stable between minor versions.

Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAApHDvpYGE6h0cD9UO-eHySPynPj1L3J%3DHxT%2BA7Ud8_Yo6AuzA%40mail.gmail.com
Backpatch-through: 12

5 months agoRevert recent ill-advised test case changes.
Robert Haas [Fri, 19 Apr 2024 21:21:56 +0000 (17:21 -0400)] 
Revert recent ill-advised test case changes.

Commit 6bf5c42b5546984df29289918f952e6211069c54 cannot work on Windows,
because it lacks symlink support. While the bug fix in commit
cd64dc42d1e1b03e57e6ba3d316e4f9dec52a78d is correct as far as I know,
the test case changes depend on the previous commit, so this will
have to live without test coverage until we can come up with a better
solution. Commit fa7036dd6644d13233b475874a94754a5903e35a was a test
case bug fix on top of those two, to prevent failures on Linux, so that
has to come out as well.

Per the buildfarm, CI, and Thomas Munro.

5 months agoUse tempdir_short instead of tempdir.
Robert Haas [Fri, 19 Apr 2024 19:50:02 +0000 (15:50 -0400)] 
Use tempdir_short instead of tempdir.

After cd64dc42d1e1b03e57e6ba3d316e4f9dec52a78d, a significant
percentage of the buildfarm got unhappy, because pg_basebackup chokes
if it tries to create a tarfile with symlink more than 99 characters
in length. To try to fix that problem, use tempdir_short instead of
tempdir, as we do in pg_verifybackup's 003_corruption.pl.

There's a more complicated workaround for the same issue in
pg_basebackup's 010_pg_basebackup.pl, but I'm not clear whether
there's any reason to do it that way here. For now, let's try this,
to at least get the buildfarm green again.

A better long-term fix would be to figure out how to generate tar
files containing long symlinks, but that will have to wait for
another time.

5 months agopg_combinebackup: Fix incorrect tablespace handling.
Robert Haas [Fri, 19 Apr 2024 17:30:42 +0000 (13:30 -0400)] 
pg_combinebackup: Fix incorrect tablespace handling.

The previous coding mangled the pathname calculation for
incremental files located in user-defined tablespaces.

Enhance the test cases to cover such cases, as I should have
done originally. Thanks to Andres Freund for alerting me to the
lack of test coverage.

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

5 months agoMake PostgreSQL::Test::Cluster::init_from_backup handle tablespaces.
Robert Haas [Wed, 17 Apr 2024 19:56:33 +0000 (15:56 -0400)] 
Make PostgreSQL::Test::Cluster::init_from_backup handle tablespaces.

This commit doesn't use this infrastructure for anything new, although
it does adapt 010_pg_basebackup.pl to use it. However, a future commit
will use this to improve test coverage for pg_combinebackup.

Patch by me, reviewed (but not fully endorsed) by Andres Freund.

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

5 months agoAdd missing index_insert_cleanup calls
Tomas Vondra [Fri, 19 Apr 2024 13:47:48 +0000 (15:47 +0200)] 
Add missing index_insert_cleanup calls

The optimization for inserts into BRIN indexes added by c1ec02be1d79
relies on a cache that needs to be explicitly released after calling
index_insert(). The commit however failed to invoke the cleanup in
validate_index(), which calls index_insert() indirectly through
table_index_validate_scan().

After inspecting index_insert() callers, it seems unique_key_recheck()
is missing the call too.

Fixed by adding the two missing index_insert_cleanup() calls.

The commit does two additional improvements. The aminsertcleanup()
signature is modified to have the index as the first argument, to make
it more like the other AM callbacks. And the aminsertcleanup() callback
is invoked even if the ii_AmCache is NULL, so that it can decide if the
cleanup is necessary.

Author: Alvaro Herrera, Tomas Vondra
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/202401091043.e3nrqiad6gb7@alvherre.pgsql

5 months agoFix a couple typos in BRIN code
Tomas Vondra [Fri, 19 Apr 2024 13:43:14 +0000 (15:43 +0200)] 
Fix a couple typos in BRIN code

Typos introduced by commits c1ec02be1d79b43757171470 and dae761a87eda.

Author: Alvaro Herrera
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/202401091043.e3nrqiad6gb7@alvherre.pgsql

5 months agoDoc: Remove mention of @ and ~ GiST operators
Daniel Gustafsson [Fri, 19 Apr 2024 12:50:10 +0000 (14:50 +0200)] 
Doc: Remove mention of @ and ~ GiST operators

These operators were removed by 2f70fdb0644c in the v14 cycle but they were
accidentally left in the table of build-in operator classes. Backpatch down
to v14 where the operators where removed.

Author: Aleksander Alekseev <aleksander@timescale.com>
Reported-by: Colin Caine <cmcaine@gmail.com>
Discussion: https://postgr.es/m/CADwQTQbbr2UQ_fpbyc+8ay=RwEYgYk=TZxH3+RHDqAQfoG+EWA@mail.gmail.com
Backpatch-through: v14

5 months agoBetter handle indirect constraint drops
Alvaro Herrera [Fri, 19 Apr 2024 10:37:33 +0000 (12:37 +0200)] 
Better handle indirect constraint drops

It is possible for certain cases to remove not-null constraints without
maintaining the attnotnull in its correct state; for example if you drop
a column that's part of the primary key, and the other columns of the PK don't
have not-null constraints, then we should reset the attnotnull flags for
those other columns; up to this commit, we didn't.  Handle those cases
better by doing the attnotnull reset in RemoveConstraintById() instead
of in dropconstraint_internal().

However, there are some cases where we must not do so.  For example if
those other columns are in replica identity indexes or are generated
identity columns, we must keep attnotnull set, even though it results in
the catalog inconsistency that no not-null constraint supports that.

Because the attnotnull reset now happens in more places than before, for
instance when a column of the primary key changes type, we need an
additional trick to reinstate it as necessary.  Introduce a new
alter-table pass that does this, which needs simply reschedule some
AT_SetAttNotNull subcommands that were already being generated and
ignored.

Because of the exceptions in which attnotnull is not reset noted above,
we also include a pg_dump hack to include a not-null constraint when the
attnotnull flag is set even if no pg_constraint row exists.  This part
is undesirable but necessary, because failing to handle the case can
result in unrestorable dumps.

Reported-by: Tender Wang <tndrwang@gmail.com>
Co-authored-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CAHewXN=hMbNa3d43NOR=OCgdgpTt18S-1fmueCoEGesyeK4bqw@mail.gmail.com

5 months agoUse macro NUM_MERGE_MATCH_KINDS instead of '3' in MERGE code.
Dean Rasheed [Fri, 19 Apr 2024 08:40:20 +0000 (09:40 +0100)] 
Use macro NUM_MERGE_MATCH_KINDS instead of '3' in MERGE code.

Code quality improvement for 0294df2f1f84.

Aleksander Alekseev, reviewed by Richard Guo.

Discussion: https://postgr.es/m/CAJ7c6TMsiaV5urU_Pq6zJ2tXPDwk69-NKVh4AMN5XrRiM7N%2BGA%40mail.gmail.com

5 months agoRemove unused function prototype
Daniel Gustafsson [Fri, 19 Apr 2024 07:58:04 +0000 (09:58 +0200)] 
Remove unused function prototype

Commit aafc05de1bf5 removed StartSlotSyncWorker() but mistakenly left
the prototype in slotsync.h.  Fix by removing.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/3F577953-A29E-4722-98AD-2DA9EFF2CBB8@yesql.se

5 months agoFix incorrect parameter name in prototype
Daniel Gustafsson [Fri, 19 Apr 2024 07:58:00 +0000 (09:58 +0200)] 
Fix incorrect parameter name in prototype

The function declaration for select_next_encryption_method use the
variable name have_valid_connection, so fix the prototype in the
header to match that.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/3F577953-A29E-4722-98AD-2DA9EFF2CBB8@yesql.se

5 months agoDoc: Update link to the mentioned subsection
Daniel Gustafsson [Thu, 18 Apr 2024 21:02:39 +0000 (23:02 +0200)] 
Doc: Update link to the mentioned subsection

This updates the link from pg_createsubscriber to initial data sync
to actually link to the subsection in question as opposed to the
main logical replication section.

Author: Pavel Luzanov <p.luzanov@postgrespro.ru>
Discussion: https://postgr.es/m/a4af555a-ac60-4416-877d-0440d29b8763@postgrespro.ru

5 months agoFix typos and duplicate words
Daniel Gustafsson [Thu, 18 Apr 2024 19:28:07 +0000 (21:28 +0200)] 
Fix typos and duplicate words

This fixes various typos, duplicated words, and tiny bits of whitespace
mainly in code comments but also in docs.

Author: Daniel Gustafsson <daniel@yesql.se>
Author: Heikki Linnakangas <hlinnaka@iki.fi>
Author: Alexander Lakhin <exclusion@gmail.com>
Author: David Rowley <dgrowleyml@gmail.com>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/3F577953-A29E-4722-98AD-2DA9EFF2CBB8@yesql.se

5 months agoRemove spurious "the".
Robert Haas [Thu, 18 Apr 2024 17:06:27 +0000 (13:06 -0400)] 
Remove spurious "the".

Spotted by Martin Marqués.

Discussion: http://postgr.es/m/CABeG9LvQMtsKrOkhcA_mKJu1duArw4v+smeJKurYGjPVBZFecg@mail.gmail.com

5 months agoDon't try to fix eliminated nbtree array scan keys.
Peter Geoghegan [Thu, 18 Apr 2024 15:48:41 +0000 (11:48 -0400)] 
Don't try to fix eliminated nbtree array scan keys.

Preprocessing for nbtree index scans allowed array "input" scan keys
already marked eliminated during array-specific preprocessing to be
"fixed up" during preprocessing proper.  This allowed eliminated scan
keys on DESC index columns to spurious have their strategy commuted,
causing assertion failures.

To fix, teach _bt_fix_scankey_strategy to ignore these scan keys.  This
brings it in line with its only caller, _bt_preprocess_keys.

Oversight in commit 5bf748b8, which enhanced nbtree ScalarArrayOp
execution.

Reported-By: Donghang Lin <donghanglin@gmail.com>
Discussion: https://postgr.es/m/CAA=D8a2sHK6CAzZ=0CeafC-Y-MFXbYxnRSHvZTi=+JHu6kAa8Q@mail.gmail.com

5 months agoRestrict where INCREMENTAL.${NAME} files are recognized.
Robert Haas [Thu, 18 Apr 2024 15:00:38 +0000 (11:00 -0400)] 
Restrict where INCREMENTAL.${NAME} files are recognized.

Previously, they were recognized anywhere in an incremental backup
directory; now, we restrict this to places where they are expected to
appear. That means this code will need updating if we ever do
incremental backups of files in other places (e.g. SLRU files), but
it lets you create a file called INCREMENTAL.config (or something like
that) at the top level of the data directory and still have things
work.

Patch by me, per request from David Steele, who also reviewed.

Discussion: http://postgr.es/m/5a7817da-6349-4653-8056-470300b6e512@pgmasters.net

5 months agoDon't try to assign smart names to constraints
Alvaro Herrera [Thu, 18 Apr 2024 14:10:53 +0000 (16:10 +0200)] 
Don't try to assign smart names to constraints

This part of my previous commit seems to have broken pg_upgrade on
crake, at least from 9.2.  I'll see if there's a better fix, but in the
meantime this should suffice to keep the buildfarm green.

5 months agodocs: Mention that pg_combinebackup does not verify backups.
Robert Haas [Thu, 18 Apr 2024 13:52:19 +0000 (09:52 -0400)] 
docs: Mention that pg_combinebackup does not verify backups.

We don't want users to think that pg_combinebackup is trying to check
the validity of individual backups, because it isn't. Adjust the wording
about sanity checks to make it clear that verification of individual
backups is the job of pg_verifybackup, and that the checks performed
by pg_combinebackup are around the relationships between the backups.

Per discussion with David Steele.

Discussion: http://postgr.es/m/e6f930c3-590c-47b9-b094-217bb2a3e22e@pgmasters.net

5 months agoFix restore of not-null constraints with inheritance
Alvaro Herrera [Thu, 18 Apr 2024 13:35:15 +0000 (15:35 +0200)] 
Fix restore of not-null constraints with inheritance

In tables with primary keys, pg_dump creates tables with primary keys by
initially dumping them with throw-away not-null constraints (marked "no
inherit" so that they don't create problems elsewhere), to later drop
them once the primary key is restored.  Because of a unrelated
consideration, on tables with children we add not-null constraints to
all columns of the primary key when it is created.

If both a table and its child have primary keys, and pg_dump happens to
emit the child table first (and its throw-away not-null) and later its
parent table, the creation of the parent's PK will fail because the
throw-away not-null constraint collides with the permanent not-null
constraint that the PK wants to add, so the dump fails to restore.

We can work around this problem by letting the primary key "take over"
the child's not-null.  This requires no changes to pg_dump, just two
changes to ALTER TABLE: first, the ability to convert a no-inherit
not-null constraint into a regular inheritable one (including recursing
down to children, if there are any); second, the ability to "drop" a
constraint that is defined both directly in the table and inherited from
a parent (which simply means to mark it as no longer having a local
definition).

Secondarily, change ATPrepAddPrimaryKey() to acquire locks all the way
down the inheritance hierarchy, in case we need to recurse when
propagating constraints.

These two changes allow pg_dump to reproduce more cases involving
inheritance from versions 16 and older.

Lastly, make two changes to pg_dump: 1) do not try to drop a not-null
constraint that's marked as inherited; this allows a dump to restore
with no errors if a table with a PK inherits from another which also has
a PK; 2) avoid giving inherited constraints throwaway names, for the
rare cases where such a constraint survives after the restore.

Reported-by: Andrew Bille <andrewbille@gmail.com>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CAJnzarwkfRu76_yi3dqVF_WL-MpvT54zMwAxFwJceXdHB76bOA@mail.gmail.com
Discussion: https://postgr.es/m/Zh0aAH7tbZb-9HbC@pryzbyj2023

5 months agoUpdate src/tools/pginclude/README to match recent changes to cpluspluscheck
Peter Eisentraut [Thu, 18 Apr 2024 09:32:22 +0000 (11:32 +0200)] 
Update src/tools/pginclude/README to match recent changes to cpluspluscheck

Commit 7b8e2ae2f has turned cpluspluscheck from separate script into a
--cplusplus option for headerscheck.  Update README correspondingly.

Author: Anton Voloshin <a.voloshin@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/02e69fa9-885d-4f41-9057-15a1d212eaf8@postgrespro.ru

5 months agoFix object name clash in recently introduced test
Amit Langote [Thu, 18 Apr 2024 08:16:26 +0000 (17:16 +0900)] 
Fix object name clash in recently introduced test

c0fc0751862 wasn't careful about naming the DOMAIN used in some new
tests in sqljson_queryfunc.sql so as not to clash with the name of a
DOMAIN used in the nearby sqljson_jsontable.sql.  Fix by using a
different name for the newly added DOMAIN in sqljson_queryfuncs.sql.

Per buildfarm members canebrake and urutu.

Discussion: https://postgr.es/m/CA+HiwqEjkbDxqqD3VJamc6R9+B102H7=SFYYOM7gKrxzJO35TQ@mail.gmail.com

5 months agoSQL/JSON: Miscellaneous fixes and improvements
Amit Langote [Thu, 18 Apr 2024 05:38:12 +0000 (14:38 +0900)] 
SQL/JSON: Miscellaneous fixes and improvements

This addresses some post-commit review comments for commits 6185c973,
de3600452, and 9425c596a0, with the following changes:

* Fix JSON_TABLE() syntax documentation to use the term
  "path_expression" for JSON path expressions instead of
  "json_path_specification" to be consistent with the other SQL/JSON
  functions.

* Fix a typo in the example code in JSON_TABLE() documentation.

* Rewrite some newly added comments in jsonpath.h.

* In JsonPathQuery(), add missing cast to int before printing an enum
  value.

Reported-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com

5 months agoSQL/JSON: Fix issues with DEFAULT .. ON ERROR / EMPTY
Amit Langote [Thu, 18 Apr 2024 05:46:35 +0000 (14:46 +0900)] 
SQL/JSON: Fix issues with DEFAULT .. ON ERROR / EMPTY

SQL/JSON query functions allow specifying an expression to return
when either of ON ERROR or ON EMPTY condition occurs when evaluating
the JSON path expression.  The parser (transformJsonBehavior()) checks
that the specified expression is one of the supported expressions, but
there are two issues with how the check is done that are fixed in this
commit:

* No check for some expressions related to coercion, such as
  CoerceViaIO, that may appear in the transformed user-specified
  expressions that include cast(s)

* An unsupported expression may be masked by a coercion-related
  expression, which must be flagged by checking the latter's
  argument expression recursively

Author: Jian He <jian.universality@gmail.com>
Author: Amit Langote <amitlangote09@gmail.com>
Reported-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxEqhqsfrg_p7EMyo5zak3d767iFDL8vz_4%3DZBHpOtrghw@mail.gmail.com
Discussion: https://postgr.es/m/CACJufxGOerH1QJknm1noh-Kz5FqU4p7QfeZSeVT2tN_4SLXYNg@mail.gmail.com

5 months agoSQL/JSON: Improve some error messages
Amit Langote [Thu, 18 Apr 2024 05:33:47 +0000 (14:33 +0900)] 
SQL/JSON: Improve some error messages

This improves some error messages emitted by SQL/JSON query functions
by mentioning column name when available, such as when they are
invoked as part of evaluating JSON_TABLE() columns.  To do so, a new
field column_name is added to both JsonFuncExpr and JsonExpr that is
only populated when creating those nodes for transformed JSON_TABLE()
columns.

While at it, relevant error messages are reworded for clarity.

Reported-by: Jian He <jian.universality@gmail.com>
Suggested-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com

5 months agoRefactoring for CommitTransactionCommand()/AbortCurrentTransaction()
Alexander Korotkov [Wed, 17 Apr 2024 21:29:41 +0000 (00:29 +0300)] 
Refactoring for CommitTransactionCommand()/AbortCurrentTransaction()

fefd9a3fed turned tail recursion of CommitTransactionCommand() and
AbortCurrentTransaction() into iteration.  However, it splits the handling of
cases between different functions.

This commit puts the handling of all the cases into
AbortCurrentTransactionInternal() and CommitTransactionCommandInternal().
Now CommitTransactionCommand() and AbortCurrentTransaction() are just doing
the repeated calls of internal functions.

Reported-by: Andres Freund
Discussion: https://postgr.es/m/20240415224834.w6piwtefskoh32mv%40awork3.anarazel.de
Author: Andres Freund

5 months agoRemove GlobalVisTestNonRemovable[Full]Horizon, not used anymore
Andres Freund [Wed, 17 Apr 2024 18:21:17 +0000 (11:21 -0700)] 
Remove GlobalVisTestNonRemovable[Full]Horizon, not used anymore

GlobalVisTestNonRemovableHorizon() was only used for the implementation of
snapshot_too_old, which was removed in f691f5b80a8. As using
GlobalVisTestNonRemovableHorizon() is not particularly efficient, no new uses
for it should be added. Therefore remove.

Discussion: https://postgr.es/m/20240415185720.q4dg4dlcyvvrabz4@awork3.anarazel.de

5 months agoCleanup parallel BRIN index build code
Tomas Vondra [Wed, 17 Apr 2024 16:31:43 +0000 (18:31 +0200)] 
Cleanup parallel BRIN index build code

Commit b43757171470 added support for parallel builds of BRIN indexes,
using code similar to BTREE. But there were to be a couple unnecessary
differences, particularly in how the leader waits for the workers, and
merges the results. So remove these, to make the code more similar.

The leader never waited on the workersdonecv condition variable, but
simply called WaitForParallelWorkersToFinish() in _brin_end_parallel()
and then merged the per-worker results. This worked correctly, but it
seems better to do the wait and merge before _brin_end_parallel().

This commit moves the relevant code to _brin_parallel_heapscan/merge(),
which means  _brin_end_parallel() remains responsible only for exiting
the parallel mode and accumulating WAL usage data.

Discussion: https://postgr.es/m/3733d042-71e1-6ae6-5fac-00c12db62db6@enterprisedb.com

5 months agoStabilize test of BRIN parallel create
Tomas Vondra [Wed, 17 Apr 2024 14:14:44 +0000 (16:14 +0200)] 
Stabilize test of BRIN parallel create

As explained in 4d916dd876, the test instability is caused by delayed
cleanup of deleted rows. This commit removes the DELETE, stabilizing the
test without accidentally disabling parallel builds.

The intent of the delete however was to produce empty ranges, and test
that the parallel index build populates those correctly. But there's
another way to create empty ranges - partial indexes, which does not
rely on cleanup of deleted rows.

Idea to use partial indexes by Matthias van de Meent, patch by me.

Discussion: https://postgr.es/m/95d9cd43-5a92-407c-b7e4-54cd303630fe%40enterprisedb.com

5 months agoRevert "Stabilize test of BRIN parallel create"
Tomas Vondra [Wed, 17 Apr 2024 14:12:03 +0000 (16:12 +0200)] 
Revert "Stabilize test of BRIN parallel create"

This reverts commit 4d916dd876c3. The goal of that commit was to
stabilize a test of parallel BRIN build, but using a TEMPORARY table
disables parallel index builds on that table, making the test useless.

Discussion: https://postgr.es/m/95d9cd43-5a92-407c-b7e4-54cd303630fe%40enterprisedb.com

5 months agomeson: Add some missing LLVM function checks
Peter Eisentraut [Wed, 17 Apr 2024 13:16:39 +0000 (15:16 +0200)] 
meson: Add some missing LLVM function checks

The checks for

HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER and
HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER

are in configure but are missing on the meson side.  This adds those.

Reported-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/5539b16c-cff7-46d5-9621-c3fb6b549e9e@iki.fi

5 months agoRemove dead code
Peter Eisentraut [Wed, 17 Apr 2024 08:46:43 +0000 (10:46 +0200)] 
Remove dead code

The configure check for HAVE_DECL_LLVMORCREGISTERPERF was removed by
e9a9843e138, but some code guarded by it was left.  (That commit
removed the "register" calls but left the "unregister" calls.)  That
code cannot be reached anymore, so remove it.

Reported-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/5539b16c-cff7-46d5-9621-c3fb6b549e9e@iki.fi

5 months agoAdd missing source file to libpq/nls.mk
Peter Eisentraut [Wed, 17 Apr 2024 07:09:53 +0000 (09:09 +0200)] 
Add missing source file to libpq/nls.mk

5 months agodoc: Fix COPY ON_ERROR option syntax synopsis.
Masahiko Sawada [Wed, 17 Apr 2024 07:10:18 +0000 (16:10 +0900)] 
doc: Fix COPY ON_ERROR option syntax synopsis.

ON_ERROR option values don't require quotations, which was
inconsistent with the syntax synopsis in the documentation.

Oversight in b725b7eec43.

Author: Atsushi Torikoshi
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoC%3Dn4xR3%2BKQiqodnfT9chSB62XwZqmMff39H%3Dx9DS4scQ%40mail.gmail.com

5 months agoFix typos with function name in event_trigger.c
Michael Paquier [Wed, 17 Apr 2024 05:56:31 +0000 (14:56 +0900)] 
Fix typos with function name in event_trigger.c

Databases exist, contrary to datatabases.

Oversight in e83d1b0c40cc.

Author: Japin Li
Discussion: https://postgr.es/m/ME3P282MB316611A2F7BF43919F695228B6082@ME3P282MB3166.AUSP282.PROD.OUTLOOK.COM

5 months agoDisallow specifying ON_ERROR option without value.
Masahiko Sawada [Wed, 17 Apr 2024 02:31:27 +0000 (11:31 +0900)] 
Disallow specifying ON_ERROR option without value.

The ON_ERROR option of the COPY command previously allowed omitting
its value, which was inconsistent with the syntax synopsis in the
documentation and the behavior of other non-boolean COPY options.

This change enforces providing a value for the ON_ERROR option,
ensuring consistency across other non-boolean options and aligning
with the documented syntax.

Author: Atsushi Torikoshi
Reviewed-by: Masahiko Sawada
Discussion: https://postgr.es/m/a9770bf57646d90dedc3d54cf32634b2%40oss.nttdata.com

5 months agoUpdate mmgr's README to mention BumpContext
David Rowley [Tue, 16 Apr 2024 22:49:09 +0000 (10:49 +1200)] 
Update mmgr's README to mention BumpContext

Oversight in 29f6a959c.

In passing, since we now have 4 memory context types to choose from,
provide a brief overview of the specialities of each memory context
type.

Reported-by: Amul Sul
Author: Amul Sul, David Rowley
Discussion: https://postgr.es/m/CAAJ_b94U2s9nHh--DEK=sPEZUQ+x7vQJ7529fF8UAH97QJ9NXg@mail.gmail.com

5 months agoPush dedicated BumpBlocks to the tail of the blocks list
David Rowley [Tue, 16 Apr 2024 22:40:31 +0000 (10:40 +1200)] 
Push dedicated BumpBlocks to the tail of the blocks list

BumpContext relies on using the head block from its 'blocks' field to
use as the current block to allocate new chunks to.  When we receive an
allocation request larger than allocChunkLimit, we place these chunks on
a new dedicated block and, until now, we pushed the block onto the
*head* of the 'blocks' list.

This behavior caused the previous bump block to no longer be available
for new normal-sized (non-large) allocations and would result in blocks
only being partially filled if a large allocation request arrived before
the block became full.

Here adjust the code to push these dedicated blocks onto the *tail* of
the blocks list so that the head block remains intact and available to
be used by normal allocation request sizes until it becomes full.

In passing, make the elog(ERROR) calls for the unsupported callbacks
consistent.  Likewise for the header comments for those functions.

Discussion: https://postgr.es/m/CAApHDvp9___r-ayJj0nZ6GD3MeCGwGZ0_6ZptWpwj+zqHtmwCw@mail.gmail.com
Discussion: https://postgr.es/m/CAApHDvqerXpzUnuDQfUEi3DZA+9=Ud9WSt3ruxN5b6PcOosx2g@mail.gmail.com

5 months agoMark some new location fields as ParseLoc
Peter Eisentraut [Tue, 16 Apr 2024 18:22:41 +0000 (20:22 +0200)] 
Mark some new location fields as ParseLoc

Some new code probably didn't see 605721f819f and continued to use
type int for parse location fields.  Fix those.

5 months agoClean up more indent breakage from 6377e12a5.
Tom Lane [Tue, 16 Apr 2024 17:00:40 +0000 (13:00 -0400)] 
Clean up more indent breakage from 6377e12a5.

Per buildfarm member koel.

5 months agoFix assorted bugs in ecpg's macro mechanism.
Tom Lane [Tue, 16 Apr 2024 16:31:32 +0000 (12:31 -0400)] 
Fix assorted bugs in ecpg's macro mechanism.

The code associated with EXEC SQL DEFINE was unreadable and full of
bugs, notably:

* It'd attempt to free a non-malloced string if the ecpg program
tries to redefine a macro that was defined on the command line.

* Possible memory stomp if user writes "-D=foo".

* Undef'ing or redefining a macro defined on the command line would
change the state visible to the next file, when multiple files are
specified on the command line.  (While possibly that could have been
an intentional choice, the code clearly intends to revert to the
original macro state; it's just failing to consider this interaction.)

* Missing "break" in defining a new macro meant that redefinition
of an existing name would cause an extra entry to be added to the
definition list.  While not immediately harmful, a subsequent undef
would result in the prior entry becoming visible again.

* The interactions with input buffering are subtle and were entirely
undocumented.

It's not that surprising that we hadn't noticed these bugs,
because there was no test coverage at all of either the -D
command line switch or multiple input files.  This patch adds
such coverage (in a rather hacky way I guess).

In addition to the code bugs, the user documentation was confused
about whether the -D switch defines a C macro or an ecpg one, and
it failed to mention that you can write "-Dsymbol=value".

These problems are old, so back-patch to all supported branches.

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

5 months agoFix nbtree "deduce NOT NULL" scan key comment.
Peter Geoghegan [Tue, 16 Apr 2024 16:04:20 +0000 (12:04 -0400)] 
Fix nbtree "deduce NOT NULL" scan key comment.

Oversight in commit c9c0589fda.

5 months agoUndo incorrect typedefs.list change.
Tom Lane [Tue, 16 Apr 2024 15:37:51 +0000 (11:37 -0400)] 
Undo incorrect typedefs.list change.

6377e12a5 should not have removed AcquireSampleRowsFunc,
as that's still in use.  Per buildfarm member koel.

5 months agoStabilize test of BRIN parallel create
Tomas Vondra [Tue, 16 Apr 2024 15:31:03 +0000 (17:31 +0200)] 
Stabilize test of BRIN parallel create

The test for parallel create of BRIN indexes added by commit 8225c2fd40
happens to be unstable - a background transaction (e.g. auto-analyze)
may hold back global xmin for the initial VACUUM / CREATE INDEX. If the
cleanup happens before the next CREATE INDEX, the indexes will not be
exactly the same.

This is the same issue as e2933a6e11, so fix it the same way by making
the table TEMPORARY, which uses an up-to-date cutoff xmin that is not
held back by other processes.

Reported by Alexander Lakhin, who also suggested the fix.

Author: Alexander Lakhin
Discussion: https://postgr.es/m/b58901cd-a7cc-29c6-e2b1-e3d7317c3c69@gmail.com
Discussion: https://postgr.es/m/2892135.1668976646@sss.pgh.pa.us

5 months agoEnsure generated join clauses for child rels have correct relids.
Tom Lane [Tue, 16 Apr 2024 15:03:43 +0000 (11:03 -0400)] 
Ensure generated join clauses for child rels have correct relids.

When building a join clause derived from an EquivalenceClass, if the
clause is to be used with an appendrel child relation then make sure
its clause_relids include the relids of that child relation.
Normally this would be true already because the EquivalenceMember
would be a Var of that relation.  However, if the appendrel represents
a flattened UNION ALL construct then some child EquivalenceMembers
could be constants with no relids.  The resulting under-marked clause
is problematic because it could mislead join_clause_is_movable_into
about where the clause should be evaluated.  We do not have an example
showing incorrect plan generation, but there are existing cases in
the regression tests that will fail the Asserts this patch adds to
get_baserel_parampathinfo.  A similarly wrong conclusion about a
clause being considered by get_joinrel_parampathinfo would lead to
wrong placement of the clause.  (This also squares with the way
that clause_relids is calculated for non-equijoin clauses in
adjust_appendrel_attrs.)

The other reason for wanting these new Asserts is that the previous
blithe assumption that the results of generate_join_implied_equalities
"necessarily satisfy join_clause_is_movable_into" turns out to be
wrong pre-v16.  If it's still wrong it'd be good to find out.

Per bug #18429 from Benoît Ryder.  The bug as filed was fixed by
commit 2489d76c4, but these changes correlate with the fix we
will need to apply in pre-v16 branches.

Discussion: https://postgr.es/m/18429-8982d4a348cc86c6@postgresql.org

5 months agoFix nbtree posting list comment.
Peter Geoghegan [Tue, 16 Apr 2024 15:20:41 +0000 (11:20 -0400)] 
Fix nbtree posting list comment.

Oversight in commit 0d861bbb70.

5 months agoFix nbtree page recycling comment.
Peter Geoghegan [Tue, 16 Apr 2024 15:14:36 +0000 (11:14 -0400)] 
Fix nbtree page recycling comment.

Oversight in commit e5d8a99903.

5 months agorevert: Generalize relation analyze in table AM interface
Alexander Korotkov [Tue, 16 Apr 2024 10:14:20 +0000 (13:14 +0300)] 
revert: Generalize relation analyze in table AM interface

This commit reverts 27bc1772fc and dd1f6b0c17.  Per review by Andres Freund.

Discussion: https://postgr.es/m/20240415201057.khoyxbwwxfgzomeo%40awork3.anarazel.de

5 months agoImprove test coverage in bump.c
David Rowley [Tue, 16 Apr 2024 04:21:31 +0000 (16:21 +1200)] 
Improve test coverage in bump.c

There were no callers of BumpAllocLarge() in the regression tests, so
here we add a sort with a tuple large enough to use that path in bump.c.

Also, BumpStats() wasn't being called, so add a test to sysviews.sql to
call pg_backend_memory_contexts() while a bump context exists in the
backend.

Reported-by: Andres Freund
Discussion: https://postgr.es/m/20240414223305.m3i5eju6zylabvln@awork3.anarazel.de

5 months agoAdd missing PGDLLIMPORT markings
Michael Paquier [Tue, 16 Apr 2024 00:38:46 +0000 (09:38 +0900)] 
Add missing PGDLLIMPORT markings

All backend-side variables should be marked with PGDLLIMPORT, as per
policy introduced in 8ec569479f.  aafc05de1bf5 has forgotten
MyClientSocket, and 05c3980e7f47 LoadedSSL.

These can be spotted with a command like this one (be careful of not
switching __pg_log_level):
src/tools/mark_pgdllimport.pl $(git ls-files src/include/)

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/ZhzkRzrkKhbeQMRm@paquier.xyz

5 months agodocs: Consolidate into new "WAL for Extensions" chapter.
Robert Haas [Mon, 15 Apr 2024 19:46:19 +0000 (15:46 -0400)] 
docs: Consolidate into new "WAL for Extensions" chapter.

Previously, we had consecutive, very short chapters called "Generic
WAL" and "Custom WAL Resource Managers," explaining different approaches
to the same problem. Merge them into a single chapter. Explain most
of the differences between the approaches in the chapter's
introductory text, rather than in the individual sections.

Discussion: http://postgr.es/m/46ac50c1-6b2a-404f-a683-b67af6ab56e9@eisentraut.org

5 months agodoc: Note exceptions for SET ROLE's effect on privilege checks.
Nathan Bossart [Mon, 15 Apr 2024 19:03:24 +0000 (14:03 -0500)] 
doc: Note exceptions for SET ROLE's effect on privilege checks.

The documentation for SET ROLE states that superusers who switch to
a non-superuser role lose their superuser privileges.  While this
is true for most commands, there are exceptions such as SET ROLE
and SET SESSION AUTHORIZATION, which continue to use the current
session user and the authenticated user, respectively.
Furthermore, the description of this command already describes its
effect, so it is arguably unnecessary to include this special case.
This commit removes the note about the superuser case and adds a
sentence about the aforementioned exceptions to the description.

Co-authored-by: Yurii Rashkovskii
Reviewed-by: Shubham Khanna, Robert Haas, Michael Paquier
Discussion: https://postgr.es/m/CA%2BRLCQysHtME0znk2KUMJN343ksboSRQSU-hCnOjesX6VK300Q%40mail.gmail.com

5 months agoFix type-checking of RECORD-returning functions in FROM, redux.
Tom Lane [Mon, 15 Apr 2024 16:56:56 +0000 (12:56 -0400)] 
Fix type-checking of RECORD-returning functions in FROM, redux.

Commit 2ed8f9a01 intended to institute a policy that if a
RangeTblFunction has a coldeflist, then the function return type is
certainly RECORD, and we should use the coldeflist as the source of
truth about what the columns of the record type are.  When the
original function has been folded to a constant, inspection of the
constant might give a different answer.  This situation will lead to
a tuple-type-mismatch error at execution, but up until that point we
need to consistently believe the coldeflist, or we'll have problems
from different bits of code reaching different conclusions.

expandRTE didn't get that memo though, and would try to produce a
tupdesc based on the constant in this situation, leading to an
assertion failure.  (Desultory testing suggests that non-assert
builds often manage to give the expected error, although I also
saw a "cache lookup failed for type 0" error, and it seems at
least possible that a crash could happen.)

Some other callers of get_expr_result_type and get_expr_result_tupdesc
were also being incautious about this.  While none of them seem to
have actual bugs, they're working harder than necessary in this case,
besides which it seems safest to have an explicit policy of not using
those functions on an RTE with a coldeflist.  Adjust the code
accordingly, and add commentary to funcapi.c about this policy.

Also fix an obsolete comment that claimed "get_expr_result_type()
doesn't know how to extract type info from a RECORD constant".
That hasn't been true since commit d57534740.

Per bug #18422 from Alexander Lakhin.
As with the previous commit, back-patch to all supported branches.

Discussion: https://postgr.es/m/18422-89ca86c8eac5246d@postgresql.org

5 months agoATTACH PARTITION: Don't match a PK with a UNIQUE constraint
Alvaro Herrera [Mon, 15 Apr 2024 13:07:47 +0000 (15:07 +0200)] 
ATTACH PARTITION: Don't match a PK with a UNIQUE constraint

When matching constraints in AttachPartitionEnsureIndexes() we weren't
testing the constraint type, which could make a UNIQUE key lacking a
not-null constraint incorrectly satisfy a primary key requirement.  Fix
this by testing that the constraint types match.  (Other possible
mismatches are verified by comparing index properties.)

Discussion: https://postgr.es/m/202402051447.wimb4xmtiiyb@alvherre.pgsql

5 months agoGrammar fixes for split/merge partitions code
Alexander Korotkov [Mon, 15 Apr 2024 12:41:37 +0000 (15:41 +0300)] 
Grammar fixes for split/merge partitions code

The fixes relate to comments, error messages, and corresponding expected output
of regression tests.

Discussion: https://postgr.es/m/CAMbWs49DDsknxyoycBqiE72VxzL_sYHF6zqL8dSeNehKPJhkKg%40mail.gmail.com
Discussion: https://postgr.es/m/86bfd241-a58c-479a-9a72-2c67a02becf8%40postgrespro.ru
Discussion: https://postgr.es/m/CAHewXNkGMPU50QG7V6Q60JGFORfo8LfYO1_GCkCa0VWbmB-fEw%40mail.gmail.com
Author: Richard Guo, Dmitry Koval, Tender Wang

5 months agoFix propagating attnotnull in multiple inheritance
Alvaro Herrera [Mon, 15 Apr 2024 10:20:56 +0000 (12:20 +0200)] 
Fix propagating attnotnull in multiple inheritance

In one of the many strange corner cases of multiple inheritance being
used, commit b0e96f311985 missed a CommandCounterIncrement() call after
updating the attnotnull flag during ALTER TABLE ADD COLUMN, which caused
a catalog tuple to be update attempted twice in the same command, giving
rise to a "tuple already updated by self" error.  Add the missing call
to solve that, and a test case that reproduces the scenario.

As a (perhaps surprising) secondary effect, this CCI addition triggers
another behavior change: when a primary key is added to a parent
partitioned table and the column in an existing partition does not have
a not-null constraint, we no longer error out.  This will probably be a
welcome change by some users, and I think it's unlikely that anybody
will miss the old behavior.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: http://postgr.es/m/045dec3f-9b3d-aa44-0c99-85f6992306c7@gmail.com

5 months agopsql: Make output of \dD more stable
Peter Eisentraut [Mon, 15 Apr 2024 07:28:48 +0000 (09:28 +0200)] 
psql: Make output of \dD more stable

\dD showed domain check constraints in arbitrary order, which can
cause regression test failures, which was exposed by commit
9895b35cb8.  To fix, order the constraints by conname, which matches
what psql does in other queries listing constraints.

5 months agoFix ALTER DOMAIN NOT NULL syntax
Peter Eisentraut [Mon, 15 Apr 2024 06:20:34 +0000 (08:20 +0200)] 
Fix ALTER DOMAIN NOT NULL syntax

This addresses a few problems with commit e5da0fe3c22 ("Catalog domain
not-null constraints").

In CREATE DOMAIN, a NOT NULL constraint looks like

    CREATE DOMAIN d1 AS int [ CONSTRAINT conname ] NOT NULL

(Before e5da0fe3c22, the constraint name was accepted but ignored.)

But in ALTER DOMAIN, a NOT NULL constraint looks like

    ALTER DOMAIN d1 ADD [ CONSTRAINT conname ] NOT NULL VALUE

where VALUE is where for a table constraint the column name would be.
(This works as of e5da0fe3c22.  Before e5da0fe3c22, this syntax
resulted in an internal error.)

But for domains, this latter syntax is confusing and needlessly
inconsistent between CREATE and ALTER.  So this changes it to just

    ALTER DOMAIN d1 ADD [ CONSTRAINT conname ] NOT NULL

(None of these syntaxes are per SQL standard; we are just living with
the bits of inconsistency that have built up over time.)

In passing, this also changes the psql \dD output to not show not-null
constraints in the column "Check", since it's already shown in the
column "Nullable".  This has also been off since e5da0fe3c22.

Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/9ec24d7b-633d-463a-84c6-7acff769c9e8%40eisentraut.org

5 months agoPut back initialization of 'sslmode', to silence Coverity
Heikki Linnakangas [Sun, 14 Apr 2024 20:02:43 +0000 (23:02 +0300)] 
Put back initialization of 'sslmode', to silence Coverity

Coverity pointed out that the function checks for conn->sslmode !=
NULL, which implies that it might be NULL, but later we access it
without a NULL-check anyway. It doesn't know that it is in fact always
initialized earlier, in conninfo_add_defaults(), and hence the
NULL-check is not necessary. However, there is a lot of distance
between conninfo_add_defaults() and pqConnectOptions2(), so it's not
surprising that it doesn't see that. Put back the initialization code,
as it existed before commit 05fd30c0e7, to silence the warning.

In the long run, I'd like to refactor the libpq options handling and
initalization code. It seems silly to strdup() and copy strings, for
things like sslmode that have a limited set of possible values; it
should be an enum. But that's for another day.

5 months agoFix unnecessary padding in incremental backups
Tomas Vondra [Sun, 14 Apr 2024 18:34:29 +0000 (20:34 +0200)] 
Fix unnecessary padding in incremental backups

Commit 10e3226ba13d added padding to incremental backups to ensure the
block data is properly aligned. The code in sendFile() however failed to
consider that the header may be a multiple of BLCKSZ and thus already
aligned, adding a full BLCKSZ of unnecessary padding.

Not only does this make the incremental file a bit larger, but the other
places calculating the amount of padding did realize it's not needed and
did not include it in the formula. This resulted in pg_basebackup
getting confused while parsing the data stream, trying to access files
with invalid filenames (e.g. with binary data etc.) and failing.

5 months agoAdd regression test for BRIN parallel builds
Tomas Vondra [Sun, 14 Apr 2024 16:58:30 +0000 (18:58 +0200)] 
Add regression test for BRIN parallel builds

Adds a regression test for parallel CREATE INDEX for BRIN indexes, to
improve coverage for BRIN code, particularly code to allow parallel
index builds introduced by b43757171470.

The test is added to pageinspect, as that allows comparing the index to
one built without parallelism. Another option would be to just build the
index with parallelism and then check it produces correct results. But
checking the index is exactly as if built without parallelism makes
these query checks unnecessary.

Discussion: https://postgr.es/m/1df00a66-db5a-4e66-809a-99b386a06d86%40enterprisedb.com

5 months agoUse the correct PG_DETOAST_DATUM macro in BRIN
Tomas Vondra [Sun, 14 Apr 2024 16:19:52 +0000 (18:19 +0200)] 
Use the correct PG_DETOAST_DATUM macro in BRIN

Commit 6bcda4a721 replaced PG_DETOAST_DATUM with PG_DETOAST_DATUM_PACKED
in two BRIN output functions, for minmax-multi and bloom opclasses. But
this is incorrect - the code is accessing the data through structs that
already include a 4B header, so the detoast needs to match that. But the
PACKED macro may keep the 1B header, which means the struct fields will
point to incorrect data.

Backpatch-through: 16
Discussion: https://postgr.es/m/1df00a66-db5a-4e66-809a-99b386a06d86%40enterprisedb.com

5 months agoUpdate nbits_set in brin_bloom_union
Tomas Vondra [Sun, 14 Apr 2024 15:58:59 +0000 (17:58 +0200)] 
Update nbits_set in brin_bloom_union

Properly update the number of bits set in the bitmap after merging the
filters in brin_bloom_union.

This is mostly harmless, as the counter is used only in the output
function, which means pageinspect may show incorrect information about
the BRIN summary. The counter does not affect correctness.

Discovered while adding a regression test comparing indexes built with
and without parallelism. The parallel index builds exercise the union
procedure when merging results from workers, which is otherwise very
hard to do in a test. Which is why this went unnoticed until now.

Backpatch through 14, where the BRIN bloom opclasses were introduced.

Backpatch-through: 14
Discussion: https://postgr.es/m/1df00a66-db5a-4e66-809a-99b386a06d86%40enterprisedb.com

5 months agofreespace: Don't return blocks past the end of the main fork.
Noah Misch [Sat, 13 Apr 2024 15:34:20 +0000 (08:34 -0700)] 
freespace: Don't return blocks past the end of the main fork.

GetPageWithFreeSpace() callers assume the returned block exists in the
main fork, failing with "could not read block" errors if that doesn't
hold.  Make that assumption reliable now.  It hadn't been guaranteed,
due to the weak WAL and data ordering of participating components.  Most
operations on the fsm fork are not WAL-logged.  Relation extension is
not WAL-logged.  Hence, an fsm-fork block on disk can reference a
main-fork block that no WAL record has initialized.  That could happen
after an OS crash, a replica promote, or a PITR restore.  wal_log_hints
makes the trouble easier to hit; a replica promote or PITR ending just
after a relevant fsm-fork FPI_FOR_HINT may yield this broken state.  The
v16 RelationAddBlocks() mechanism also makes the trouble easier to hit,
since it bulk-extends even without extension lock waiters.  Commit
917dc7d2393ce680dea7a59418be9ff341df3c14 stopped trouble around
truncation, but vectors involving PageIsNew() pages remained.

This implementation adds a RelationGetNumberOfBlocks() call when the
cached relation size doesn't confirm a block exists.  We've been unable
to identify a benchmark that slows materially, but this may show up as
additional time in lseek().  An alternative without that overhead would
be a new ReadBufferMode such that ReadBufferExtended() returns NULL
after a 0-byte read, with all other errors handled normally.  However,
each GetFreeIndexPage() caller would then need code for the return-NULL
case.  Back-patch to v14, due to earlier versions not caching relation
size and the absence of a pre-v16 problem report.

Ronan Dunklau.  Reported by Ronan Dunklau.

Discussion: https://postgr.es/m/1878547.tdWV9SEqCh%40aivenlaptop

5 months agoCorrect "improve role option documentation".
Noah Misch [Sat, 13 Apr 2024 14:56:14 +0000 (07:56 -0700)] 
Correct "improve role option documentation".

This corrects doc commit 21912e3c0262e2cfe64856e028799d6927862563.
Back-patch to v16, like that one.

Reviewed by David G. Johnston.

Discussion: https://postgr.es/m/20240331061642.07@rfd.leadboat.com

5 months agoDocument PG_TEST_EXTRA=libpq_encryption and also check 'kerberos'
Heikki Linnakangas [Fri, 12 Apr 2024 16:52:39 +0000 (19:52 +0300)] 
Document PG_TEST_EXTRA=libpq_encryption and also check 'kerberos'

In the libpq encryption negotiation tests, don't run the GSSAPI tests
unless PG_TEST_EXTRA='kerberos' is also set. That makes it possible to
still run most of the tests when GSSAPI support is compiled in, but
there's no MIT Kerberos installation.

5 months agoMove libpq encryption negotiation tests
Heikki Linnakangas [Fri, 12 Apr 2024 16:52:37 +0000 (19:52 +0300)] 
Move libpq encryption negotiation tests

The test targets libpq's options, so 'src/test/interfaces/libpq/t' is
a more natural place for it.

While doing this, I noticed that I had missed adding the
libpq_encryption subdir to the Makefile. That's why this commit only
needs to remove it from the meson.build file.

Per Peter Eisentraut's suggestion.

Discussion: https://www.postgresql.org/message-id/09d4bf5d-d0fa-4c66-a1d7-5ec757609646@eisentraut.org

5 months agoFix compilation with --with-gssapi --without-openssl
Heikki Linnakangas [Fri, 12 Apr 2024 16:52:34 +0000 (19:52 +0300)] 
Fix compilation with --with-gssapi --without-openssl

The #define is spelled ENABLE_GSS, not USE_GSS. Introduced in commit
05fd30c0e7, reported by Thomas Munro.

Discussion: https://www.postgresql.org/message-id/CA%2BhUKG%2BHRTtB%2Bx%2BKKKj_cfX6sNhbeGuqmGxjGMwdVPG7YGFP8w@mail.gmail.com

5 months agoFix libpq_encryption tests when compiled without SSL support
Heikki Linnakangas [Fri, 12 Apr 2024 16:52:28 +0000 (19:52 +0300)] 
Fix libpq_encryption tests when compiled without SSL support

It correctly skipped tests involving SSL in the server when SSL
support was not compiled in, but even when SSL is not enabled in the
server and the connection is established without SSL, libpq behaves
differently in many of the test scenarios when libpq is compiled
without SSL support. For example, with sslmode=prefer, if libpq is
compiled with SSL support it will attempt to use SSL, but without SSL
support it will try authenticating in plaintext mode directly. The
expected test output didn't take that into account.

Discussion: https://www.postgresql.org/message-id/CA%2BhUKG%2BHRTtB%2Bx%2BKKKj_cfX6sNhbeGuqmGxjGMwdVPG7YGFP8w@mail.gmail.com

5 months agoDon't allocate large buffer on the stack in pg_verifybackup
Andrew Dunstan [Fri, 12 Apr 2024 14:52:25 +0000 (10:52 -0400)] 
Don't allocate large buffer on the stack in pg_verifybackup

Per complaint from Andres Freund. Follow his suggestion to allocate the
buffer once in the calling routine instead.

Also make a tiny indentation improvement.

Discussion: https://postgr.es/m/20240411190147.a3yries632olfcgg@awork3.anarazel.de

5 months agoAssorted minor cleanups in the test_json_parser module
Andrew Dunstan [Tue, 9 Apr 2024 19:30:48 +0000 (15:30 -0400)] 
Assorted minor cleanups in the test_json_parser module

Per gripes from Michael Paquier

Discussion: https://postgr.es/m/ZhTQ6_w1vwOhqTQI@paquier.xyz

Along the way, also clean up a handful of typos in 3311ea86ed and
ea7b4e9a2a, found by Alexander Lakhin, and a couple of stylistic
snafus noted by Daniel Westermann and Daniel Gustafsson.

5 months agoShrink test file for test_json_parser module
Andrew Dunstan [Tue, 9 Apr 2024 18:35:08 +0000 (14:35 -0400)] 
Shrink test file for test_json_parser module

Also delete live URLs

Jacob Champion

Discussion: https://postgr.es/m/CAOYmi+mtH=V1wZKAOauCd5QqQWr61hnXMJbJ9h-CZXAa1JXd3w@mail.gmail.com

5 months agoAdd a TAP test for test_json_parser_perf
Andrew Dunstan [Tue, 9 Apr 2024 18:23:20 +0000 (14:23 -0400)] 
Add a TAP test for test_json_parser_perf

This just makes sure the test can run with a single iteration. A real
performance test would test with many more.