users/rhaas/postgres.git
22 months agoShow information about flex (version and command path) in meson output
Michael Paquier [Mon, 3 Jul 2023 22:25:34 +0000 (07:25 +0900)]
Show information about flex (version and command path) in meson output

Like bison, this is useful to know which version and command of flex are
detected by meson.  For example, this was useful for me when using
win_flex.exe on Windows.

Reviewed-by: Peter Eisentraut
Discussion: https://postgr.es/m/[email protected]

22 months agoIncrease size of bgw_library_name.
Nathan Bossart [Mon, 3 Jul 2023 22:02:16 +0000 (15:02 -0700)]
Increase size of bgw_library_name.

This commit increases the size of the bgw_library_name member of
the BackgroundWorker struct from BGW_MAXLEN (96) bytes to MAXPGPATH
(default of 1024) bytes so that it can store longer file names
(e.g., absolute paths).

Author: Yurii Rashkovskii
Reviewed-by: Daniel Gustafsson, Aleksander Alekseev
Discussion: https://postgr.es/m/CA%2BRLCQyjFV5Y8tG5QgUb6gjteL4S3p%2B1gcyqWTqigyM93WZ9Pg%40mail.gmail.com

22 months agoFix race in SSI interaction with gin fast path.
Thomas Munro [Mon, 3 Jul 2023 04:20:01 +0000 (16:20 +1200)]
Fix race in SSI interaction with gin fast path.

The ginfast.c code previously checked for conflicts in before locking
the relevant buffer, leaving a window where a RW conflict could be
missed.  Re-order.

There was also a place where buffer ID and block number were confused
while trying to predicate-lock a page, noted by visual inspection.

Back-patch to all supported releases.  Fixes one more problem discovered
with the reproducer from bug #17949, in this case when Dmitry tried
other index types.

Reported-by: Artem Anisimov <[email protected]>
Reported-by: Dmitry Dolgov <[email protected]>
Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/17949-a0f17035294a55e2%40postgresql.org

22 months agoFix race in SSI interaction with bitmap heap scan.
Thomas Munro [Mon, 3 Jul 2023 04:18:20 +0000 (16:18 +1200)]
Fix race in SSI interaction with bitmap heap scan.

When performing a bitmap heap scan, we don't want to miss concurrent
writes that occurred after we observed the heap's rs_nblocks, but before
we took predicate locks on index pages.  Therefore, we can't skip
fetching any heap tuples that are referenced by the index, because we
need to test them all with CheckForSerializableConflictOut().  The
old optimization that would ignore any references to blocks >=
rs_nblocks gets in the way of that requirement, because it means that
concurrent writes in that window are ignored.

Removing that optimization shouldn't affect correctness at any isolation
level, because any new tuples shouldn't be visible to an MVCC snapshot.
There also shouldn't be any error-causing references to heap blocks past
the end, because we should have held at least an AccessShareLock on the
table before the index scan.  It can't get smaller while our transaction
is running.  For now, though, we'll keep the optimization at lower
levels to avoid making unnecessary changes in a bug fix.

Back-patch to all supported releases.  In release 11, the code is in a
different place but not fundamentally different.  Fixes one aspect of
bug #17949.

Reported-by: Artem Anisimov <[email protected]>
Reviewed-by: Dmitry Dolgov <[email protected]>
Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/17949-a0f17035294a55e2%40postgresql.org

22 months agoFix race in SSI interaction with empty btrees.
Thomas Munro [Mon, 3 Jul 2023 04:16:27 +0000 (16:16 +1200)]
Fix race in SSI interaction with empty btrees.

When predicate-locking btrees, we have a special case for completely
empty btrees, since there is no page to lock.  This was racy, because,
without buffer lock held, a matching key could be inserted between the
_bt_search() and the PredicateLockRelation() calls.

Fix, by rechecking _bt_search() after taking the relation-level SIREAD
lock, if using SERIALIZABLE isolation and an empty btree is discovered.

Back-patch to all supported releases.  Fixes one aspect of bug #17949.

Reported-by: Artem Anisimov <[email protected]>
Reviewed-by: Dmitry Dolgov <[email protected]>
Reviewed-by: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/17949-a0f17035294a55e2%40postgresql.org

22 months agoDon't truncate database and user names in startup packets.
Nathan Bossart [Mon, 3 Jul 2023 20:18:05 +0000 (13:18 -0700)]
Don't truncate database and user names in startup packets.

Unlike commands such as CREATE DATABASE, ProcessStartupPacket()
does not perform multibyte-aware truncation of overlength names.
This means that connection attempts might fail even if the user
provides the same overlength names that were used in CREATE
DATABASE, CREATE ROLE, etc.  Ideally, we'd do the same multibyte-
aware truncation in both code paths, but it doesn't seem worth the
added complexity of trying to discover the encoding of the names.
Instead, let's simply skip truncating the names in the startup
packet and let the user/database lookup fail later on.  With this
change, users must provide the exact names stored in the catalogs,
even if the names were truncated.

This reverts commit d18c1d1f51.

Author: Bertrand Drouvot
Reviewed-by: Kyotaro Horiguchi, Tom Lane
Discussion: https://postgr.es/m/07436793-1426-29b2-f924-db7422a05fb7%40gmail.com

22 months agoConsider fillfactor when estimating relation size
Tomas Vondra [Mon, 3 Jul 2023 16:55:31 +0000 (18:55 +0200)]
Consider fillfactor when estimating relation size

When table_block_relation_estimate_size() estimated the number of tuples
in a relation without statistics (e.g. right after load), it did not
consider fillfactor when calculating density. With non-default
fillfactor values, this may result in significant overestimate of the
number of tuples - up to 10x with the minimum 10% fillfactor. This may
have unexpected consequences, e.g. when creating hash indexes.

This considers the current fillfactor value in the "no statistics" code
path.  If the fillfactor changes after loading data into the table, the
estimate may be off. But that seems much less likely than changing the
fillfactor before the data load.

Reviewed-by: Corey Huinker, Peter Eisentraut
Discussion: https://postgr.es/m/cf154ef9-6bac-d268-b735-67a3443debba@enterprisedb.com

22 months agoRemove expensive test of postgres_fdw batch inserts
Tomas Vondra [Mon, 3 Jul 2023 16:16:58 +0000 (18:16 +0200)]
Remove expensive test of postgres_fdw batch inserts

The test inserted 70k rows into a foreign table, in order to verify
correct behavior with more than 65535 parameters, and was added in
response to a bug report.

However, this is rather expensive, especially when running the tests
under valgrind, CLOBBER_CACHE_ALWAYS etc. It doesn't seem worth it to
keep running the test, so remove it from all branches (14+).

Backpatch-through: 14
Discussion: https://postgr.es/m/2131017.1623451468@sss.pgh.pa.us

22 months agoImprove pg_basebackup long file name test Windows robustness
Andrew Dunstan [Mon, 3 Jul 2023 14:06:26 +0000 (10:06 -0400)]
Improve pg_basebackup long file name test Windows robustness

Creation of a file with a very long name can create problems on Windows
due to its file path limits. Work around that by creating the file via a
symlink with a shorter name.

Error displayed by buildfarm animal fairywren.o

Backpatch to all live branches

22 months agoFix code indentation violations
Tomas Vondra [Mon, 3 Jul 2023 10:38:30 +0000 (12:38 +0200)]
Fix code indentation violations

Commits ce5aaea8cd2b8b2852bb and 28d03feac3 violated the expected code
indentation rules, upsetting the new buildfarm member "koel."

Discussion: https://postgr.es/m/ZKIU4mhWpgJOM0W0%40paquier.xyz

22 months agoA minor simplification for List manipulation
Peter Eisentraut [Mon, 3 Jul 2023 09:35:15 +0000 (11:35 +0200)]
A minor simplification for List manipulation

