postgresql.git
23 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: -

23 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

23 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

23 months agoFix typo in comment.
Amit Langote [Fri, 16 Jun 2023 01:04:22 +0000 (10:04 +0900)]
Fix typo in comment.

Back-patch down to 11.

Author: Sho Kato (<[email protected]>)
Discussion: https://postgr.es/m/TYCPR01MB68499042A33BC32241193AAF9F5BA%40TYCPR01MB6849.jpnprd01.prod.outlook.com

23 months agoWhen removing a left join, clean out references in EquivalenceClasses.
Tom Lane [Thu, 15 Jun 2023 19:24:50 +0000 (15:24 -0400)]
When removing a left join, clean out references in EquivalenceClasses.

Since commit b448f1c8d, we've been able to remove left joins
(that are otherwise removable) even when they are underneath
other left joins, a case that was previously prevented by a
delay_upper_joins check.  This is a clear improvement, but
it has a surprising side-effect: it's now possible that there
are EquivalenceClasses whose relid sets mention the removed
baserel and/or outer join.  If we fail to clean those up,
we may drop essential join quals due to not having any join
level that appears to satisfy their relid sets.

(It's not quite 100% clear that this was impossible before.
But the lack of complaints since we added join removal a dozen
years ago strongly suggests that it was impossible.)

Richard Guo and Tom Lane, per bug #17976 from Zuming Jiang

Discussion: https://postgr.es/m/17976-4b638b525e9a983b@postgresql.org

23 months agoRemove outdated reference to a removed file
Amit Langote [Thu, 15 Jun 2023 09:39:45 +0000 (18:39 +0900)]
Remove outdated reference to a removed file

parse_jsontable.c was removed as part of 2f2b18bd3f55, though its
mention in src/backend/parser/README was not.  Fix that.

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

23 months agolibpq: Fix up some error message coding
Peter Eisentraut [Thu, 15 Jun 2023 11:54:37 +0000 (13:54 +0200)]
libpq: Fix up some error message coding

This applies the new error message API from commit 0873b2d354 to the
changes introduced by bbf9c282ce.  The latter was committed shortly
after the former, so it probably didn't get the news in time.

23 months agoAdd missing subscription TAP test for meson
Michael Paquier [Thu, 15 Jun 2023 08:27:21 +0000 (17:27 +0900)]
Add missing subscription TAP test for meson

033_run_as_table_owner was missing from the list of subscription tests
to run under meson, so add it.

Oversight in 4826759.

Author: Hayato Kuroda
Discussion: https://postgr.es/m/TYAPR01MB58668F4D85A9A122A158F442F55BA@TYAPR01MB5866.jpnprd01.prod.outlook.com

23 months agoReplace GUC_UNIT_MEMORY|GUC_UNIT_TIME with GUC_UNIT.
Masahiko Sawada [Thu, 15 Jun 2023 08:04:19 +0000 (17:04 +0900)]
Replace GUC_UNIT_MEMORY|GUC_UNIT_TIME with GUC_UNIT.

We used (GUC_UNIT_MEMORY | GUC_UNIT_TIME) instead of GUC_UNIT some
places but we already define it in guc.h. This commit replaces them
with GUC_UNIT for better consistency with their surrounding code.

Author: Japin Li
Reviewed-by: Richard Guo, Michael Paquier, Masahiko Sawada
Discussion: https://postgr.es/m/MEYP282MB1669EC0FED922F7A151673ACB65AA@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

23 months agointarray: Prevent out-of-bound memory reads with gist__int_ops
Michael Paquier [Thu, 15 Jun 2023 04:45:34 +0000 (13:45 +0900)]
intarray: Prevent out-of-bound memory reads with gist__int_ops

As gist__int_ops stands in intarray, it is possible to store GiST
entries for leaf pages that can cause corruptions when decompressed.
Leaf nodes are stored as decompressed all the time by the compression
method, and the decompression method should map with that, retrieving
the contents of the page without doing any decompression.  However, the
code authorized the insertion of leaf page data with a higher number of
array items than what can be supported, generating a NOTICE message to
inform about this matter (199 for a 8k page, for reference).  When
calling the decompression method, a decompression would be attempted on
this leaf node item but the contents should be retrieved as they are.

The NOTICE message generated when dealing with the compression of a leaf
page and too many elements in the input array for gist__int_ops has been
introduced by 08ee64e, removing the marker stored in the array to track
if this is actually a leaf node.  However, it also missed the fact that
the decompression path should do nothing for a leaf page.  Hence, as the
code stand, a too-large array would be stored as uncompressed but the
decompression path would attempt a decompression rather that retrieving
the contents as they are.

This leads to various problems.  First, even if 08ee64e tried to address
that, it is possible to do out-of-bound chunk writes with a large input
array, with the backend informing about that with WARNINGs.  On
decompression, retrieving the stored leaf data would lead to incorrect
memory reads, leading to crashes or even worse.

Perhaps somebody would be interested in expanding the number of array
items that can be handled in a leaf page for this operator in the
future, which would require revisiting the choice done in 08ee64e, but
based on the lack of reports about this problem since 2005 it does not
look so.  For now, this commit prevents the insertion of data for leaf
pages when using more array items that the code can handle on
decompression, switching the NOTICE message to an ERROR.  If one wishes
to use more array items, gist__intbig_ops is an optional choice.

While on it, use ERRCODE_PROGRAM_LIMIT_EXCEEDED as error code when a
limit is reached, because that's what the module is facing in such
cases.

Author: Ankit Kumar Pandey, Alexander Lakhin
Reviewed-by: Richard Guo, Michael Paquier
Discussion: https://postgr.es/m/796b65c3-57b7-bddf-b0d5-a8afafb8b627@gmail.com
Discussion: https://postgr.es/m/17888-f72930e6b5ce8c14@postgresql.org
Backpatch-through: 11

23 months agoFix possible crash in tablesync worker.
Amit Kapila [Thu, 15 Jun 2023 03:07:48 +0000 (08:37 +0530)]
Fix possible crash in tablesync worker.

Commit c3afe8cf5a added a new password_required option but forgot that you
need database access to check whether an arbitrary role ID is a superuser.

Commit e7e7da2f8d fixed a similar bug in apply worker, and this patch
fixes a similar bug in tablesync worker.

Author: Hou Zhijie
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/OS0PR01MB571607F5A9D723755268D36294759@OS0PR01MB5716.jpnprd01.prod.outlook.com

23 months agoMake parseNodeString() C idiom compatible with Visual Studio 2015.
Noah Misch [Wed, 14 Jun 2023 12:31:54 +0000 (05:31 -0700)]
Make parseNodeString() C idiom compatible with Visual Studio 2015.

Between v15 and now, this function's "else if" chain grew from 252 lines
to 592 lines, exceeding a compiler limit that manifests as "fatal error
C1026: parser stack overflow, program too complex (compiling source file
src/backend/nodes/readfuncs.c)".  Use "if (...)  return ...;" instead.

Reviewed by Tom Lane, Peter Eisentraut and Michael Paquier.  Not all
reviewers endorse this.

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