Fix one place that was using lfirst(list_head(list)) by using linitial(list)
instead.  They are equivalent but the latter is simpler.  We did the same in
9d299a49.

Author: Richard Guo <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAMbWs49dJnpezDQDDxCPKq7+=_3NyqLqGqnhqCjd+dYe4MS15w@mail.gmail.com

22 months agoUpdate PG_CACHE_LINE_SIZE description.
Heikki Linnakangas [Mon, 3 Jul 2023 08:56:30 +0000 (11:56 +0300)]
Update PG_CACHE_LINE_SIZE description.

PG_CACHE_LINE_SIZE was originally only used in xlog.c, but this hasn't
been true for a very long time and is now wildly used, so modify its
description to not mention any explicit source code file.

Author: Julien Rouhaud
Discussion: https://www.postgresql.org/message-id/20230701074936.p3qcssl4t7murt2q@jrouhaud

22 months agocirrus/freebsd: define ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
Peter Eisentraut [Mon, 3 Jul 2023 08:08:40 +0000 (10:08 +0200)]
cirrus/freebsd: define ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS

See also: 54100f5c6052404f68de9ce7310ceb61f1c2918f

Author: Justin Pryzby <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/20220528153741[email protected]

22 months agoTake pg_attribute out of VacAttrStats
Peter Eisentraut [Mon, 3 Jul 2023 05:09:22 +0000 (07:09 +0200)]
Take pg_attribute out of VacAttrStats

The VacAttrStats structure contained the whole Form_pg_attribute for a
column, but it actually only needs attstattarget from there.  So
remove the Form_pg_attribute field and make a separate field for
attstattarget.  This simplifies some code for extended statistics that
doesn't deal with a column but an expression, which had to fake up
pg_attribute rows to satisfy internal APIs.  Also, we can remove some
comments that essentially said "don't look at pg_attribute directly".

Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/d6069765-5971-04d3-c10d-e4f7b2e9c459%40eisentraut.org

22 months agoAdd macro for maximum statistics target
Peter Eisentraut [Mon, 3 Jul 2023 05:09:22 +0000 (07:09 +0200)]
Add macro for maximum statistics target

The number of places where 10000 was hardcoded had grown a bit beyond
the comfort level.  Introduce a macro MAX_STATISTICS_TARGET instead.

Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/d6069765-5971-04d3-c10d-e4f7b2e9c459%40eisentraut.org

22 months agoChange type of pg_statistic_ext.stxstattarget
Peter Eisentraut [Mon, 3 Jul 2023 05:09:22 +0000 (07:09 +0200)]
Change type of pg_statistic_ext.stxstattarget

Change from int32 to int16, to match attstattarget (changed in
90189eefc1).

Reviewed-by: Tomas Vondra <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/d6069765-5971-04d3-c10d-e4f7b2e9c459%40eisentraut.org

22 months agoRemove support for OpenSSL 1.0.1
Michael Paquier [Mon, 3 Jul 2023 04:20:27 +0000 (13:20 +0900)]
Remove support for OpenSSL 1.0.1

Here are some notes about this change:
- As X509_get_signature_nid() should always exist (OpenSSL and
LibreSSL), hence HAVE_X509_GET_SIGNATURE_NID is now gone.
- OPENSSL_API_COMPAT is bumped to 0x10002000L.
- One comment related to 1.0.1e introduced by 74242c2 is removed.

Upstream OpenSSL still provides long-term support for 1.0.2 in a closed
fashion, so removing it is out of scope for a few years, at least.

Reviewed-by: Jacob Champion, Daniel Gustafsson
Discussion: https://postgr.es/m/[email protected]

22 months agoRefactor some code related to wait events "BufferPin" and "Extension"
Michael Paquier [Mon, 3 Jul 2023 02:01:02 +0000 (11:01 +0900)]
Refactor some code related to wait events "BufferPin" and "Extension"

The following changes are done:
- Addition of WaitEventBufferPin and WaitEventExtension, that hold a
list of wait events related to each category.
- Addition of two functions that encapsulate the list of wait events for
each category.
- Rename BUFFER_PIN to BUFFERPIN (only this wait event class used an
underscore, requiring a specific rule in the automation script).

These changes make a bit easier the automatic generation of all the code
and documentation related to wait events, as all the wait event
categories are now controlled by consistent structures and functions.

Author: Bertrand Drouvot
Discussion: https://postgr.es/m/c6f35117-4b20-4c78-1df5-d3056010dcf5@gmail.com
Discussion: https://postgr.es/m/77a86b3a-c4a8-5f5d-69b9-d70bbf2e9b98@gmail.com

22 months agoMake PG_TEST_NOCLEAN work for temporary directories in TAP tests
Michael Paquier [Mon, 3 Jul 2023 01:06:04 +0000 (10:06 +0900)]
Make PG_TEST_NOCLEAN work for temporary directories in TAP tests

When set, this environment variable was only effective for data
directories but not for all the other temporary files created by
PostgreSQL::Test::Utils.  Keeping the temporary files after a successful
run can be useful for debugging purposes.

The documentation is updated to reflect the new behavior, with contents
available in doc/ since v16 and in src/test/perl/README since v15.

Author: Jacob Champion
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CAAWbhmgHtDH1SGZ+Fw05CsXtE0mzTmjbuUxLB9mY9iPKgM6cUw@mail.gmail.com
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 11

22 months agoRemove redundant PARTITION BY columns from WindowClauses
David Rowley [Mon, 3 Jul 2023 00:49:43 +0000 (12:49 +1200)]
Remove redundant PARTITION BY columns from WindowClauses

Here we adjust the query planner to have it remove items from a window
clause's PARTITION BY clause in cases where the pathkey for a column in
the PARTITION BY clause is redundant.

Doing this allows the optimization added in 9d9c02ccd to stop window
aggregation early rather than going into "pass-through" mode to find
tuples belonging to the next partition.  Also, when we manage to remove
all PARTITION BY columns, we now no longer needlessly check that the
current tuple belongs to the same partition as the last tuple in
nodeWindowAgg.c.  If the pathkey was redundant then all tuples must
contain the same value for the given redundant column, so there's no point
in checking that during execution.

Author: David Rowley
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/CAApHDvo2ji+hdxrxfXtRtsfSVw3to2o1nCO20qimw0dUGK8hcQ@mail.gmail.com

22 months agoSilence "missing contrecord" error.
Thomas Munro [Sun, 2 Jul 2023 22:53:44 +0000 (10:53 +1200)]
Silence "missing contrecord" error.

Commit dd38ff28ad added a new error message "missing contrecord" when
we fail to reassemble a record.  Unfortunately that caused noisy
messages to be logged by pg_waldump at end of segment, and by walsender
when asked to shut down on a segment boundary.

Remove the new error message, so that this condition signals end-of-
WAL without a message.  It's arguably a reportable condition that should
not be silenced while performing crash recovery, but fixing that without
introducing noise in the other cases will require more research.

Back-patch to 15.

Reported-by: Tomas Vondra <[email protected]>
Discussion: https://postgr.es/m/6a1df56e-4656-b3ce-4b7a-a9cb41df8189%40enterprisedb.com

22 months agoFix oversight in handling of modifiedCols since f24523672d
Tomas Vondra [Sun, 2 Jul 2023 18:29:01 +0000 (20:29 +0200)]
Fix oversight in handling of modifiedCols since f24523672d

Commit f24523672d fixed a memory leak by moving the modifiedCols bitmap
into the per-row memory context. In the case of AFTER UPDATE triggers,
the bitmap is however referenced from an event kept until the end of the
query, resulting in a use-after-free bug.

Fixed by copying the bitmap into the AfterTriggerEvents memory context,
which is the one where we keep the trigger events. There's only one
place that needs to do the copy, but the memory context may not exist
yet. Doing that in a separate function seems more readable.

Report by Alexander Pyhalov, fix by me. Backpatch to 13, where the
bitmap was added to the event by commit 71d60e2aa0.

Reported-by: Alexander Pyhalov
Backpatch-through: 13
Discussion: https://postgr.es/m/acddb17c89b0d6cb940eaeda18c08bbe@postgrespro.ru

22 months agoFix memory leak in Incremental Sort rescans
Tomas Vondra [Sun, 2 Jul 2023 16:54:09 +0000 (18:54 +0200)]
Fix memory leak in Incremental Sort rescans

The Incremental Sort had a couple issues, resulting in leaking memory
during rescans, possibly triggering OOM. The code had a couple of
related flaws:

1. During rescans, the sort states were reset but then also set to NULL
   (despite the comment saying otherwise). ExecIncrementalSort then
   sees NULL and initializes a new sort state, leaking the memory used
   by the old one.

2. Initializing the sort state also automatically rebuilt the info about
   presorted keys, leaking the already initialized info. presorted_keys
   was also unnecessarily reset to NULL.

Patch by James Coleman, based on patches by Laurenz Albe and Tom Lane.
Backpatch to 13, where Incremental Sort was introduced.

Author: James Coleman, Laurenz Albe, Tom Lane
Reported-by: Laurenz Albe, Zu-Ming Jiang
Backpatch-through: 13
Discussion: https://postgr.es/m/b2bd02dff61af15e3526293e2771f874cf2a3be7.camel%40cybertec.at
Discussion: https://postgr.es/m/db03c582-086d-e7cd-d4a1-3bc722f81765%40inf.ethz.ch

22 months agoImprove BRIN minmax-multi opclass test coverage
Tomas Vondra [Sun, 2 Jul 2023 08:33:34 +0000 (10:33 +0200)]
Improve BRIN minmax-multi opclass test coverage

Per the code coverage report, the existing regression tests did not
exercice some a couple important BRIN minmax-multi code paths.

- The tests focused on testing planning with a range of scan key
  strategies, but not the execution. Fixed by adding queries that
  actually test query execution for both equality and inequality.

- All tests created indexes after inserting data, but this only
  exercises the CREATE INDEX strategy that sees all values at once, not
  incremental summary updates. The new tests flip the order and create
  the index before adding data.

- The assert check(s) validating correctness of expanded ranges were
  present only in the "union" code path, which is not covered by
  regression tests at all (as it requires concurrency etc.). Fixed by
  adding the asserts to a couple more places.

Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/57020b2e-d9c9-9bc7-4892-b36d9bb07563%40enterprisedb.com

22 months agoIntroduce bloom_filter_size for BRIN bloom opclass
Tomas Vondra [Sun, 2 Jul 2023 08:24:13 +0000 (10:24 +0200)]
Introduce bloom_filter_size for BRIN bloom opclass

Move the calculation of Bloom filter parameters (for BRIN indexes) into
a separate function to make reuse easier. At the moment we only call it
from one place, but that may change and it's easier to read anyway.

Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/0e1f3350-c9cf-ab62-43a5-5dae314de89c%40enterprisedb.com

22 months agoMinor cleanups in the BRIN code
Tomas Vondra [Sun, 2 Jul 2023 08:18:56 +0000 (10:18 +0200)]
Minor cleanups in the BRIN code

BRIN bloom and minmax-multi opclasses were somewhat inconsistent when
dealing with bool variables, assigning to them Datum values etc. While
not a bug, it makes the code harder to understand, so fix that.

While at it, update an incorrect comment copied to bloom opclass from
minmax, talking about strategies not supported by bloom.

Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/0e1f3350-c9cf-ab62-43a5-5dae314de89c%40enterprisedb.com

22 months agoTrust signalfd on illumos, again.
Thomas Munro [Sun, 2 Jul 2023 03:23:28 +0000 (15:23 +1200)]
Trust signalfd on illumos, again.

Commit 3ab4fc5d avoided choosing signalfd by default on illumos, because
it triggered kernel panics.  That was fixed, so we can remove a kludge
from our code.  Users/packagers can still override the default choice at
compile time if desired, and we'll leave the back-branches unchanged so
they keep choosing self-pipe by default, but we'll default to signalfd
(like we do for Linux) in 17.  Fixed kernels should be everywhere by the
time 17 ships.

The illumos issues were:

 * https://www.illumos.org/issues/13700
 * https://www.illumos.org/issues/14892

Discussion: https://postgr.es/m/CA+hUKG+NK-K_G_i1H3OpDTwYPEsiwQi_jw58PGcW2H+-N2eVCA@mail.gmail.com

22 months agoFix test of pg_stat_io for wal_level=minimal.
Noah Misch [Sat, 1 Jul 2023 17:00:39 +0000 (10:00 -0700)]
Fix test of pg_stat_io for wal_level=minimal.

Back-patch to v16, which introduced the test.

22 months agoRemove redundant check for fast_forward.
Heikki Linnakangas [Fri, 30 Jun 2023 15:31:10 +0000 (18:31 +0300)]
Remove redundant check for fast_forward.

We already checked for it earlier in the function.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/1ba2899e-77f8-7866-79e5-f3b7d1251a3e@iki.fi

22 months agoImprove comment on why we need ctid->(cmin,cmax) mapping.
Heikki Linnakangas [Fri, 30 Jun 2023 15:30:32 +0000 (18:30 +0300)]
Improve comment on why we need ctid->(cmin,cmax) mapping.

Combocids are only part of the problem. Explain the problem in more detail.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/1ba2899e-77f8-7866-79e5-f3b7d1251a3e@iki.fi

22 months agoAdd a test case for a316a3bc
Amit Langote [Fri, 30 Jun 2023 06:49:05 +0000 (15:49 +0900)]
Add a test case for a316a3bc

a316a3bc fixed the code in build_simpl_rel() that propagates
RelOptInfo.userid from parent to child rels so that it works
correctly for the child rels of a UNION ALL subquery rel, though
no tests were added in that commit.  So do so here.

As noted in the discussion, coming up with a test case in the core
regression suite for this fix has turned out to be tricky, so the
test case is added to the postgres_fdw's suite instead.
postgresGetForeignRelSize()'s use of user mapping for the user
specified in RelOptInfo.userid makes it relatively easier to craft
a test case around.

Discussion: https://postgr.es/m/CA%2BHiwqH91GaFNXcXbLAM9L%3DzBwUmSyv699Mtv3i1_xtk9Xec_A%40mail.gmail.com
Backpatch-through: 16

22 months agoIntroduce long options in pg_archivecleanup
Michael Paquier [Fri, 30 Jun 2023 06:47:11 +0000 (15:47 +0900)]
Introduce long options in pg_archivecleanup

This patch is a preliminary refactoring for an upcoming patch aimed at
adding new options to this tool, and using long options for these is
more user-friendly.  The existing short options gain long flavors, as
of:
* -d/--debug
* -n/--dry-run
* -x/--strip-extension

Author: Atsushi Torikoshi
Reviewed-by: Fujii Masao, Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/d660ef741ce3d82f3b4283f1cafd576c@oss.nttdata.com

22 months agoFix marking of indisvalid for partitioned indexes at creation
Michael Paquier [Fri, 30 Jun 2023 04:54:48 +0000 (13:54 +0900)]
Fix marking of indisvalid for partitioned indexes at creation

The logic that introduced partitioned indexes missed a few things when
invalidating a partitioned index when these are created, still the code
is written to handle recursions:
1) If created from scratch because a mapping index could not be found,
the new index created could be itself invalid, if for example it was a
partitioned index with one of its leaves invalid.
2) A CCI was missing when indisvalid is set for a parent index, leading
to inconsistent trees when recursing across more than one level for a
partitioned index creation if an invalidation of the parent was
required.

This could lead to the creation of a partition index tree where some of
the partitioned indexes are marked as invalid, but some of the parents
are marked valid, which is not something that should happen (as
validatePartitionedIndex() defines, indisvalid is switched to true for a
partitioned index iff all its partitions are themselves valid).