23 months agoFix typo in comment.
Masahiko Sawada [Wed, 14 Jun 2023 04:28:41 +0000 (13:28 +0900)]
Fix typo in comment.

Introduced in 4d330a61bb1.

Author: Masahiko Sawada
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAD21AoDg8rTWJkrNJg9UTP89vS8smfib2c55DVqKrCn8zR-GYA@mail.gmail.com

23 months agoRetain relkind too in RTE_SUBQUERY entries for views.
Amit Langote [Tue, 13 Jun 2023 03:52:47 +0000 (12:52 +0900)]
Retain relkind too in RTE_SUBQUERY entries for views.

47bb9db75 modified the ApplyRetrieveRule()'s conversion of a view's
original RTE_RELATION entry into an RTE_SUBQUERY one to retain relid,
rellockmode, and perminfoindex so that the executor can lock the view
and check its permissions.  It seems better to also retain
relkind for cross-checking that the exception of an
RTE_SUBQUERY entry being allowed to carry relation details only
applies to views, so do so.

Bump catversion because this changes the output format of
RTE_SUBQUERY RTEs.

Suggested-by: David Steele <[email protected]>
Reviewed-by: David Steele <[email protected]>
Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/3953179e-9540-e5d1-a743-4bef368785b0%40pgmasters.net

23 months agoFix make_etags breakage on certain platforms.
Tatsuo Ishii [Wed, 14 Jun 2023 02:02:50 +0000 (11:02 +0900)]
Fix make_etags breakage on certain platforms.

make_etags produced wrong format TAGS files on platforms such as Mac,
which uses non-Exuberant ctags.

Author: Masahiko Sawada
Reviewed-by: Tatsuo Ishii
Backpatch-through: 15
Discussion: https://postgr.es/m/CAD21AoDmCqpS%2BU6b9Bc-b4OFx3tz%3DNv6O2KVkoVg7sHk60spjA%40mail.gmail.com

23 months agoFix "wrong varnullingrels" for Memoize's lateral references, too.
Tom Lane [Tue, 13 Jun 2023 22:01:33 +0000 (18:01 -0400)]
Fix "wrong varnullingrels" for Memoize's lateral references, too.

The issue fixed in commit bfd332b3f can also bite Memoize plans,
because of the separate copies of lateral reference Vars made
by paraminfo_get_equal_hashops.  Apply the same hacky fix there.

(In passing, clean up shaky grammar in the existing comments
for this function.)

Richard Guo

Discussion: https://postgr.es/m/CAMbWs4-krwk0Wbd6WdufMAupuou_Ua73ijQ4XQCr1Mb5BaVtKQ@mail.gmail.com

23 months agoCorrectly update hasSubLinks while mutating a rule action.
Tom Lane [Tue, 13 Jun 2023 19:58:37 +0000 (15:58 -0400)]
Correctly update hasSubLinks while mutating a rule action.

rewriteRuleAction neglected to check for SubLink nodes in the
securityQuals of range table entries.  This could lead to failing
to convert such a SubLink to a SubPlan, resulting in assertion
crashes or weird errors later in planning.

In passing, fix some poor coding in rewriteTargetView:
we should not pass the source parsetree's hasSubLinks
field to ReplaceVarsFromTargetList's outer_hasSubLinks.
ReplaceVarsFromTargetList knows enough to ignore that
when a Query node is passed, but it's still confusing
and bad precedent: if we did try to update that flag
we'd be updating a stale copy of the parsetree.

Per bug #17972 from Alexander Lakhin.  This has been broken since
we added RangeTblEntry.securityQuals (although the presented test
case only fails back to 215b43cdc), so back-patch all the way.

Discussion: https://postgr.es/m/17972-f422c094237847d0@postgresql.org

23 months agodoc: Move list entry to proper position
Peter Eisentraut [Tue, 13 Jun 2023 13:00:52 +0000 (15:00 +0200)]
doc: Move list entry to proper position

23 months agoReport stats when replaying XLOG_RUNNING_XACTS
Andres Freund [Mon, 12 Jun 2023 22:06:12 +0000 (15:06 -0700)]
Report stats when replaying XLOG_RUNNING_XACTS

Previously stats in the startup process would only get reported during
shutdown of the startup process. It has been that way for a long time, but
became a lot more noticeable with the new pg_stat_io view, which separates out
IO done by different backend types...

While replaying after every XLOG_RUNNING_XACTS isn't the prettiest approach,
it has the advantage of being quite easy. Given that we're well past feature
freeze...

It's not a problem that we don't report stats more frequently with
wal_level=minimal, in that case stats can't be read before the stats process
has shut down.

Besides the above, this commit also changes pgstat_report_stat() to acquire
the timestamp with GetCurrentTimestamp() instead of
GetCurrentTransactionStopTimestamp().

Thanks to Melih Mutlu, Kyotaro Horiguchi for prototypes of other approaches to
solving this issue.

Reported-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/5315aedc-fbca-1556-c5de-dc2e00b23a14@oss.nttdata.com

23 months agoAccept fractional seconds in jsonpath's datetime() method.
Tom Lane [Mon, 12 Jun 2023 14:54:28 +0000 (10:54 -0400)]
Accept fractional seconds in jsonpath's datetime() method.

Commit 927d9abb6 purported to make datetime() accept any string
that could be output for a datetime value by to_jsonb().  But it
overlooked the possibility of fractional seconds being present,
so that cases as simple as to_jsonb(now()) would defeat it.

Fix by adding formats that include ".US" to the list in
executeDateTimeMethod().  (Note that while this is nominally
microseconds, it'll do the right thing for fractions with
fewer than six digits.)

In passing, re-order the list to restore the datatype ordering
specified in its comment.  The violation accidentally did not
break anything; but the next edit might be less lucky, so add
more comments.

Per report from Tim Field.  Back-patch to v13 where datetime()
was added, like the previous patch.

Discussion: https://postgr.es/m/014A028B-5CE6-4FDF-AC24-426CA6FC9CEE@mohiohio.com

23 months agosrc/tools/msvc/clean.bat: Reconcile with PostgreSQL 16 work.
Noah Misch [Mon, 12 Jun 2023 14:40:39 +0000 (07:40 -0700)]
src/tools/msvc/clean.bat: Reconcile with PostgreSQL 16 work.

23 months agosrc/tools/msvc: Move all.sym temporary file back to Debug/postgres.
Noah Misch [Mon, 12 Jun 2023 14:40:39 +0000 (07:40 -0700)]
src/tools/msvc: Move all.sym temporary file back to Debug/postgres.

Commit 70df2df1cc89e69e31b31b6aa0d65fd72935af38 moved it to the
top_srcdir, where it caused "git status" noise.

23 months agoAdd win32ver data to meson-built postgres.exe.
Noah Misch [Mon, 12 Jun 2023 14:40:38 +0000 (07:40 -0700)]
Add win32ver data to meson-built postgres.exe.

As in the older build systems, the resources object is not an input to
postgres.def.

Reviewed by Andres Freund.

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

23 months agoGive postgres.exe the icon of other executables.
Noah Misch [Mon, 12 Jun 2023 14:40:38 +0000 (07:40 -0700)]
Give postgres.exe the icon of other executables.