This patch makes sure that indisvalid is set to false on a partitioned
index if at least one of its partition is invalid.  The flag is set to
true if *all* its partitions are valid.

The regression test added in this commit abuses of a failed concurrent
index creation, marked as invalid, that maps with an index created on
its partitioned table afterwards.

Reported-by: Alexander Lakhin
Reviewed-by: Alexander Lakhin
Discussion: https://postgr.es/m/14987634-43c0-0cb3-e075-94d423607e08@gmail.com
Backpatch-through: 11

22 months agoAdd tab completion for CREATE SCHEMA in psql
Michael Paquier [Fri, 30 Jun 2023 01:28:08 +0000 (10:28 +0900)]
Add tab completion for CREATE SCHEMA in psql

The following patterns are added for CREATE SCHEMA:
- AUTHORIZATION, without a schema name or after a schema name.
- Possible list of owner roles after AUTHORIZATION.
- CREATE and GRANT within the supported set of commands.
- Correct object types supported in an embedded CREATE SCHEMA command.

While on it, this commit adjusts the completion done after CREATE
UNLOGGED:
- Addition of SEQUENCE.
- Avoid suggesting MATERIALIZED VIEW in CREATE TABLE.

Author: Dagfinn Ilmari Mannsåker
Reviewed-by: Suraj Khamkar, Michael Paquier
Discussion: https://postgr.es/m/[email protected]

22 months agoUse named captures in Catalog::ParseHeader()
Michael Paquier [Fri, 30 Jun 2023 00:16:27 +0000 (09:16 +0900)]
Use named captures in Catalog::ParseHeader()

Using at least perl 5.14 is required since 4c15327, meaning that it is
possible to use named captures and the %+ hash instead of having to
count parenthesis groups manually.

While on it, CATALOG is made more flexible in its handling of
whitespaces for parameter lists (see the addition of \s* in this
case).  The generated postgres.bki remains exactly the same before and
after this commit.

Author: Dagfinn Ilmari Mannsåker
Reviewed-by: John Naylor
Discussion: https://postgr.es/m/[email protected]

22 months agoStamp HEAD as 17devel.
Tom Lane [Thu, 29 Jun 2023 23:05:23 +0000 (19:05 -0400)]
Stamp HEAD as 17devel.

Let the hacking begin ...

22 months agoFix pg_depend entry to AMs after ALTER TABLE .. SET ACCESS METHOD
Michael Paquier [Thu, 29 Jun 2023 22:49:01 +0000 (07:49 +0900)]
Fix pg_depend entry to AMs after ALTER TABLE .. SET ACCESS METHOD

ALTER TABLE .. SET ACCESS METHOD was not registering a dependency to the
new access method with the relation altered in its rewrite phase, making
possible the drop of an access method even if there are relations that
depend on it.  During the rewrite, a temporary relation is created to
build the new relation files before swapping the new and old files, and,
while the temporary relation was registering a correct dependency to the
new AM, the old relation did not do that.  A dependency on the access
method is added when the relation files are swapped, which is the point
where pg_class is updated.

Materialized views and tables use the same code path, hence both were
impacted.

Backpatch down to 15, where this command has been introduced.

Reported-by: Alexander Lakhin
Reviewed-by: Nathan Bossart, Andres Freund
Discussion: https://postgr.es/m/18000-9145c25b1af475ca@postgresql.org
Backpatch-through: 15

22 months agomeson: Remove redundant return code check
Andres Freund [Thu, 29 Jun 2023 16:12:52 +0000 (09:12 -0700)]
meson: Remove redundant return code check

run_command(check: true) already would have errorred out before the check is
reached.

Author: Tristan Partin <[email protected]>
Discussion: CSPIJVUDZFKX.3KHMOAVGF94RV@c3po

22 months agoDefend against bogus parameterization of join input paths.
Tom Lane [Thu, 29 Jun 2023 16:12:52 +0000 (12:12 -0400)]
Defend against bogus parameterization of join input paths.

An outer join cannot be formed using an input path that is parameterized
by a value that is supposed to be nulled by the outer join.  This is
obviously nonsensical, and it could lead to a bad plan being selected;
although currently it seems that we'll hit various sanity-check
assertions first.

I think that such cases were formerly prevented by the delay_upper_joins
mechanism, but now that that's gone we need an explicit check.

(Perhaps we should avoid generating baserel paths that could
lead to this situation in the first place; but it seems like
having a defense at the join level would be a good idea anyway.)

Richard Guo and Tom Lane, per report from Jaime Casanova

Discussion: https://postgr.es/m/CAJKUy5g2uZRrUDZJ8p-=giwcSHVUn0c9nmdxPSY0jF0Ov8VoEA@mail.gmail.com

22 months agoFix order of operations in ExecEvalFieldStoreDeForm().
Tom Lane [Thu, 29 Jun 2023 14:19:10 +0000 (10:19 -0400)]
Fix order of operations in ExecEvalFieldStoreDeForm().

If the given composite datum is toasted out-of-line,
DatumGetHeapTupleHeader will perform database accesses to detoast it.
That can invalidate the result of get_cached_rowtype, as documented
(perhaps not plainly enough) in that function's API spec; which leads
to strange errors or crashes when we try to use the TupleDesc to read
the tuple.  In short then, trying to update a field of a composite
column could fail intermittently if the overall column value is wide
enough to require toasting.

We can fix the bug at no cost by just changing the order of
operations, since we don't need the TupleDesc until after detoasting.
(Other callers of get_cached_rowtype appear to get this right already,
so there's only one bug.)

Note that the added regression test case reveals this bug reliably
only with debug_discard_caches/CLOBBER_CACHE_ALWAYS.

Per bug #17994 from Alexander Lakhin.  Sadly, this patch does not fix
the missing-values issue revealed in the bug discussion; we'll need
some more work to cover that.

Discussion: https://postgr.es/m/17994-5c7100b51b4790e9@postgresql.org

22 months agomeson: Fix intl misspelling
Peter Eisentraut [Thu, 29 Jun 2023 11:16:52 +0000 (13:16 +0200)]
meson: Fix intl misspelling

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Use a better error message in an impossible case
Peter Eisentraut [Thu, 29 Jun 2023 11:06:41 +0000 (13:06 +0200)]
meson: Use a better error message in an impossible case

Meson validates 'choice' options for us, so technically this case is
impossible. A better error message helps people reading the code
understand what is going on in that branch.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Make some Meson style more consistent with surrounding code
Peter Eisentraut [Thu, 29 Jun 2023 11:06:02 +0000 (13:06 +0200)]
meson: Make some Meson style more consistent with surrounding code

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Fix some grammar usage in Meson comments
Peter Eisentraut [Thu, 29 Jun 2023 11:05:05 +0000 (13:05 +0200)]
meson: Fix some grammar usage in Meson comments

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Mention the correct way to disable readline support
Peter Eisentraut [Thu, 29 Jun 2023 11:04:04 +0000 (13:04 +0200)]
meson: Mention the correct way to disable readline support

Using false to disable a feature option is incorrect.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Remove old comment
Peter Eisentraut [Thu, 29 Jun 2023 11:03:19 +0000 (13:03 +0200)]
meson: Remove old comment

That portion of code is not run in the Windows case already given the
structure of the surrounding if statement.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Use the not_found_dep constant
Peter Eisentraut [Thu, 29 Jun 2023 10:56:30 +0000 (12:56 +0200)]
meson: Use the not_found_dep constant

Previously in the build description, a not_found_dep was defined. Make
use of it.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Attach colon to keyword argument
Peter Eisentraut [Thu, 29 Jun 2023 10:53:41 +0000 (12:53 +0200)]
meson: Attach colon to keyword argument

This matches the style found in the rest of the Meson build description.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Use consistent Meson option description formats
Peter Eisentraut [Thu, 29 Jun 2023 10:52:12 +0000 (12:52 +0200)]
meson: Use consistent Meson option description formats

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Use consistent casing in Meson option descriptions
Peter Eisentraut [Thu, 29 Jun 2023 10:47:33 +0000 (12:47 +0200)]
meson: Use consistent casing in Meson option descriptions

Meson itself uses capital letters for option descriptions, so follow
that.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agomeson: Remove triple-quoted strings
Peter Eisentraut [Thu, 29 Jun 2023 10:44:27 +0000 (12:44 +0200)]
meson: Remove triple-quoted strings

Triple-quoted strings are for multiline strings in Meson. None of the
descriptions that got changed were multiline and the entire file uses
single-line descriptions.

Author: Tristan Partin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CSPIJVUDZFKX.3KHMOAVGF94RV%40c3po

22 months agoRemove inappropriate raw_expression_tree_walker() code
Peter Eisentraut [Thu, 29 Jun 2023 08:30:55 +0000 (10:30 +0200)]
Remove inappropriate raw_expression_tree_walker() code

It was walking into the ColumnDef->compression field, which is not a
node but a string.  This code is currently not reachable (because the
compression field is only set in situations that don't go through
raw_expression_tree_walker()), but if it had been, this could have
behaved erratically.

22 months agoError message wording improvements
Peter Eisentraut [Thu, 29 Jun 2023 07:14:55 +0000 (09:14 +0200)]
Error message wording improvements

22 months agoFix psql \?'s entries for \dp and \z.
Nathan Bossart [Thu, 29 Jun 2023 04:32:53 +0000 (21:32 -0700)]
Fix psql \?'s entries for \dp and \z.

d913928c9c added support for the "S" modifier to psql's \dp and \z
meta-commands, but it missed updating the corresponding entries in
\?'s output.

Author: Noriyoshi Shinoda
Discussion: https://postgr.es/m/DM4PR84MB17342A51B3A1556CFBC7A4B2EE25A%40DM4PR84MB1734.NAMPRD84.PROD.OUTLOOK.COM

22 months agopg_stat_statements: Fix second comment related to entry resets
Michael Paquier [Thu, 29 Jun 2023 00:17:26 +0000 (09:17 +0900)]
pg_stat_statements: Fix second comment related to entry resets

This should have been part of dc73db6, but it got lost in the mix.
Oversight in 6b4d23f.

Author: Japin Li
Discussion: https://postgr.es/m/MEYP282MB1669FC91C764E277821936D3B624A@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Backpatch-through: 14

22 months agopg_stat_statements: Fix incorrect comment with entry resets
Michael Paquier [Wed, 28 Jun 2023 23:04:47 +0000 (08:04 +0900)]
pg_stat_statements: Fix incorrect comment with entry resets

Oversight in 6b4d23f.

Author: Japin Li, Richard Guo
Discussion: https://postgr.es/m/MEYP282MB1669FC91C764E277821936D3B624A@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Backpatch-through: 14

22 months agoReword error messages for consistency
Peter Eisentraut [Wed, 28 Jun 2023 17:30:26 +0000 (19:30 +0200)]
Reword error messages for consistency

22 months agoDoc: minor wording adjustments in transaction isolation discussion.
Tom Lane [Wed, 28 Jun 2023 16:48:14 +0000 (12:48 -0400)]
Doc: minor wording adjustments in transaction isolation discussion.

Re-word for more clarity, per gripe from Anton Sidyakin.

Discussion: https://postgr.es/m/168745911769.2239590.6062411529242609290@wrigleys.postgresql.org

22 months agoAdd timeline ID to file names generated with pg_waldump --save-fullpage
Michael Paquier [Wed, 28 Jun 2023 07:26:55 +0000 (16:26 +0900)]
Add timeline ID to file names generated with pg_waldump --save-fullpage

Not including the timeline IDs to the file names generated by pg_waldump
for the individual blocks saved could cause some of these files to be
overwritten when scanning segments across multiple timelines.  Having
this information is also as much useful as the LSNs, to be able to know
from exactly which WAL segment a block is comes from.

While on it, this fixes a few comments in the tests, where the format of
the file was not described as matching with the reality.

Reported-by: Fujii Masao
Reviewed-by: Kyotaro Horiguchi, David Christensen
Discussion: https://postgr.es/m/[email protected]

22 months agoIgnore invalid indexes when enforcing index rules in ALTER TABLE ATTACH PARTITION
Michael Paquier [Wed, 28 Jun 2023 06:57:31 +0000 (15:57 +0900)]
Ignore invalid indexes when enforcing index rules in ALTER TABLE ATTACH PARTITION

A portion of ALTER TABLE .. ATTACH PARTITION is to ensure that the
partition being attached to the partitioned table has a correct set of
indexes, so as there is a consistent index mapping between the
partitioned table and its new-to-be partition.  However, as introduced
in 8b08f7d, the current logic could choose an invalid index as a match,
which is something that can exist when dealing with more than two levels
of partitioning, like attaching a partitioned table (that has
partitions, with an index created by CREATE INDEX ON ONLY) to another
partitioned table.

A partitioned index with indisvalid set to false is equivalent to an
incomplete partition tree, meaning that an invalid partitioned index
does not have indexes defined in all its partitions.  Hence, choosing an
invalid partitioned index can create inconsistent partition index trees,
where the parent attaching to is valid, but its partition may be
invalid.

In the report from Alexander Lakhin, this showed up as an assertion
failure when validating an index.  Without assertions enabled, the
partition index tree would be actually broken, as indisvalid should
be switched to true for a partitioned index once all its partitions are
themselves valid.  With two levels of partitioning, the top partitioned
table used a valid index and was able to link to an invalid index stored
on its partition, itself a partitioned table.

I have studied a few options here (like the possibility to switch
indisvalid to false for the parent), but came down to the conclusion
that we'd better rely on a simple rule: invalid indexes had better never
be chosen, so as the partition attached uses and creates indexes that
the parent expects.  Some regression tests are added to provide some
coverage.  Note that the existing coverage is not impacted.

This is a problem since partitioned indexes exist, so backpatch all the
way down to v11.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/14987634-43c0-0cb3-e075-94d423607e08@gmail.com
Backpatch-through: 11

22 months agoRemove dependency to query text in JumbleQuery()
Michael Paquier [Tue, 27 Jun 2023 23:59:36 +0000 (08:59 +0900)]
Remove dependency to query text in JumbleQuery()

Since 3db72eb, the query ID of utilities is generated using the Query
structure, making the use of the query string in JumbleQuery()
unnecessary.  This commit removes the argument "querytext" from
JumbleQuery().

Reported-by: Joe Conway
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/[email protected]

22 months agoFix comment on clearing padding.
Heikki Linnakangas [Tue, 27 Jun 2023 07:11:31 +0000 (10:11 +0300)]
Fix comment on clearing padding.

Author: Japin Li
Discussion: https://www.postgresql.org/message-id/MEYP282MB16696317B5DA7D0D92306149B627A@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

22 months agoStamp 16beta2.
Tom Lane [Mon, 26 Jun 2023 20:07:19 +0000 (16:07 -0400)]
Stamp 16beta2.

22 months agodoc: PG 16 relnotes, update for beta 2
Bruce Momjian [Mon, 26 Jun 2023 17:44:40 +0000 (13:44 -0400)]
doc:  PG 16 relnotes, update for beta 2

22 months agoTranslation updates
Peter Eisentraut [Mon, 26 Jun 2023 10:02:02 +0000 (12:02 +0200)]
Translation updates

Source-Git-URL: https://git.postgresql.org/git/pgtranslation/messages.git
Source-Git-Hash: ab77975e9d2cde44da796c18af3ec1a66f0df7ae

22 months agoChange "..." to cstring in old input/output function comments.
Heikki Linnakangas [Mon, 26 Jun 2023 08:52:02 +0000 (11:52 +0300)]
Change "..." to cstring in old input/output function comments.

It was not clear what the "..." meant.

Author: Steve Chavez
Discussion: https://www.postgresql.org/message-id/CAGRrpzZzeh7zC3yaVG9di%3DydJ%[email protected]

22 months agoCheck for interrupts and stack overflow in TParserGet().
Tom Lane [Sat, 24 Jun 2023 21:18:08 +0000 (17:18 -0400)]
Check for interrupts and stack overflow in TParserGet().

TParserGet() recurses for some token types, meaning it's possible
to drive it to stack overflow.  Since this is a minority behavior,
I chose to add the check_stack_depth() call to the two places that
recurse rather than doing it during every single call.

While at it, add CHECK_FOR_INTERRUPTS(), because this can run
unpleasantly long for long inputs.

Per bug #17995 from Zuming Jiang.  This is old, so back-patch
to all supported branches.

Discussion: https://postgr.es/m/17995-9f20ff3e6389db4c@postgresql.org

22 months agodoc: rename "decades" to be more generic
Bruce Momjian [Sat, 24 Jun 2023 02:50:55 +0000 (22:50 -0400)]
doc:  rename "decades" to be more generic

Reported-by: Michael Paquier
Discussion: https://postgr.es/m/[email protected]

Backpatch-through: 11

22 months agoError message refactoring
Peter Eisentraut [Fri, 23 Jun 2023 14:36:17 +0000 (16:36 +0200)]
Error message refactoring

Take some untranslatable things out of the message and replace by
format placeholders, to reduce translatable strings and reduce
translation mistakes.

22 months agodoc: Improve punctuation
Peter Eisentraut [Fri, 23 Jun 2023 12:48:38 +0000 (14:48 +0200)]
doc: Improve punctuation

22 months agodoc: Clean up title case use
Peter Eisentraut [Fri, 23 Jun 2023 12:14:57 +0000 (14:14 +0200)]
doc: Clean up title case use

22 months agoFix incorrect error message in libpq_pipeline
Michael Paquier [Fri, 23 Jun 2023 08:49:07 +0000 (17:49 +0900)]
Fix incorrect error message in libpq_pipeline

One of the tests for the pipeline mode with portal description expects a
non-NULL PQgetResult, but used an incorrect error message on failure,
telling that PQgetResult being NULL was the expected result.

Author: Jelte Fennema
Discussion: https://postgr.es/m/CAGECzQTkShHecFF+EZrm94Lbsu2ej569T=bz+PjMbw9Aiioxuw@mail.gmail.com
Backpatch-through: 14

22 months agoImprove privilege documentation for maintenance commands.
Nathan Bossart [Thu, 22 Jun 2023 22:48:38 +0000 (15:48 -0700)]
Improve privilege documentation for maintenance commands.

The documentation of the required privileges for maintenance
commands (i.e., VACUUM, ANALYZE, CLUSTER, LOCK TABLE, REFRESH
MATERIALIZED VIEW, and REINDEX) is redundant, inaccurate, and
difficult to read.  This commit fixes and simplifies this
documentation by removing references to ownership, superuser, and
the pg_maintain role.  In addition, this removes notes about
database-wide VACUUM and ANALYZE, clarifies matters for REINDEX on
partitioned indexes and tables, and strengthens the description of
the pg_maintain role.

Reviewed-by: Michael Paquier, Jeff Davis
Discussion: https://postgr.es/m/20230615041044.GA736001%40nathanxps13

22 months agoFix cache lookup hazards introduced by ff9618e82a.
Nathan Bossart [Thu, 22 Jun 2023 22:48:20 +0000 (15:48 -0700)]
Fix cache lookup hazards introduced by ff9618e82a.

ff9618e82a introduced has_partition_ancestor_privs(), which is used
to check whether a user has MAINTAIN on any partition ancestors.
This involves syscache lookups, and presently this function does
not take any relation locks, so it is likely subject to the same
kind of cache lookup failures that were fixed by 19de0ab23c.

To fix this problem, this commit partially reverts ff9618e82a.
Specifically, it removes the partition-related changes, including
the has_partition_ancestor_privs() function mentioned above.  This
means that MAINTAIN on a partitioned table is no longer sufficient
to perform maintenance commands on its partitions.  This is more
like how privileges for maintenance commands work on supported
versions.  Privileges are checked for each partition, so a command
that flows down to all partitions might refuse to process them
(e.g., if the current user doesn't have MAINTAIN on the partition).

In passing, adjust a few related comments and error messages, and
add a test for the privilege checks for CLUSTER on a partitioned
table.

Reviewed-by: Michael Paquier, Jeff Davis
Discussion: https://postgr.es/m/20230613211246.GA219055%40nathanxps13

22 months agoDoc: Clarify the behavior of triggers/rules in a logical subscriber.
Amit Kapila [Thu, 22 Jun 2023 07:07:19 +0000 (12:37 +0530)]
Doc: Clarify the behavior of triggers/rules in a logical subscriber.

By default, triggers and rules do not fire on a logical replication
subscriber based on the "session_replication_role" GUC being set to
"replica". However, the docs in the logical replication section assumed
that the reader understood how this GUC worked. This modifies the docs to
be more explicit and links back to the GUC itself.

Author: Jonathan Katz, Peter Smith
Reviewed-by: Vignesh C, Euler Taveira
Backpatch-through: 11
Discussion: https://postgr.es/m/5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org

22 months agoDoc: mention that extended stats aren't used for joins
David Rowley [Thu, 22 Jun 2023 00:45:30 +0000 (12:45 +1200)]
Doc: mention that extended stats aren't used for joins

Statistics defined by the CREATE STATISTICS command are only used to
assist with the selectivity estimations of base relations, never for
joins.  Here we mention this fact in the notes section of the CREATE
STATISTICS command.

Discussion: https://postgr.es/m/CAApHDvrMuVgDOrmg_EtFDZ=AOovq6EsJNnHH1ddyZ8EqL4yzMw@mail.gmail.com
Backpatch-through: 11

22 months agonbtree VACUUM: cope with topparent inconsistencies.
Peter Geoghegan [Thu, 22 Jun 2023 00:41:58 +0000 (17:41 -0700)]
nbtree VACUUM: cope with topparent inconsistencies.

Avoid "right sibling %u of block %u is not next child" errors when
vacuuming a corrupt nbtree index.  Just LOG the issue and press on.
That way VACUUM will have a decent chance of finishing off all required
processing for the index (and for the table as a whole).

This is similar to recent work from commit 5abff197, as well as work
from commit 5b861baa (later backpatched as commit 43e409ce), which
taught nbtree VACUUM to keep going when its "re-find" check fails.  The
hardening added by this commit takes place directly after the "re-find"
check, right before the critical section for the first stage of page
deletion.

Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=dayg0vjs4+er84TS9ami=csdzjpuiCGbEw=idhwqhzQ@mail.gmail.com
Backpatch: 11- (all supported versions).

22 months agodoc: update PG history as over "three decades"
Bruce Momjian [Wed, 21 Jun 2023 23:20:07 +0000 (19:20 -0400)]
doc:  update PG history as over "three decades"

Reported-by: Pierre <[email protected]>
Discussion: https://postgr.es/m/168724660637.399156.7642965215720120947@wrigleys.postgresql.org

Backpatch-through: 11

22 months agoICU: do not convert locale 'C' to 'en-US-u-va-posix'.
Jeff Davis [Wed, 21 Jun 2023 20:18:25 +0000 (13:18 -0700)]
ICU: do not convert locale 'C' to 'en-US-u-va-posix'.

Older versions of ICU canonicalize "C" to "en-US-u-va-posix"; but
starting in ICU version 64, the "C" locale is considered
obsolete. Postgres commit ea1db8ae70 introduced code to always
canonicalize "C" to "en-US-u-va-posix" for consistency and
convenience, but it was deemed too confusing.

This commit removes that code, so that "C" is treated like other ICU
locale names: canonicalization is attempted, and if it fails, the
behavior is controlled by icu_validation_level.

A similar change was previously committed as f7faa9976c, then reverted
due to an ICU-version-dependent test failure. This commit un-reverts
it, omitting the test because we now expect the behavior to depend on
the version of ICU being used.

Discussion: https://postgr.es/m/3a200aca-4672-4b37-fc91-5d198a323503%40eisentraut.org
Discussion: https://postgr.es/m/f83f089ee1e9acd5dbbbf3353294d24e1f196e95[email protected]
Discussion: https://postgr.es/m/37520ec1ae9591f83132f82dbd625f3fc2d69c16[email protected]

22 months agoinitdb: change default --locale-provider back to libc.
Jeff Davis [Wed, 21 Jun 2023 18:10:03 +0000 (11:10 -0700)]
initdb: change default --locale-provider back to libc.

Reverts 27b62377b4.

Discussion: https://postgr.es/m/eff031036baa07f325de29215371a4c9e69d61f3[email protected]
Discussion: https://postgr.es/m/3353947.1682092131@sss.pgh.pa.us

22 months agoAvoid Assert failure when processing empty statement in aborted xact.
Tom Lane [Wed, 21 Jun 2023 15:07:11 +0000 (11:07 -0400)]
Avoid Assert failure when processing empty statement in aborted xact.

exec_parse_message() wants to create a cached plan in all cases,
including for empty input.  The empty-input path does not have
a test for being in an aborted transaction, making it possible
that plancache.c will fail due to trying to do database lookups
even though there's no real work to do.

One solution would be to throw an aborted-transaction error in
this path too, but it's not entirely clear whether the lack of
such an error was intentional or whether some clients might be
relying on non-error behavior.  Instead, let's hack plancache.c
so that it treats empty statements with the same logic it
already had for transaction control commands, ensuring that it
can soldier through even in an already-aborted transaction.

Per bug #17983 from Alexander Lakhin.  Back-patch to all
supported branches.

Discussion: https://postgr.es/m/17983-da4569fcb878672e@postgresql.org

22 months agoAllow and require passing files on command line of pgperltidy
Peter Eisentraut [Wed, 21 Jun 2023 14:14:47 +0000 (16:14 +0200)]
Allow and require passing files on command line of pgperltidy

pgperltidy as well as pgperlcritic and pgperlsyncheck now allow
passing files and directories on the command line, like pgindent does.
(Previously, they would always operate on the whole tree.)

Also, for consistency with pgindent's new behavior (as of b16259b3c1),
passing an argument is now required.  To get the previous default
behavior, use "pgperltidy ." for example.

Discussion: https://www.postgresql.org/message-id/flat/45aacd8a-5265-d9da-8df2-b8e2c0cf6a07%40eisentraut.org

22 months agoDisable use of archiving in 009_twophase.pl
Michael Paquier [Wed, 21 Jun 2023 07:16:15 +0000 (16:16 +0900)]
Disable use of archiving in 009_twophase.pl

This partially reverts 68cb5af, as using archiving to enforce the
rename of the last partial segment of the old timeline at promotion to
use .partial as suffix is impacting the tests when it does switchovers.
As showed by the logs gathered by the CI in the tests that failed, a new
standby may fail to find the WAL segment it needs to follow a promoted
instance with its timeline jump, as it got renamed to .partial.

This problem would manifest as a run timeout with 009_twophase.pl, as
the new standby repeatedly requests a segment from the promoted primary
that it would not find.

Reported-by: Nathan Bossart
Discussion: https://postgr.es/m/20230621043345.GA787473@nathanxps13
Backpatch-through: 13

22 months agoFix the errhint message and docs for drop subscription failure.
Amit Kapila [Wed, 21 Jun 2023 05:06:09 +0000 (10:36 +0530)]
Fix the errhint message and docs for drop subscription failure.

The existing errhint message and docs were missing the fact that we can't
disassociate from the slot unless the subscription is disabled.

Author: Robert Sjöblom, Peter Smith
Reviewed-by: Peter Eisentraut, Amit Kapila
Backpatch-through: 11
Discussion: https://postgr.es/m/807bdf85-61ea-88e2-5712-6d9fcd4eabff@fortnox.se

22 months agoMove bool parameter for vacuum_rel() to option bits.
Nathan Bossart [Tue, 20 Jun 2023 22:14:58 +0000 (15:14 -0700)]
Move bool parameter for vacuum_rel() to option bits.

ff9618e82a introduced the skip_privs parameter, which is used to
skip privilege checks when recursing to a relation's TOAST table.
This parameter should have been added as a flag bit in
VacuumParams->options instead.

Suggested-by: Michael Paquier
Reviewed-by: Michael Paquier, Jeff Davis
Discussion: https://postgr.es/m/ZIj4v1CwqlDVJZfB%40paquier.xyz

22 months agoFix hash join when inner hashkey expressions contain Params.
Tom Lane [Tue, 20 Jun 2023 21:47:36 +0000 (17:47 -0400)]
Fix hash join when inner hashkey expressions contain Params.

If the inner-side expressions contain PARAM_EXEC Params, we must
re-hash whenever the values of those Params change.  The executor
mechanism for that exists already, but we failed to invoke it because
finalize_plan() neglected to search the Hash.hashkeys field for
Params.  This allowed a previous scan's hash table to be re-used
when it should not be, leading to rows missing from the join's output.
(I believe incorrectly-included join rows are impossible however,
since checking the real hashclauses would reject false matches.)

This bug is very ancient, dating probably to d24d75ff1 of 7.4.
Sadly, this simple fix depends on the plan representational changes
made by 2abd7ae9b, so it will only work back to v12.  I thought
about trying to make some kind of hack for v11, but I'm leery
of putting code significantly different from what is used in the
newer branches into a nearly-EOL branch.  Seeing that the bug
escaped detection for a full twenty years, problematic cases
must be rare; so I don't feel too awful about leaving v11 as-is.

Per bug #17985 from Zuming Jiang.  Back-patch to v12.

Discussion: https://postgr.es/m/17985-748b66607acd432e@postgresql.org

22 months agodocs: adjust tag indenting and add MERGE mention
Bruce Momjian [Tue, 20 Jun 2023 17:15:18 +0000 (13:15 -0400)]
docs:  adjust tag indenting and add MERGE mention

Discussion: https://postgr.es/m/CAMpnoC4_WsY3gsY+ud-Z0GDbafR=K7t7cXn2gatEqFnsRNY3yQ@mail.gmail.com

Author: Will Mortensen

22 months agoFix another cause of "wrong varnullingrels" planner failures.
Tom Lane [Tue, 20 Jun 2023 15:09:56 +0000 (11:09 -0400)]
Fix another cause of "wrong varnullingrels" planner failures.

I removed the delay_upper_joins mechanism in commit b448f1c8d,
reasoning that it was only needed when we have a single-table
(SELECT ... WHERE) as the immediate RHS child of a left join,
and we could get rid of that by hoisting the WHERE condition into
the parent join's quals.  However that new code missed a case:
we could have "foo LEFT JOIN ((SELECT ... WHERE) LEFT JOIN bar)",
and if the two left joins can be commuted then we now have the
problematic query shape.  We can fix this too easily enough,
by allowing the syntactically-lower left join to pass through
its parent qual location pointer recursively.  That lets
prepjointree.c discard the SELECT by temporarily hoisting the
WHERE condition into the ancestor join's qual.

Per bug #17978 from Zuming Jiang.

Discussion: https://postgr.es/m/17978-12f3d93a55297266@postgresql.org

22 months agoDon't include outer join relids in lateral_relids bitmapsets.
Tom Lane [Tue, 20 Jun 2023 14:29:57 +0000 (10:29 -0400)]
Don't include outer join relids in lateral_relids bitmapsets.

This avoids an assertion failure when outer joins are rearranged
per identity 3.  Listing only the baserels from a PlaceHolderVar's
ph_lateral set should be enough to ensure that the required values
are available when we need to compute the PHV --- it's what we
did before inventing nullingrel sets, after all.  It's a bit
unsatisfying; but with beta2 hard upon us, there's not time to
look for an aesthetically cleaner fix.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/CAMbWs48Jcw-NvnxT23WiHP324wG44DvzcH1j4hc0Zn+3sR9cfg@mail.gmail.com

22 months agoCentralize fixups for mismatched nullingrels in nestloop params.
Tom Lane [Tue, 20 Jun 2023 14:22:52 +0000 (10:22 -0400)]
Centralize fixups for mismatched nullingrels in nestloop params.

It turns out that the fixes we applied in commits bfd332b3f
and 63e4f13d2 were not nearly enough to solve the problem.
We'd focused narrowly on subquery RTEs with lateral references,
but lateral references can occur in several other RTE kinds
such as function RTEs.  Putting the same hack into half a dozen
code paths seems quite unattractive.  Hence, revert the code changes
(but not the test cases) from those commits and instead solve it
centrally in identify_current_nestloop_params(), as Richard proposed
originally.  This is a bit annoying because it could mask erroneous
nullingrels in nestloop params that are generated from non-LATERAL
parameterized paths; but on balance I don't see a better way.
Maybe at some future time we'll be motivated to find a more rigorous
approach to nestloop params, but that's not happening for beta2.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/CAMbWs48Jcw-NvnxT23WiHP324wG44DvzcH1j4hc0Zn+3sR9cfg@mail.gmail.com

22 months agoAdd b334612b8 to .git-blame-ignore-revs.
Tom Lane [Tue, 20 Jun 2023 13:52:52 +0000 (09:52 -0400)]
Add b334612b8 to .git-blame-ignore-revs.

22 months agoPre-beta2 mechanical code beautification.
Tom Lane [Tue, 20 Jun 2023 13:50:43 +0000 (09:50 -0400)]
Pre-beta2 mechanical code beautification.

Run pgindent and pgperltidy.  It seems we're still some ways
away from all committers doing this automatically.  Now that
we have a buildfarm animal that will whine about poorly-indented
code, we'll try to keep the tree more tidy.

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

22 months agotest_extensions: make meson.build consistent with Makefile.
Jeff Davis [Tue, 20 Jun 2023 01:08:59 +0000 (18:08 -0700)]
test_extensions: make meson.build consistent with Makefile.

Specify --no-locale and --encoding=UTF8 to be consistent with the
Makefile, which specifies NO_LOCALE=1. Fixes test for some locales
when meson is used and ICU is disabled. May have been an oversight in
e6927270cd.

Also switch argument order in unaccent/meson.build to make it
consistent in style.

Discussion: https://postgr.es/m/CABwTF4Wz41pNMJ9q3tpH=6mnvg6aopDU5Lzvers5=6=WJVekww@mail.gmail.com
Author: Gurjeet Singh
Author: Jeff Davis

22 months agoEnable archiving in recovery TAP test 009_twophase.pl
Michael Paquier [Tue, 20 Jun 2023 01:25:27 +0000 (10:25 +0900)]
Enable archiving in recovery TAP test 009_twophase.pl

This is a follow-up of f663b00, that has been committed to v13 and v14,
tweaking the TAP test for two-phase transactions so as it provides
coverage for the bug that has been fixed.  This change is done in its
own commit for clarity, as v15 and HEAD did not show the problematic
behavior, still missed coverage for it.

While on it, this adds a comment about the dependency of the last
partial segment rename and RecoverPreparedTransactions() at the end of
recovery, as that can be easy to miss.

Author: Michael Paquier
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/743b9b45a2d4013bd90b6a5cba8d6faeb717ee34[email protected]
Backpatch-through: 13

22 months agofd.c: Retry after EINTR in more places
Andres Freund [Mon, 19 Jun 2023 21:11:32 +0000 (14:11 -0700)]
fd.c: Retry after EINTR in more places

Starting with 4d330a61bb1 we can use posix_fallocate() to extend
files. Unfortunately in some situation, e.g. on tmpfs filesystems, EINTR may
be returned. See also 4518c798b2b.

To fix, add a retry path to FileFallocate(). In contrast to 4518c798b2b the
amount we extend by is limited and the extending may happen at a high
frequency, so disabling signals does not appear to be the correct path here.

Also add retry paths to other file operations currently lacking them (around
fdatasync(), fsync(), ftruncate(), posix_fadvise(), sync_file_range(),
truncate()) - they are all documented or have been observed to return EINTR.

Even though most of these functions used in the back branches, it does not
seem worth the risk to backpatch - outside of the new-to-16 case of
posix_fallocate() I am not aware of problem reports due to the lack of
retries.

Reported-by: Christoph Berg <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch: -

22 months agopg_regress: for --no-locale, use LOCALE='C'.
Jeff Davis [Mon, 19 Jun 2023 18:51:22 +0000 (11:51 -0700)]
pg_regress: for --no-locale, use LOCALE='C'.

Instead of specifying LC_COLLATE='C' and LC_CTYPE='C', specify
LOCALE='C' which will also affect ICU. This makes pg_regress
consistent with recent changes to initdb in commit a14e75eb0b6.

Fixes buildfarm failure.

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

22 months agoDon't use partial unique indexes for unique proofs in the planner
David Rowley [Mon, 19 Jun 2023 01:00:42 +0000 (13:00 +1200)]
Don't use partial unique indexes for unique proofs in the planner

Here we adjust relation_has_unique_index_for() so that it no longer makes
use of partial unique indexes as uniqueness proofs.  It is incorrect to
use these as the predicates used by check_index_predicates() to set
predOK makes use of not only baserestrictinfo quals as proofs, but also
qual from join conditions.  For relation_has_unique_index_for()'s case, we
need to know the relation is unique for a given set of columns before any
joins are evaluated, so if predOK was only set to true due to some join
qual, then it's unsafe to use such indexes in
relation_has_unique_index_for().  The final plan may not even make use
of that index, which could result in reading tuples that are not as
unique as the planner previously expected them to be.

Bug: #17975
Reported-by: Tor Erik Linnerud
Backpatch-through: 11, all supported versions
Discussion: https://postgr.es/m/17975-98a90c156f25c952%40postgresql.org

23 months agoCREATE DATABASE: make LOCALE apply to all collation providers.
Jeff Davis [Fri, 16 Jun 2023 17:27:32 +0000 (10:27 -0700)]
CREATE DATABASE: make LOCALE apply to all collation providers.

For CREATE DATABASE, make LOCALE parameter apply regardless of the
provider used. Also affects initdb and createdb --locale arguments.

Previously, LOCALE (and --locale) only affected the database default
collation when using the libc provider.

Discussion: https://postgr.es/m/1a63084d-221e-4075-619e-6b3e590f673e@enterprisedb.com
Reviewed-by: Peter Eisentraut
23 months agolibpq: Add missing gettext trigger
Peter Eisentraut [Fri, 16 Jun 2023 08:53:22 +0000 (10:53 +0200)]
libpq: Add missing gettext trigger

libpq_ngettext() was missing.  This was an ancient mistake (commit
acd08d764a).

23 months agoAdd missing pg_basebackup TAP test for meson.
Masahiko Sawada [Fri, 16 Jun 2023 01:32:49 +0000 (10:32 +0900)]
Add missing pg_basebackup TAP test for meson.

011_in_place_tablespace was missing from the list of pg_basebackup
tests to run under meson, so add it.

Oversight in 363e8f9115.

Discussion: https://postgr.es/m/CAD21AoDTh1A8bvNBF3LQNQg=27xTpSgvpT+4_yyEj6p4Zv8unA@mail.gmail.com