We had left it icon-free since users won't achieve much by opening it
from Windows Explorer.  Subsequent to that decision, Task Manager
started to show the icon.  That shifts the balance in favor of attaching
the icon, so do so.  No back-patch, but make this late addition to v16.

Reviewed by Andres Freund and Magnus Hagander.

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

23 months agoFix "wrong varnullingrels" for subquery nestloop parameters.
Tom Lane [Mon, 12 Jun 2023 14:01:26 +0000 (10:01 -0400)]
Fix "wrong varnullingrels" for subquery nestloop parameters.

If we apply outer join identity 3 when relation C is a subquery
having lateral references to relation B, then the lateral references
within C continue to bear the original syntactically-correct
varnullingrels marks, but that won't match what is available from
the outer side of the nestloop.  Compensate for that in
process_subquery_nestloop_params().  This is a slightly hacky fix,
but we certainly don't want to re-plan C in toto for each possible
outer join order, so there's not a lot of better alternatives.

Richard Guo and Tom Lane, per report from Markus Winand

Discussion: https://postgr.es/m/DFBB2D25-DE97-49CA-A60E-07C881EA59A7@winand.at

23 months agoRemove a few unused global variables and declarations.
Heikki Linnakangas [Mon, 12 Jun 2023 13:25:37 +0000 (16:25 +0300)]
Remove a few unused global variables and declarations.

- Commit 3eb77eba5a, which moved the pending ops queue from md.c to
  sync.c, introduced a duplicate, unused 'pendingOpsCxt'
  variable. (I'm surprised none of the compilers or static analysis
  tools have complained about that.)

- Commit c2fe139c20 moved the 'synchronize_seqscans' variable and
  introduced an extern declaration in tableam.h, making the one in
  guc_tables.c unnecessary.

- Commit 6f0cf87872 removed the 'pgstat_temp_directory' GUC, but
  forgot to remove the corresponding global variable.

- Commit 1b4e729eaa removed the 'pg_krb_realm' GUC, and its global
  variable, but forgot the declaration in auth.h.

Spotted all these by reading the code.

23 months agoFix instability in regression test for Parallel Hash Full Join
Michael Paquier [Mon, 12 Jun 2023 03:19:46 +0000 (12:19 +0900)]
Fix instability in regression test for Parallel Hash Full Join

As reported by buildfarm member conchuela, one of the regression tests
added by 558c9d7 is having some ordering issues.  This commit adds an
ORDER BY clause to make the output more stable for the problematic
query.

Fix suggested by Tom Lane.  The plan of the query updated still uses a
parallel hash full join.

Author: Melanie Plageman
Discussion: https://postgr.es/m/623596.1684541098@sss.pgh.pa.us

23 months agohstore: Tighten key/value parsing check for whitespaces
Michael Paquier [Mon, 12 Jun 2023 00:14:03 +0000 (09:14 +0900)]
hstore: Tighten key/value parsing check for whitespaces

isspace() can be locale-sensitive depending on the platform, causing
hstore to consider as whitespaces characters it should not see as such.
For example, U+0105, being decoded as 0xC4 0x85 in UTF-8, would be
discarded from the input given.

This problem is similar to 9ae2661, though it was missed that hstore
can also manipulate non-ASCII inputs, so replace the existing isspace()
calls with scanner_isspace().

This problem exists for a long time, so backpatch all the way down.

Author: Evan Jones
Discussion: https://postgr.es/m/CA+HWA9awUW0+RV_gO9r1ABZwGoZxPztcJxPy8vMFSTbTfi4jig@mail.gmail.com
Backpatch-through: 11

23 months agonbtree: Allocate new pages in separate function.
Peter Geoghegan [Sat, 10 Jun 2023 21:08:25 +0000 (14:08 -0700)]
nbtree: Allocate new pages in separate function.

Split nbtree's _bt_getbuf function is two: code that read locks or write
locks existing pages remains in _bt_getbuf, while code that deals with
allocating new pages is moved to a new, dedicated function called
_bt_allocbuf.  This simplifies most _bt_getbuf callers, since it is no
longer necessary for them to pass a heaprel argument.  Many of the
changes to nbtree from commit 61b313e4 can be reverted.  This minimizes
the divergence between HEAD/PostgreSQL 16 and earlier release branches.

_bt_allocbuf replaces the previous nbtree idiom of passing P_NEW to
_bt_getbuf.  There are only 3 affected call sites, all of which continue
to pass a heaprel for recovery conflict purposes.  Note that nbtree's
use of P_NEW was superficial; nbtree never actually relied on the P_NEW
code paths in bufmgr.c, so this change is strictly mechanical.

GiST already took the same approach; it has a dedicated function for
allocating new pages called gistNewBuffer().  That factor allowed commit
61b313e4 to make much more targeted changes to GiST.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=8Z9qY58bjm_7TAHgtW6RzZ5Ke62q5emdCEy9BAzwhmg@mail.gmail.com

23 months agoAdd another old commit to git-blame-ignore-revs.
Peter Geoghegan [Sat, 10 Jun 2023 20:55:15 +0000 (13:55 -0700)]
Add another old commit to git-blame-ignore-revs.

23 months agoRevert "Fix search_path to a safe value during maintenance operations."
Jeff Davis [Sat, 10 Jun 2023 15:11:02 +0000 (08:11 -0700)]
Revert "Fix search_path to a safe value during maintenance operations."

This reverts commit 05e17373517114167d002494e004fa0aa32d1fd1.

23 months agomeson: Add dependencies to perl modules to various script invocations
Andres Freund [Sat, 10 Jun 2023 03:12:16 +0000 (20:12 -0700)]
meson: Add dependencies to perl modules to various script invocations

Eventually it is likely worth trying to deal with this in a more expansive
way, by generating dependency files generated within the scripts. But it's not
entirely obvious how to do that in perl and is work more suitable for 17
anyway.

Reported-by: Dagfinn Ilmari Mannsåker <[email protected]>
Reviewed-by: Tristan Partin <[email protected]>
Discussion: https://postgr.es/m/[email protected]

23 months agodoc: PG 16 relnotes, add author
Bruce Momjian [Sat, 10 Jun 2023 01:04:28 +0000 (21:04 -0400)]
doc:  PG 16 relnotes, add author

Reported-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoDP46y+1yUMikYWhCfkhSEuoXmHq2SV8_PyQoM1uWBRbg@mail.gmail.com

23 months agoFix search_path to a safe value during maintenance operations.
Jeff Davis [Fri, 9 Jun 2023 18:20:47 +0000 (11:20 -0700)]
Fix search_path to a safe value during maintenance operations.

While executing maintenance operations (ANALYZE, CLUSTER, REFRESH
MATERIALIZED VIEW, REINDEX, or VACUUM), set search_path to
'pg_catalog, pg_temp' to prevent inconsistent behavior.

Functions that are used for functional indexes, in index expressions,
or in materialized views and depend on a different search path must be
declared with CREATE FUNCTION ... SET search_path='...'.

This change addresses a security risk introduced in commit 60684dd834,
where a role with MAINTAIN privileges on a table may be able to
escalate privileges to the table owner. That commit is not yet part of
any release, so no need to backpatch.

Discussion: https://postgr.es/m/e44327179e5c9015c8dda67351c04da552066017.camel%40j-davis.com
Reviewed-by: Greg Stark
Reviewed-by: Nathan Bossart
23 months agoFix missing word in nbtree/README.
Nathan Bossart [Fri, 9 Jun 2023 04:20:24 +0000 (21:20 -0700)]
Fix missing word in nbtree/README.

Reported-by: Daniel Westermann
Author: Gurjeet Singh
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/ZR0P278MB0427F0E0CE4ED140F52D1923D250A%40ZR0P278MB0427.CHEP278.PROD.OUTLOOK.COM

23 months agoRefactor routine to find single log content pattern in TAP tests
Michael Paquier [Fri, 9 Jun 2023 02:56:27 +0000 (11:56 +0900)]
Refactor routine to find single log content pattern in TAP tests

The same routine to check if a specific pattern can be found in the
server logs was copied over four different test scripts.  This refactors
the whole to use a single routine located in PostgreSQL::Test::Cluster,
named log_contains, to grab the contents of the server logs and check
for a specific pattern.

On HEAD, the code previously used assumed that slurp_file() could not
handle an undefined offset, setting it to zero, but slurp_file() does
do an extra fseek() before retrieving the log contents only if an offset
is defined.  In two places, the test was retrieving the full log
contents with slurp_file() after calling substr() to apply an offset,
ignoring that slurp_file() would be able to handle that.

Backpatch all the way down to ease the introduction of new tests that
could rely on the new routine.

Author: Vignesh C
Reviewed-by: Andrew Dunstan, Dagfinn Ilmari Mannsåker, Michael Paquier
Discussion: https://postgr.es/m/CALDaNm0YSiLpjCmajwLfidQrFOrLNKPQir7s__PeVvh9U3uoTQ@mail.gmail.com
Backpatch-through: 11

23 months agoHonor run_as_owner option in tablesync worker.
Masahiko Sawada [Fri, 9 Jun 2023 01:43:03 +0000 (10:43 +0900)]
Honor run_as_owner option in tablesync worker.

Commit 482675987 introduced "run_as_owner" subscription option so that
subscription runs with either the permissions of the subscription
owner or the permission of the table owner. However, tablesync workers
did not use this option for the initial data copy.

With this change, tablesync workers run with appropriate permissions
based on "run_as_owner" option.

Ajin Cherian, with changes and regression tests added by me.

Reported-By: Amit Kapila
Author: Ajin Cherian, Masahiko Sawada
Reviewed-by: Ajin Cherian, Amit Kapila
Discussion: https://postgr.es/m/CAA4eK1L=qzRHPEn+qeMoKQGFBzqGoLBzt_ov0A89iFFiut+ppA@mail.gmail.com

23 months agoRefactor log check logic for connect_ok/fails in PostgreSQL::Test::Cluster
Michael Paquier [Fri, 9 Jun 2023 00:37:21 +0000 (09:37 +0900)]
Refactor log check logic for connect_ok/fails in PostgreSQL::Test::Cluster

This commit refactors a bit the code in charge of checking for log
patterns when connections fail or succeed, by moving the log pattern
checks into their own routine, for clarity.  This has come up as
something to improve while discussing the refactoring of find_in_log().

Backpatch down to 14 where these routines are used, to ease the
introduction of new tests that could rely on them.

Author: Vignesh C, Michael Paquier
Discussion: https://postgr.es/m/CALDaNm0YSiLpjCmajwLfidQrFOrLNKPQir7s__PeVvh9U3uoTQ@mail.gmail.com
Backpatch-through: 14

23 months agoFix oversight in outer join removal.
Tom Lane [Thu, 8 Jun 2023 21:10:04 +0000 (17:10 -0400)]
Fix oversight in outer join removal.

A placeholder that references the outer join's relid in ph_eval_at
is logically "above" the join, and therefore we can't remove its
PlaceHolderInfo: it might still be used somewhere in the query.

This was not an issue pre-v16 because we failed to remove the join
at all in such cases.  The new outer-join-aware-Var infrastructure
permits deducing that it's okay to remove the join, but then we
have to clean up correctly afterwards.

Report and fix by Richard Guo

Discussion: https://postgr.es/m/CAMbWs4_tuVn9EwwMcggGiZJWWstdXX_ci8FeEU17vs+4nLgw3w@mail.gmail.com

23 months agoRe-allow INDEX_VAR as rt_index in ChangeVarNodes().
Tom Lane [Thu, 8 Jun 2023 17:11:49 +0000 (13:11 -0400)]
Re-allow INDEX_VAR as rt_index in ChangeVarNodes().

Apparently some extensions are in the habit of calling
ChangeVarNodes() with INDEX_VAR as the rt_index to replace.
That worked before 2489d76c4, at least as long as there were
not PlaceHolderVars in the expression; but now it fails
because bms_is_member spits up.  Add a test to avoid that.

Per report from Anton Melnikov, though this is not his
proposed patch.

Discussion: https://postgr.es/m/5b370a46-f6d2-373d-9dbc-0d55250e82c1@inbox.ru

23 months agoFix small overestimation of base64 encoding output length.
Tom Lane [Thu, 8 Jun 2023 15:24:31 +0000 (11:24 -0400)]
Fix small overestimation of base64 encoding output length.

pg_base64_enc_len() and its clones overestimated the output
length by up to 2 bytes, as a result of sloppy thinking about
where to divide.  No callers require a precise estimate, so
this has no consequences worse than palloc'ing a byte or two
more than necessary.  We might as well get it right though.

This bug is very ancient, dating to commit 79d78bb26 which
added encode.c.  (The other instances were presumably copied
from there.)  Still, it doesn't quite seem worth back-patching.

Oleg Tselebrovskiy

Discussion: https://postgr.es/m/f94da55286a63022150bc266afdab754@postgrespro.ru

23 months agodoc: Fix example command for ALTER FOREIGN TABLE ... OPTIONS.
Fujii Masao [Thu, 8 Jun 2023 11:11:52 +0000 (20:11 +0900)]
doc: Fix example command for ALTER FOREIGN TABLE ... OPTIONS.

In the documentation, previously the example command for
ALTER FOREIGN TABLE ... OPTIONS incorrectly included both
the option name and value with the DROP operation.
The correct syntax for the DROP operation requires only
the name of the option to be specified. This commit fixes
the example by removing the option value from the DROP operation.

Back-patch to all supported versions.

Author: Mehmet Emin KARAKAS <[email protected]>
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/CANQrdXAHzbcEYhjGoe5A42OmfvdQhHFJzyKj9gJvHuDKyOF5Ng@mail.gmail.com

23 months agoDon't use _BitScanForward64/_BitScanReverse64 on 32-bit MSVC builds
David Rowley [Wed, 7 Jun 2023 22:10:34 +0000 (10:10 +1200)]
Don't use _BitScanForward64/_BitScanReverse64 on 32-bit MSVC builds

677319746 added support for making use of MSVC's bit scanning functions.
However, that commit failed to consider 32-bit MSVC builds where the
64-bit versions of these functions are unavailable.  This resulted in
compilation failures on 32-bit MSVC.

Here we adjust the code so we fall back on the manual way of finding the
bit positions for 64-bit integers when building on 32-bit MSVC.

Bug: #17967
Reported-by: Youmiu Mo
Discussion: https://postgr.es/m/17967-cd21e34a314141b2@postgresql.org

23 months agoUse per-tuple context in ExecGetAllUpdatedCols
Tomas Vondra [Wed, 7 Jun 2023 14:48:50 +0000 (16:48 +0200)]
Use per-tuple context in ExecGetAllUpdatedCols

Commit fc22b6623b (generated columns) replaced ExecGetUpdatedCols() with
ExecGetAllUpdatedCols() in a couple places handling UPDATE (triggers and
lock mode). However, ExecGetUpdatedCols() did exec_rt_fetch() while
ExecGetAllUpdatedCols() also allocates memory through bms_union()
without paying attention to the memory context and happened to use the
long-lived ExecutorState, leaking the memory until the end of the query.

The amount of leaked memory is proportional to the number of (updated)
attributes, types of UPDATE triggers, and the number of processed rows
(which for UPDATE ... FROM ... may be much higher than updated rows).

Fixed by switching to the per-tuple context in GetAllUpdatedColumns().
This is fine for all in-core callers, but external callers may need to
copy the result. But we're not aware of any such callers.

Note the issue was introduced by fc22b6623b, but the macros were later
renamed by f50e888990.

Backpatch to 12, where the issue was introduced.

Reported-by: Tomas Vondra
Reviewed-by: Andres Freund, Tom Lane, Jakub Wartak
Backpatch-through: 12
Discussion: https://postgr.es/m/222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com

23 months agodoc: Fix confusing positioning of notes in connection settings
Peter Eisentraut [Wed, 7 Jun 2023 15:54:53 +0000 (17:54 +0200)]
doc: Fix confusing positioning of notes in connection settings

Reported-by: Jonathan S. Katz <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/6f825d42-a1ce-492a-2ea7-c83e6e65fa8b%40postgresql.org

23 months agoRemove read-only server settings lc_collate and lc_ctype
Peter Eisentraut [Wed, 7 Jun 2023 14:57:06 +0000 (16:57 +0200)]
Remove read-only server settings lc_collate and lc_ctype

The GUC settings lc_collate and lc_ctype are from a time when those
locale settings were cluster-global.  When those locale settings were
made per-database (PG 8.4), the settings were kept as read-only.  As
of PG 15, you can use ICU as the per-database locale provider, so
examining these settings is already less meaningful and possibly
confusing, since you need to look into pg_database to find out what is
really happening, and they would likely become fully obsolete in the
future anyway.

Reviewed-by: Jeff Davis <[email protected]>
Discussion: https://www.postgresql.org/message-id/696054d1-bc88-b6ab-129a-18b8bce6a6f0@enterprisedb.com

23 months agoReload configuration more frequently in apply worker.
Amit Kapila [Wed, 7 Jun 2023 03:49:17 +0000 (09:19 +0530)]
Reload configuration more frequently in apply worker.

The apply worker was not reloading the configuration while processing
messages if there is a continuous flow of messages from upstream. It was
also not reloading the configuration if there is a change in the
configuration after it has waited for the message and before receiving the
new replication message. This can lead to failure in tests because we
expect that after reload, the behavior of apply worker to respect the
changed GUCs.

We found this while analyzing a rare buildfarm failure.

Author: Hou Zhijie
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/OS0PR01MB5716AF9079CC0755CD015322947E9@OS0PR01MB5716.jpnprd01.prod.outlook.com

23 months agoInitialize 'recordXtime' to silence compiler warning.
Heikki Linnakangas [Tue, 6 Jun 2023 17:30:53 +0000 (20:30 +0300)]
Initialize 'recordXtime' to silence compiler warning.

In reality, recordXtime will always be set by the getRecordTimestamp
call, but the compiler doesn't necessarily see that.

Back-patch to all supported versions.

Author: Tristan Partin
Discussion: https://www.postgresql.org/message-id/CT5MN8E11U0M.1NYNCHXYUHY41@gonk

23 months agodoc: PG 16 relnotes, fix PREPARE/EXECUTE wording
Bruce Momjian [Mon, 5 Jun 2023 18:00:37 +0000 (14:00 -0400)]
doc:  PG 16 relnotes, fix PREPARE/EXECUTE wording

Reported-by: Erik Rijkers
Discussion: https://postgr.es/m/73f361d0-237e-3413-224b-86ab6b71a3dd@xs4all.nl

23 months agoRemove obsolete comment
Peter Eisentraut [Mon, 5 Jun 2023 13:33:08 +0000 (15:33 +0200)]
Remove obsolete comment

OIDs are no longer system columns, since 578b229718.

23 months agoDoc: unify use of timestamp with time zone vs timestamptz
David Rowley [Mon, 5 Jun 2023 05:34:27 +0000 (17:34 +1200)]
Doc: unify use of timestamp with time zone vs timestamptz

For pg_stat_all_tables, last_vacuum, last_autovacuum and co all used the
full "timestamp with time zone" type name.  For consistency, make the
newly added "last_seq_scan" also use the full type name instead of
"timestamptz".

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

23 months agoDoc: explain about dependency tracking for new-style SQL functions.
Tom Lane [Sun, 4 Jun 2023 17:27:34 +0000 (13:27 -0400)]
Doc: explain about dependency tracking for new-style SQL functions.

5.14 Dependency Tracking was not updated when we added new-style
SQL functions.  Improve that.

Noted by Sami Imseih.  Back-patch to v14 where
new-style SQL functions came in.

Discussion: https://postgr.es/m/2C1933AB-C2F8-499B-9D18-4AC1882256A0@amazon.com

23 months agoFix pg_dump's failure to honor dependencies of SQL functions.
Tom Lane [Sun, 4 Jun 2023 17:05:54 +0000 (13:05 -0400)]
Fix pg_dump's failure to honor dependencies of SQL functions.

A new-style SQL function can contain a parse-time dependency
on a unique index, much as views and matviews can (such cases
arise from GROUP BY and ON CONFLICT clauses, for example).
To dump and restore such a function successfully, pg_dump must
postpone the function until after the unique index is created,
which will happen in the post-data part of the dump.  Therefore
we have to remove the normal constraint that functions are
dumped in pre-data.  Add code similar to the existing logic
that handles this for matviews.  I added test cases for both
as well, since code coverage tests showed that we weren't
testing the matview logic.

Per report from Sami Imseih.  Back-patch to v14 where
new-style SQL functions came in.

Discussion: https://postgr.es/m/2C1933AB-C2F8-499B-9D18-4AC1882256A0@amazon.com

23 months agoFix misuse of pg_log_info() for details/hints.
Tom Lane [Sun, 4 Jun 2023 15:22:05 +0000 (11:22 -0400)]
Fix misuse of pg_log_info() for details/hints.

Two places in pg_dump_sort.c were using pg_log_info() to add
more details to a message printed with pg_log_warning().
This is bad, because at default verbosity level we would
print the warning line but not the details.  One should use
pg_log_warning_detail() or pg_log_warning_hint() instead.
Commit 9a374b77f got rid of most such abuses, but unaccountably
missed these.

Noted while studying a bug report from Sami Imseih.
Back-patch to v15 where 9a374b77f came in.  (Prior versions
don't have the missing-details misbehavior, for reasons
I didn't bother to track down.)

Discussion: https://postgr.es/m/2C1933AB-C2F8-499B-9D18-4AC1882256A0@amazon.com

23 months agodoc: Add note to prevent server spoofing with SCRAM
Michael Paquier [Sat, 3 Jun 2023 21:44:09 +0000 (17:44 -0400)]
doc: Add note to prevent server spoofing with SCRAM

The set of recommendations added in the documentation with this commit
helps in avoiding SCRAM exchanges with untrusted servers.

Author: Jacob Champion, Jonathan Katz
Reviewed-by: Stephen Frost, Daniel Gustafsson, Michael Paquier
Discussion: https://postgr.es/m/CAAWbhmg5Gh0JetNbQi7z0yOsdsN9YECv8GoY-QBGBBiip9+JOw@mail.gmail.com

23 months agodoc: PG 16 relnotes, add psql \df+ source code change
Bruce Momjian [Thu, 1 Jun 2023 23:59:46 +0000 (19:59 -0400)]
doc:  PG 16 relnotes, add psql \df+ source code change

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

23 months agodoc: add missing "the" in LATERAL sentence.
Bruce Momjian [Thu, 1 Jun 2023 14:22:16 +0000 (10:22 -0400)]
doc:  add missing "the" in LATERAL sentence.

Backpatch-through: 11

23 months agodoc: PG 16 relnotes, move memory item and reword OUTER item
Bruce Momjian [Wed, 31 May 2023 11:01:21 +0000 (07:01 -0400)]
doc:  PG 16 relnotes, move memory item and reword OUTER item

Reported-by: David Rowley
Discussion: https://postgr.es/m/CAApHDvqmqxcX2n9NwvsfnsN0be6DjmyLSjz3Jk2DaZO5OLW+pw@mail.gmail.com

23 months agodoc: PG 16 relnotes, add memory overhead reduction item
Bruce Momjian [Tue, 30 May 2023 23:32:15 +0000 (19:32 -0400)]
doc:  PG 16 relnotes, add memory overhead reduction item

Reported-by: David Rowley
Discussion: https://postgr.es/m/CAApHDvqnUoyrJxS4uqnKo87b3_cUjaDDte4NQag49YHu1oEOgA@mail.gmail.com

23 months agodoc: PG 16 relnotes, adjust subscription origin mention
Bruce Momjian [Tue, 30 May 2023 23:08:14 +0000 (19:08 -0400)]
doc:  PG 16 relnotes, adjust subscription origin mention

Reported-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoC+VihMWs3-xVB3Z=8LzLbsQc52TO29o25rzfqcnJDCUQ@mail.gmail.com

23 months agodoc: PG 16 relnotes, adjust auto_explain logging item
Bruce Momjian [Tue, 30 May 2023 10:04:09 +0000 (06:04 -0400)]
doc:  PG 16 relnotes, adjust auto_explain logging item

Reported-by: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/[email protected]

23 months agodoc: Add missing backend_type to pg_stat_activity
Daniel Gustafsson [Tue, 30 May 2023 08:31:11 +0000 (10:31 +0200)]
doc: Add missing backend_type to pg_stat_activity

Commit 0c679464a8 added the missing backendDesc for B_STANDALONE_BACKEND
but missed updating the list of backend types in the documentation.  Fix
by adding it to the list.

Author: Noriyoshi Shinoda <[email protected]>
Discussion: https://postgr.es/m/DM4PR84MB1734ECEA02BCB59564E8FC03EE4A9@DM4PR84MB1734.NAMPRD84.PROD.OUTLOOK.COM

23 months agodoc: PG 16 relnotes: adjust outer/full hash join parallelization
Bruce Momjian [Mon, 29 May 2023 18:36:27 +0000 (14:36 -0400)]
doc: PG 16 relnotes: adjust outer/full hash join parallelization

Reported-by: David Rowley
Discussion: https://postgr.es/m/CAApHDvph4djrP+zjOK67VcgbB_p9Zn8QoO7Qctt4oQgUC_ejEw@mail.gmail.com

23 months agodoc: PG 16 relnotes, fix duplicate author and commit
Bruce Momjian [Mon, 29 May 2023 17:49:05 +0000 (13:49 -0400)]
doc:  PG 16 relnotes, fix duplicate author and commit

Reported-by: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoALE_joh=H-j5sdaAfDs=BXtCy6BQKYZBTi=neU8k0VFw@mail.gmail.com

23 months agodoc: PG 16 relnotes, fix "locale" typo and windows locale text
Bruce Momjian [Sun, 28 May 2023 03:04:48 +0000 (23:04 -0400)]
doc:  PG 16 relnotes, fix "locale" typo and windows locale text

Reported-by: Laurenz Albe, Álvaro Herrera
Discussion: https://postgr.es/m/70a09a9fa557b632f4b1505395aaa6c4cb77b55a[email protected]

23 months agoICU: use uloc_getDefault() for initdb.
Jeff Davis [Fri, 26 May 2023 18:26:11 +0000 (11:26 -0700)]
ICU: use uloc_getDefault() for initdb.

Simpler, and better preserves the locale name as read from the
environment.

Author: Daniel Verite
Discussion: https://postgr.es/m/a6204a46-c077-451b-8f9d-8965d95bb57c@manitou-mail.org

23 months agoFix joinclause removal logic to cope with cloned clauses.
Tom Lane [Fri, 26 May 2023 16:13:19 +0000 (12:13 -0400)]
Fix joinclause removal logic to cope with cloned clauses.

When we're deleting a no-op LEFT JOIN from the query, we must remove
the join's joinclauses from surviving relations' joininfo lists.
The invention of "cloned" clauses in 2489d76c4 broke the logic for
that; it'd fail to remove clones that include OJ relids outside the
doomed join's min relid sets, which could happen if that join was
previously discovered to commute with some other join.

This accidentally failed to cause problems in the majority of cases,
because we'd never decide that such a cloned clause was evaluatable at
any surviving join.  However, Richard Guo discovered a case where that
did happen, leading to "no relation entry for relid" errors later.
Also, adding assertions that a non-removed clause contains no Vars from
the doomed join exposes that there are quite a few existing regression
test cases where the problem happens but is accidentally not exposed.

The fix for this is just to include the target join's commute_above_r
and commute_below_l sets in the relid set we test against when
deciding whether a join clause is "pushed down" and thus not
removable.

While at it, do a little refactoring: the join's relid set can be
computed inside remove_rel_from_query rather than in the caller.

Patch by me; thanks to Richard Guo for review.

Discussion: https://postgr.es/m/CAMbWs4_PHrRqTKDNnTRsxxQy6BtYCVKsgXm1_gdN2yQ=kmcO5g@mail.gmail.com

23 months agoDoc fixes for commit 1e16af8ab5.
Jeff Davis [Fri, 26 May 2023 00:05:50 +0000 (17:05 -0700)]
Doc fixes for commit 1e16af8ab5.

Discussion: https://postgr.es/m/275c47ea-e7f3-e654-c99a-63bc116997d7@enterprisedb.com

23 months agonbtree VACUUM: cope with right sibling link corruption.
Peter Geoghegan [Thu, 25 May 2023 22:33:00 +0000 (15:33 -0700)]
nbtree VACUUM: cope with right sibling link corruption.

Avoid "right sibling's left-link doesn't match" 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 error was seen in the field from time to time (it's more than a
theoretical risk), so giving VACUUM the ability to press on like this
has real value.  Nothing short of a REINDEX is expected to fix the
underlying index corruption, so giving up (by throwing an error) risks
making a bad situation far worse.  Anything that blocks forward progress
by VACUUM like this might go unnoticed for a long time.  This could
eventually lead to a wraparound/xidStopLimit outage.

Note that _bt_unlink_halfdead_page() has always been able to bail on
page deletion when the target page's left sibling page was in an
inconsistent state.  It now does the same thing (returns false to back
out of the second phase of deletion) when it notices sibling link
corruption in the target page's right sibling page.

This is similar to the work from commit 5b861baa (later backpatched as
commit 43e409ce), which taught nbtree to press on with vacuuming an
index when page deletion fails to "re-find" a downlink in the target
page's parent page.  The "re-find" check seems to make VACUUM bail on
page deletion more often in practice, but there is no reason to take any
chances here.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Heikki Linnakangas <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzko2q2kP1+UvgJyP9g0mF4hopK0NtQZcxwvMv9_ytGhkQ@mail.gmail.com
Backpatch: 11- (all supported versions).

23 months agoFix filtering of "cloned" outer-join quals some more.
Tom Lane [Thu, 25 May 2023 14:28:33 +0000 (10:28 -0400)]
Fix filtering of "cloned" outer-join quals some more.

We've had multiple issues with the clause_is_computable_at logic that
I introduced in 2489d76c4: it's been known to accept more than one
clone of the same qual at the same plan node, and also to accept no
clones at all.  It's looking impractical to get it 100% right on the
basis of the currently-stored information, so fix it by introducing a
new RestrictInfo field "incompatible_relids" that explicitly shows
which outer joins a given clone mustn't be pushed above.

In principle we could populate this field in every RestrictInfo, but
that would cost space and there doesn't presently seem to be a need
for it in general.  Also, while deconstruct_distribute_oj_quals can
easily fill the field with the remaining members of the commutative
join set that it's considering, computing it in the general case
seems again pretty complicated.  So for now, just fill it for
clone quals.

Along the way, fix a bug that may or may not be only latent:
equivclass.c was generating replacement clauses with is_pushed_down
and has_clone/is_clone markings that didn't match their
required_relids.  This led me to conclude that leaving the clone flags
out of make_restrictinfo's purview wasn't such a great idea after all,
so add them.

Per report from Richard Guo.

Discussion: https://postgr.es/m/CAMbWs48EYi_9-pSd0ORes1kTmTeAjT4Q3gu49hJtYCbSn2JyeA@mail.gmail.com

23 months agodoc: fix typo in language tag documentation
Daniel Gustafsson [Thu, 25 May 2023 10:49:26 +0000 (12:49 +0200)]
doc: fix typo in language tag documentation

Commit 1e16af8ab5 accidentally mistyped 'language' in one place.

23 months agodoc: Fix example query for pg_walinspect
Daniel Gustafsson [Thu, 25 May 2023 10:43:16 +0000 (12:43 +0200)]
doc: Fix example query for pg_walinspect

The LIMIT clause had ended up in the wrong place in the query.
Backpatch to v15 where pg_walinspect was introduced.

Reported-by: Jian He <[email protected]>
Discussion: https://postgr.es/m/CACJufxHqXDr4NnmwmR6pEiVPAg54J0dgwMuYQzrH5BX6+NtF1g@mail.gmail.com
Backpatch-through: 15

23 months agoFix pgbench in prepared mode with an empty pipeline
Alvaro Herrera [Thu, 25 May 2023 10:36:18 +0000 (12:36 +0200)]
Fix pgbench in prepared mode with an empty pipeline

It crashes because it references memory that's not allocated in that
particular case.  Fix by allocating it.

Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/bcf802a6-afc1-95b9-7bf4-c5dd868ec144@gmail.com

23 months agoFix typo in TAP tests of vacuumdb
Michael Paquier [Thu, 25 May 2023 07:26:08 +0000 (16:26 +0900)]
Fix typo in TAP tests of vacuumdb

Noticed while scanning the area, introduced in 582edc3.

23 months agodoc: PG 16 relnotes, add author from previous merge
Bruce Momjian [Thu, 25 May 2023 02:03:40 +0000 (22:03 -0400)]
doc: PG 16 relnotes, add author from previous merge

Reported-by: John Naylor
Discussion: https://postgr.es/m/CAFBsxsEMoNdg6CCMuQ-6YJ8G=AgGNMVuiTb5Di5bsoPfBb=9CA@mail.gmail.com

23 months agodoc: PG 16 relnotes, wording adjustments
Bruce Momjian [Wed, 24 May 2023 16:18:43 +0000 (12:18 -0400)]
doc:  PG 16 relnotes, wording adjustments

Reported-by: Erik Rijkers
Discussion: https://postgr.es/m/c4a88acf-ab1a-a912-d4a9-5e19b323c5ed@xs4all.nl

23 months agodoc: PG 16 relnotes, merge and move vector items
Bruce Momjian [Wed, 24 May 2023 13:54:34 +0000 (09:54 -0400)]
doc: PG 16 relnotes, merge and move vector items

Reported-by: John Naylor
Discussion: https://postgr.es/m/CAFBsxsEPg8L2MmGqavc8JByC=WF_Mnkhn-KKnFPkcqh0hydung@mail.gmail.com

23 months agodoc: PG 16 relnotes, update xid/subxid searches item
Bruce Momjian [Wed, 24 May 2023 04:09:13 +0000 (00:09 -0400)]
doc: PG 16 relnotes, update xid/subxid searches item

Reported-by: John Naylor
Discussion: https://postgr.es/m/CAFBsxsEPg8L2MmGqavc8JByC=WF_Mnkhn-KKnFPkcqh0hydung@mail.gmail.com

23 months agoDocument deprecated createuser option.
Nathan Bossart [Wed, 24 May 2023 02:34:09 +0000 (19:34 -0700)]
Document deprecated createuser option.

2dcd1578c4 left the --role option undocumented, which is
inconsistent with other deprecated options such as pg_dump's
--blobs and --no-blobs.  This change adds --role back to
createuser's documentation and usage output and marks it as
deprecated.

Suggested-by: Peter Eisentraut
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/0e85c9e7-4804-1cdb-5a4a-c72c328f9ad8%40enterprisedb.com

23 months agoDoc: update src/tools/pginclude/README.
Tom Lane [Tue, 23 May 2023 22:51:43 +0000 (18:51 -0400)]
Doc: update src/tools/pginclude/README.

Commit f62975b2a made headerscheck and cpluspluscheck a little
smarter than this documentation gave them credit for.  Make
their docs match current reality.  Also add a warning about the
layer of dust that has settled on the rest of these scripts.

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

23 months agoFix the install rule for snowball_create.sql.
Tom Lane [Tue, 23 May 2023 15:15:57 +0000 (11:15 -0400)]
Fix the install rule for snowball_create.sql.

This file could be in the current (build) directory if we just
built it.  However, when installing from a VPATH build from a
tarball, it will exist in the source directory and gmake will
therefore not rebuild it.  Use the $< macro to find out where
gmake found it.

Oversight in b3a0d8324, which also exposes a buildfarm testing gap:
we test install from VPATH builds from bare source trees, but not
from tarballs.

Per report from Christoph Berg.

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

23 months agoUse lower case for icu_validation_level values
Peter Eisentraut [Tue, 23 May 2023 13:19:33 +0000 (15:19 +0200)]
Use lower case for icu_validation_level values

Similar to client_min_messages etc.

23 months agoPunctuation improvement in postgresql.conf.sample
Peter Eisentraut [Tue, 23 May 2023 13:19:12 +0000 (15:19 +0200)]
Punctuation improvement in postgresql.conf.sample

23 months agoAdd newline at end of file
Peter Eisentraut [Tue, 23 May 2023 13:18:06 +0000 (15:18 +0200)]
Add newline at end of file

2 years agodoc: PG 16 relnotes, SIMD improvements
Bruce Momjian [Tue, 23 May 2023 04:27:01 +0000 (00:27 -0400)]
doc:  PG 16 relnotes, SIMD improvements

Reported-by: John Naylor
Discussion: https://postgr.es/m/CAFBsxsEuAx4_nq=200u=70S5r83C2hzO-a9+c6YXTCbOFeDAfw@mail.gmail.com

2 years agoStamp 16beta1. REL_16_BETA1
Tom Lane [Mon, 22 May 2023 21:08:08 +0000 (17:08 -0400)]
Stamp 16beta1.

2 years agodoc: PG 16 relnotes, add major features list
Bruce Momjian [Mon, 22 May 2023 17:58:24 +0000 (13:58 -0400)]
doc: PG 16 relnotes, add major features list

Reported-by: Jonathan Katz
Discussion: https://postgr.es/m/2fd2cc0e-df39-3e77-8fcf-35aad5796b0a@postgresql.org

2 years agoSpell the values of libpq's gssdelegation parameter as "0" and "1".
Tom Lane [Mon, 22 May 2023 15:50:20 +0000 (11:50 -0400)]
Spell the values of libpq's gssdelegation parameter as "0" and "1".

That's how other boolean options are handled, so do likewise.
The previous coding with "enable" and "disable" was seemingly
modeled on gssencmode, but that's a three-way flag.

While at it, add PGGSSDELEGATION to the set of environment
variables cleared by pg_regress and Utils.pm.

Abhijit Menon-Sen, per gripe from Alvaro Herrera

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

2 years agodoc: PG 16 relnotes, improve desc. of pg_log_standby_snapshot()
Bruce Momjian [Mon, 22 May 2023 14:20:53 +0000 (10:20 -0400)]
doc:  PG 16 relnotes, improve desc. of pg_log_standby_snapshot()

2 years agoTranslation updates
Peter Eisentraut [Mon, 22 May 2023 10:44:31 +0000 (12:44 +0200)]
Translation updates

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

2 years agopg_dump doc: mention 'long' is valid for --compress
Alvaro Herrera [Mon, 22 May 2023 10:26:40 +0000 (12:26 +0200)]
pg_dump doc: mention 'long' is valid for --compress

Apparently an oversight in 2820adf7755d.

2 years agodoc: PG 16 relnotes, improve description of standby log. decode
Bruce Momjian [Mon, 22 May 2023 03:39:27 +0000 (23:39 -0400)]
doc:  PG 16 relnotes, improve description of standby log. decode

Improve description of "Allow logical decoding on standbys".

2 years agoRename some createuser options.
Nathan Bossart [Mon, 22 May 2023 03:03:56 +0000 (20:03 -0700)]
Rename some createuser options.

This change renames --admin to --with-admin, --role to --member-of,
and --member to --with-member.  Many people found the previous
names to be confusing.  The --admin and --member options are new in
v16, but --role has been there for a while, so that one has been
kept (but left undocumented) for backward compatibility.

Suggested-by: Peter Eisentraut
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/ZFvVZvQDliIWmOwg%40momjian.us

2 years agodoc: PG 16 relnotes, misc merged items and bootstrap detail
Bruce Momjian [Mon, 22 May 2023 02:52:42 +0000 (22:52 -0400)]
doc: PG 16 relnotes, misc merged items and bootstrap detail

Reported-by: Andres Freund, jian he
Discussion: https://postgr.es/m/20230521171341[email protected]20230521171341[email protected]

2 years agodoc: PG 16 relnotes, misc. updates
Bruce Momjian [Sun, 21 May 2023 19:57:37 +0000 (15:57 -0400)]
doc:  PG 16 relnotes, misc. updates

Reported-by: Tom Lane
Discussion: https://postgr.es/m/277016.1684689065@sss.pgh.pa.us

2 years agoIn clause_is_computable_at(), test required_relids for clone clauses.
Tom Lane [Sun, 21 May 2023 19:25:43 +0000 (15:25 -0400)]
In clause_is_computable_at(), test required_relids for clone clauses.

Use the clause's required_relids not clause_relids for testing
whether it is computable at the current join level, if it is a
clone clause generated by deconstruct_distribute_oj_quals().

Arguably, this is more correct and we should do it for all clauses;
that would at least remove the handwavy claim that we are doing
it to save cycles compared to inspecting Vars individually.
However, attempting to do that exposes that we are not being careful
to compute an accurate value for required_relids in all cases.
I'm unsure whether it's a good idea to attempt to do that for v16,
or leave it as future clean-up.  In the meantime, this quick hack
demonstrably fixes some cases, so let's squeeze it in for beta1.

Patch by me, but great thanks to Richard Guo for investigation
and testing.  The new test cases are all modeled on his examples.

Discussion: https://postgr.es/m/CAMbWs4-_vwkBij4XOQ5ukxUvLgwTm0kS5_DO9CicUeKbEfKjUw@mail.gmail.com

2 years agoRemove over-eager assertion in ExtendBufferedRelTo()
Andres Freund [Sun, 21 May 2023 16:48:37 +0000 (09:48 -0700)]
Remove over-eager assertion in ExtendBufferedRelTo()

The assertion checked that the size of the relation is not "too large" - but
the code is explicitly dealing with the possibility of another backend
extending the relation concurrently. In that case the new relation size could
be bigger than what the current backend needs, wrongly triggering an assertion
failure.

Unfortunately it is hard to write a reliable and affordable regression tests
for this, as a lot of concurrency is needed to encounter the bug.

Introduced in 31966b151e6a.

Reported-by: Melanie Plageman <[email protected]>