postgresql.git
9 months agoOptimise numeric multiplication for short inputs.
Dean Rasheed [Tue, 9 Jul 2024 09:00:42 +0000 (10:00 +0100)]
Optimise numeric multiplication for short inputs.

When either input has a small number of digits, and the exact product
is requested, the speed of numeric multiplication can be increased
significantly by using a faster direct multiplication algorithm. This
works by fully computing each result digit in turn, starting with the
least significant, and propagating the carry up. This save cycles by
not requiring a temporary buffer to store digit products, not making
multiple passes over the digits of the longer input, and not requiring
separate carry-propagation passes.

For now, this is used when the shorter input has 1-4 NBASE digits (up
to 13-16 decimal digits), and the longer input is of any size, which
covers a lot of common real-world cases. Also, the relative benefit
increases as the size of the longer input increases.

Possible future work would be to try extending the technique to larger
numbers of digits in the shorter input.

Joel Jacobson and Dean Rasheed.

Discussion: https://postgr.es/m/44d2ffca-d560-4919-b85a-4d07060946aa@app.fastmail.com

9 months agoSQL/JSON: Various improvements to SQL/JSON query function docs
Amit Langote [Tue, 9 Jul 2024 07:12:22 +0000 (16:12 +0900)]
SQL/JSON: Various improvements to SQL/JSON query function docs

1. Remove the keyword SELECT from the examples to be consistent
with the examples of other JSON-related functions listed on the
same page.

2. Add <synopsis> tags around the functions' syntax definition

3. Capitalize function names in the syntax synopsis and the examples

4. Use <itemizedlist> lists for dividing the descriptions of
   individual functions into bullet points

5. Significantly rewrite the description of wrapper clauses of
   JSON_QUERY

6. Significantly rewrite the descriptions of ON ERROR / EMPTY
   clauses of JSON_QUERY() and JSON_VALUE() functions

7. Add a note about how JSON_VALUE() and JSON_QUERY() differ when
   returning a JSON null result

8. Move the description of the PASSING clause from the descriptions
   of individual functions into the top paragraph

And other miscellaneous text improvements, typo fixes.

Suggested-by: Thom Brown <[email protected]>
Suggested-by: David G. Johnston <[email protected]>
Reviewed-by: Jian He <[email protected]>
Reviewed-by: Erik Rijkers <[email protected]>
Discussion: https://postgr.es/m/CAA-aLv7Dfy9BMrhUZ1skcg=OdqysWKzObS7XiDXdotJNF0E44Q@mail.gmail.com
Discussion: https://postgr.es/m/CAKFQuwZNxNHuPk44zDF7z8qZec1Aof10aA9tWvBU5CMhEKEd8A@mail.gmail.com

9 months agoTo improve the code, move the error check in logical_read_xlog_page().
Amit Kapila [Tue, 9 Jul 2024 03:30:45 +0000 (09:00 +0530)]
To improve the code, move the error check in logical_read_xlog_page().

Commit 0fdab27ad6 changed the code to wait for WAL to be available before
determining the timeline but forgot to move the failure check.

This change is to make the related code easier to understand and enhance
otherwise there is no bug in the current code.

In the passing, improve the nearby comments to explain why we determine
am_cascading_walsender after waiting for the required WAL.

Author: Peter Smith
Reviewed-by: Bertrand Drouvot, Amit Kapila
Discussion: https://postgr.es/m/CAHut+PvqX49fusLyXspV1Mmd_EekPtXG0oT146vZjcb9XDvNgw@mail.gmail.com

9 months agoUse pgstat_kind_infos to write fixed shared statistics
Michael Paquier [Tue, 9 Jul 2024 01:27:12 +0000 (10:27 +0900)]
Use pgstat_kind_infos to write fixed shared statistics

This is similar to 9004abf6206e, but this time for the write part of the
stats file.  The code is changed so as, rather than referring to
individual members of PgStat_Snapshot in an order based on their
PgStat_Kind value, a loop based on pgstat_kind_infos is used to retrieve
the contents to write from the snapshot structure, for a size of
PgStat_KindInfo's shared_data_len.

This requires the addition to PgStat_KindInfo of an offset to track the
location of each fixed-numbered stats in PgStat_Snapshot.  This change
is useful to make this area of the code more easily pluggable, and
reduces the knowledge of specific fixed-numbered kinds in pgstat.c.

Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/[email protected]

9 months agoAvoid JIT-related test instability in EXPLAIN ANALYZE
David Rowley [Tue, 9 Jul 2024 00:46:48 +0000 (12:46 +1200)]
Avoid JIT-related test instability in EXPLAIN ANALYZE

036bdcec9 added some code to perform some verification on portions of
the planner costs in EXPLAIN ANALYZE but failed to consider that some
buildfarm animals such as bushmaster and taipan are running very low jit
thresholds.  This caused these animals to fail as they were outputting
JIT-related details in EXPLAIN ANALYZE for the newly added tests.

Here we avoid that by disabling JIT for the plans in question.

Discussion: https://postgr.es/m/CAApHDvpxV4rrO3XUCgGS5N9Wg6f2r0ojJPD2tX2FRV-o9sRTJA@mail.gmail.com

9 months agoFix limit block handling in pg_wal_summary_contents().
Fujii Masao [Tue, 9 Jul 2024 00:26:54 +0000 (09:26 +0900)]
Fix limit block handling in pg_wal_summary_contents().

Previously, pg_wal_summary_contents() had two issues,
causing discrepancies between pg_wal_summary_contents()
and the pg_walsummary command on the same WAL summary file:

(1) It did not emit the limit block when that's the only data for
     a particular relation fork.
(2) It emitted the same limit block multiple times if the list of
     block numbers was long enough.

This commit fixes these issues.

Backpatch to v17 where pg_wal_summary_contents() was added.

Author: Fujii Masao
Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/90980ee6-2da6-42f6-a7b0-b7bae62ae279@oss.nttdata.com

9 months agoShow Parallel Bitmap Heap Scan worker stats in EXPLAIN ANALYZE
David Rowley [Tue, 9 Jul 2024 00:15:47 +0000 (12:15 +1200)]
Show Parallel Bitmap Heap Scan worker stats in EXPLAIN ANALYZE

Nodes like Memoize report the cache stats for each parallel worker, so it
makes sense to show the exact and lossy pages in Parallel Bitmap Heap Scan
in a similar way.  Likewise, Sort shows the method and memory used for
each worker.

There was some discussion on whether the leader stats should include the
totals for each parallel worker or not.  I did some analysis on this to
see what other parallel node types do and it seems only Parallel Hash does
anything like this.  All the rest, per what's supported by
ExecParallelRetrieveInstrumentation() are consistent with each other.

Author: David Geier <[email protected]>
Author: Heikki Linnakangas <[email protected]>
Author: Donghang Lin <[email protected]>
Author: Alena Rybakina <[email protected]>
Author: David Rowley <[email protected]>
Reviewed-by: Dmitry Dolgov <[email protected]>
Reviewed-by: Michael Christofides <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Reviewed-by: Dilip Kumar <[email protected]>
Reviewed-by: Tomas Vondra <[email protected]>
Reviewed-by: Melanie Plageman <[email protected]>
Reviewed-by: Donghang Lin <[email protected]>
Reviewed-by: Masahiro Ikeda <[email protected]>
Discussion: https://postgr.es/m/b3d80961-c2e5-38cc-6a32-61886cdf766d%40gmail.com

9 months agoPerform forgotten cat version bump
David Rowley [Mon, 8 Jul 2024 21:56:46 +0000 (09:56 +1200)]
Perform forgotten cat version bump

I missed this in 036bdcec9

9 months agoTeach planner how to estimate rows for timestamp generate_series
David Rowley [Mon, 8 Jul 2024 21:54:59 +0000 (09:54 +1200)]
Teach planner how to estimate rows for timestamp generate_series

This provides the planner with row estimates for
generate_series(TIMESTAMP, TIMESTAMP, INTERVAL),
generate_series(TIMESTAMPTZ, TIMESTAMPTZ, INTERVAL) and
generate_series(TIMESTAMPTZ, TIMESTAMPTZ, INTERVAL, TEXT) when the input
parameter values can be estimated during planning.

Author: David Rowley
Reviewed-by: jian he <[email protected]>
Discussion: https://postgr.es/m/CAApHDvrBE%3D%2BASo_sGYmQJ3GvO8GPvX5yxXhRS%3Dt_ybd4odFkhQ%40mail.gmail.com

9 months agoSymlink pg_replslot robustly on Windows in pg_basebackup test
Andrew Dunstan [Mon, 8 Jul 2024 17:46:21 +0000 (13:46 -0400)]
Symlink pg_replslot robustly on Windows in pg_basebackup test

This reverts commit e9f15bc9. Instead of a hacky solution that didn't
work on Windows, we avoid trying to move the directory possibly across
drives, and instead remove it and recreate it in the new location.

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

Backpatch to release 14 like the previous patch.

9 months agoUse CREATE DATABASE ... STRATEGY = FILE_COPY in pg_upgrade.
Nathan Bossart [Mon, 8 Jul 2024 21:18:00 +0000 (16:18 -0500)]
Use CREATE DATABASE ... STRATEGY = FILE_COPY in pg_upgrade.

While this strategy is ordinarily quite costly because it requires
performing two checkpoints, testing shows that it tends to be a
faster choice than WAL_LOG during pg_upgrade, presumably because
fsync is turned off.  Furthermore, we can skip the checkpoints
altogether because the problems they are intended to prevent don't
apply to pg_upgrade.  Instead, we just need to CHECKPOINT once in
the new cluster after making any changes to template0 and before
restoring the rest of the databases.  This ensures that said
template0 changes are written out to disk prior to creating the
databases via FILE_COPY.

Co-authored-by: Matthias van de Meent
Reviewed-by: Ranier Vilela, Dilip Kumar, Robert Haas, Michael Paquier
Discussion: https://postgr.es/m/Zl9ta3FtgdjizkJ5%40nathan

9 months agoChoose ports for test servers less likely to result in conflicts
Andrew Dunstan [Mon, 8 Jul 2024 15:18:06 +0000 (11:18 -0400)]
Choose ports for test servers less likely to result in conflicts

If we choose ports in the range typically used for ephemeral ports there
is a danger of encountering a port conflict due to a race condition
between the time we choose the port in a range below that typically used
to allocate ephemeral ports, but higher than the range typically used by
well known services.

Author: Jelte Fenema-Nio, with some editing by me.

Discussion: https://postgr.es/m/d6ee8761-39d1-0033-1afb-d5a57ee056f2@gmail.com

Backpatch to all live branches (12 and up)

9 months agoForce nodes for SSL tests to start in TCP mode
Andrew Dunstan [Mon, 8 Jul 2024 09:51:26 +0000 (05:51 -0400)]
Force nodes for SSL tests to start in TCP mode

Currently they are started in unix socket mode in ost cases, and then
converted to run in TCP mode. This can result in port collisions, and
there is no virtue in startng in unix socket mode, so start as we will
be going on.

Discussion: https://postgr.es/m/d6ee8761-39d1-0033-1afb-d5a57ee056f2@gmail.com

Backpatch to all live branches (12 and up).

9 months agoUse xmlParseInNodeContext not xmlParseBalancedChunkMemory.
Tom Lane [Mon, 8 Jul 2024 18:04:00 +0000 (14:04 -0400)]
Use xmlParseInNodeContext not xmlParseBalancedChunkMemory.

xmlParseInNodeContext has basically the same functionality with
a different API: we have to supply an xmlNode that's attached to a
document rather than just the document.  That's not hard though.
The benefits are two:

* Early 2.13.x releases of libxml2 contain a bug that causes
xmlParseBalancedChunkMemory to return the wrong status value in some
cases.  This breaks our regression tests.  While that bug is now fixed
upstream and will probably never be seen in any production-oriented
distro, it is currently a problem on some more-bleeding-edge-friendly
platforms.

* xmlParseBalancedChunkMemory is considered to depend on libxml2's
semi-deprecated SAX1 APIs, and will go away when and if they do.
There may already be libxml2 builds out there that lack this function.

So there are both short- and long-term reasons to make this change.

While here, avoid allocating an xmlParserCtxt in DOCUMENT parse mode,
since that code path is not going to use it.

Like 066e8ac6e, this will need to be back-patched.  This is just a
trial commit to see if the buildfarm agrees that we can use
xmlParseInNodeContext unconditionally.

Erik Wienhold and Tom Lane, per report from Frank Streitzig.

Discussion: https://postgr.es/m/trinity-b0161630-d230-4598-9ebc-7a23acdb37cb-1720186432160@3c-app-gmx-bap25
Discussion: https://postgr.es/m/trinity-361ba18b-541a-4fe7-bc63-655ae3a7d599-1720259822452@3c-app-gmx-bs01

9 months agoFix scale clamping in numeric round() and trunc().
Dean Rasheed [Mon, 8 Jul 2024 16:48:45 +0000 (17:48 +0100)]
Fix scale clamping in numeric round() and trunc().

The numeric round() and trunc() functions clamp the scale argument to
the range between +/- NUMERIC_MAX_RESULT_SCALE (2000), which is much
smaller than the actual allowed range of type numeric. As a result,
they return incorrect results when asked to round/truncate more than
2000 digits before or after the decimal point.

Fix by using the correct upper and lower scale limits based on the
actual allowed (and documented) range of type numeric.

While at it, use the new NUMERIC_WEIGHT_MAX constant instead of
SHRT_MAX in all other overflow checks, and fix a comment thinko in
power_var() introduced by e54a758d24 -- the minimum value of
ln_dweight is -NUMERIC_DSCALE_MAX (-16383), not -SHRT_MAX, though this
doesn't affect the point being made in the comment, that the resulting
local_rscale value may exceed NUMERIC_MAX_DISPLAY_SCALE (1000).

Back-patch to all supported branches.

Dean Rasheed, reviewed by Joel Jacobson.

Discussion: https://postgr.es/m/CAEZATCXB%2BrDTuMjhK5ZxcouufigSc-X4tGJCBTMpZ3n%3DxxQuhg%40mail.gmail.com

9 months agoTypo fix
Amit Langote [Mon, 8 Jul 2024 13:12:55 +0000 (22:12 +0900)]
Typo fix

Reported-by: Junwang Zhao <[email protected]>
Discussion: https://postgr.es/m/CAEG8a3KPi=LayiTwJ11ikF7bcqnZUrcj8NgX0V8nO1mQKZ9GfQ@mail.gmail.com
Backpatch-through: 17

9 months agoFix outdated comment after removal of direct SSL fallback
Heikki Linnakangas [Mon, 8 Jul 2024 09:44:45 +0000 (12:44 +0300)]
Fix outdated comment after removal of direct SSL fallback

The option to fall back from direct SSL to negotiated SSL or a
plaintext connection was removed in commit fb5718f35f.

Discussion: https://www.postgresql.org/message-id/c82ad227-e049-4e18-8898-475a748b5a5a@iki.fi

9 months agoRenumber pg_get_acl() in pg_proc.dat
Michael Paquier [Mon, 8 Jul 2024 06:34:33 +0000 (15:34 +0900)]
Renumber pg_get_acl() in pg_proc.dat

a6417078c414 has introduced as project policy that new features
committed during the development cycle should use new OIDs in the
[8000,9999] range.

4564f1cebd43 did not respect that rule, so let's renumber pg_get_acl()
to use an OID in the correct range.

Bump catalog version.

9 months agoWiden lossy and exact page counters for Bitmap Heap Scan
David Rowley [Mon, 8 Jul 2024 02:43:09 +0000 (14:43 +1200)]
Widen lossy and exact page counters for Bitmap Heap Scan

Both of these counters were using the "long" data type.  On MSVC that's
a 32-bit type.  On modern hardware, I was able to demonstrate that we can
wrap those counters with a query that only takes 15 minutes to run.

This issue may manifest itself either by not showing the values of the
counters because they've wrapped and are less than zero, resulting in
them being filtered by the > 0 checks in show_tidbitmap_info(), or bogus
numbers being displayed which are modulus 2^32 of the actual number.

Widen these counters to uint64.

Discussion: https://postgr.es/m/CAApHDvpS_97TU+jWPc=T83WPp7vJa1dTw3mojEtAVEZOWh9bjQ@mail.gmail.com

9 months agoRemove an extra period in code comment
Richard Guo [Mon, 8 Jul 2024 02:17:22 +0000 (11:17 +0900)]
Remove an extra period in code comment

Author: Junwang Zhao
Discussion: https://postgr.es/m/CAEG8a3L9GgfKc+XT+NMHPY7atAOVYqjUqKEFQKhcPHFYRW=PuQ@mail.gmail.com

9 months agoFix right-anti-joins when the inner relation is proven unique
Richard Guo [Mon, 8 Jul 2024 01:11:46 +0000 (10:11 +0900)]
Fix right-anti-joins when the inner relation is proven unique

For an inner_unique join, we always assume that the executor will stop
scanning for matches after the first match.  Therefore, for a mergejoin
that is inner_unique and whose mergeclauses are sufficient to identify a
match, we set the skip_mark_restore flag to true, indicating that the
executor need not do mark/restore calls.  However, merge-right-anti-join
did not get this memo and continues scanning the inner side for matches
after the first match.  If there are duplicates in the outer scan, we
may incorrectly skip matching some inner tuples, which can lead to wrong
results.

Here we fix this issue by ensuring that merge-right-anti-join also
advances to next outer tuple after the first match in inner_unique
cases.  This also saves cycles by avoiding unnecessary scanning of inner
tuples after the first match.

Although hash-right-anti-join does not suffer from this wrong results
issue, we apply the same change to it as well, to help save cycles for
the same reason.

Per bug #18522 from Antti Lampinen, and bug #18526 from Feliphe Pozzer.
Back-patch to v16 where right-anti-join was introduced.

Author: Richard Guo
Discussion: https://postgr.es/m/18522-c7a8956126afdfd0@postgresql.org

9 months agoRe-enable autoruns for cmd.exe on Windows
Michael Paquier [Mon, 8 Jul 2024 00:43:59 +0000 (09:43 +0900)]
Re-enable autoruns for cmd.exe on Windows

This acts as a revert of b83747a8a65b and 9886744a361b.  As pointed out
by Noah, HEAD and REL_17_STABLE are in a weird state where the code
paths adding /D would limit the spawn of child processes, but we still
have code paths where the spawn of more than one child process(es) would
be possible.

Let's remove these /D switches for now, to bring back the code into a
state consistent with how autorun is configured on a Windows host.

Reported-by: Noah Misch
Discussion: https://postgr.es/m/20240630021211[email protected]
Backpatch-through: 17

9 months agoUse xmlAddChildList not xmlAddChild in XMLSERIALIZE.
Tom Lane [Sat, 6 Jul 2024 19:16:13 +0000 (15:16 -0400)]
Use xmlAddChildList not xmlAddChild in XMLSERIALIZE.

It looks like we should have been doing this all along,
but we got away with the wrong coding until libxml2 2.13.0
tightened up xmlAddChild's behavior.

There is more stuff to be fixed to be compatible with 2.13.0,
and it will all need to be back-patched.  This is just a
trial commit to see if the buildfarm agrees that we can use
xmlAddChildList unconditionally.

Erik Wienhold, per report from Frank Streitzig.

Discussion: https://postgr.es/m/trinity-b0161630-d230-4598-9ebc-7a23acdb37cb-1720186432160@3c-app-gmx-bap25
Discussion: https://postgr.es/m/trinity-361ba18b-541a-4fe7-bc63-655ae3a7d599-1720259822452@3c-app-gmx-bs01

9 months agoAdjust tuplestore.c not to allocate BufFiles in generation context
David Rowley [Sat, 6 Jul 2024 05:40:05 +0000 (17:40 +1200)]
Adjust tuplestore.c not to allocate BufFiles in generation context

590b045c3 made it so tuplestore.c would store tuples inside a
generation.c memory context.  After fixing a bug report in 97651b013, it
seems that it's probably best not to allocate BufFile related
allocations in that context.  Let's keep it just for tuple data.

This adjusts the code to switch to the Tuplestorestate.context's parent,
which is the MemoryContext that tuplestore_begin_common() was called in.
It does not seem worth adding a new field in Tuplestorestate to store
this when we can access it by looking at the Tuplestorestate's
context's parent.

Discussion: https://postgr.es/m/CAApHDvqFt_CdJtSr+E9YLZb7jZAyRCy3hjQ+ktM+dcOFVq-xkg@mail.gmail.com

9 months agoFix incorrect sentinel byte logic in GenerationRealloc()
David Rowley [Sat, 6 Jul 2024 01:59:34 +0000 (13:59 +1200)]
Fix incorrect sentinel byte logic in GenerationRealloc()

This only affects MEMORY_CONTEXT_CHECKING builds.

This fixes an off-by-one issue in GenerationRealloc() where the
fast-path code which tries to reuse the existing allocation if the
existing chunk is >= the new requested size.  The code there thought it
was always ok to use the existing chunk, but when oldsize == size there
isn't enough space to store the sentinel byte.  If both sizes matched
exactly set_sentinel() would overwrite the first byte beyond the chunk
and then subsequent GenerationRealloc() calls could then fail the
Assert(chunk->requested_size < oldsize) check which is trying to ensure
the chunk is large enough to store the sentinel.

The same issue does not exist in aset.c as the sentinel checking code
only adds a sentinel byte if there's enough space in the chunk.

Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/49275921-7b39-41af-5eb8-97b50ce3312e@gmail.com
Backpatch-through: 16, where the problem was introduced by 0e480385e

9 months agoCope with <regex.h> name clashes.
Thomas Munro [Fri, 5 Jul 2024 22:24:49 +0000 (10:24 +1200)]
Cope with <regex.h> name clashes.

macOS 15's SDK pulls in headers related to <regex.h> when we include
<xlocale.h>.  This causes our own regex_t implementation to clash with
the OS's regex_t implementation.  Luckily our function names already had
pg_ prefixes, but the macros and typenames did not.

Include <regex.h> explicitly on all POSIX systems, and fix everything
that breaks.  Then we can prove that we are capable of fully hiding and
replacing the system regex API with our own.

1.  Deal with standard-clobbering macros by undefining them all first.
POSIX says they are "symbolic constants".  If they are macros, this
allows us to redefine them.  If they are enums or variables, our macros
will hide them.

2.  Deal with standard-clobbering types by giving our types pg_
prefixes, and then using macros to redirect xxx_t -> pg_xxx_t.

After including our "regex/regex.h", the system <regex.h> is hidden,
because we've replaced all the standard names.  The PostgreSQL source
tree and extensions can continue to use standard prefix-less type and
macro names, but reach our implementation, if they included our
"regex/regex.h" header.

Back-patch to all supported branches, so that macOS 15's tool chain can
build them.

Reported-by: Stan Hu <[email protected]>
Suggested-by: Tom Lane <[email protected]>
Tested-by: Aleksander Alekseev <[email protected]>
Discussion: https://postgr.es/m/CAMBWrQnEwEJtgOv7EUNsXmFw2Ub4p5P%2B5QTBEgYwiyjy7rAsEQ%40mail.gmail.com

9 months agoFix placement of "static".
Tom Lane [Fri, 5 Jul 2024 21:32:55 +0000 (17:32 -0400)]
Fix placement of "static".

Various buildfarm critters were complaining about

pgbench.c:304:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration]

Evidently a thinko in 720b0eaae.

9 months agoRemove check hooks for GUCs that contribute to MaxBackends.
Nathan Bossart [Fri, 5 Jul 2024 19:42:55 +0000 (14:42 -0500)]
Remove check hooks for GUCs that contribute to MaxBackends.

Each of max_connections, max_worker_processes,
autovacuum_max_workers, and max_wal_senders has a GUC check hook
that verifies the sum of those GUCs does not exceed a hard-coded
limit (see the comment for MAX_BACKENDS in postmaster.h).  In
general, the hooks effectively guard against egregious
misconfigurations.

However, this approach has some problems.  Since these check hooks
are called as each GUC is assigned its user-specified value, only
one of the hooks will be called with all the relevant GUCs set.  If
one or more of the user-specified values are less than the initial
values of the GUCs' underlying variables, false positives can
occur.

Furthermore, the error message emitted when one of the check hooks
fails is not tremendously helpful.  For example, the command

$ pg_ctl -D . start -o "-c max_connections=262100 -c max_wal_senders=10000"

fails with the following error:

FATAL:  invalid value for parameter "max_wal_senders": 10000

Fortunately, there is an extra copy of this check in
InitializeMaxBackends() that we can rely on, so this commit removes
the aforementioned GUC check hooks in favor of that one.  It also
enhances the error message to clearly show the values of the
relevant GUCs and the hard-coded limit their sum may not exceed.
The downside of this change is that server startup progresses
further before failing due to such misconfigurations (thus taking
longer), but these failures are expected to be rare, so we don't
anticipate any real harm in practice.

Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/ZnMr2k-Nk5vj7T7H%40nathan

9 months agoImprove PL/Tcl's method for choosing Tcl names of procedures.
Tom Lane [Fri, 5 Jul 2024 18:14:42 +0000 (14:14 -0400)]
Improve PL/Tcl's method for choosing Tcl names of procedures.

Previously, the internal name of a PL/Tcl function was just
"__PLTcl_proc_NNNN", where NNNN is the function OID.  That's pretty
unhelpful when reading an error report.  Plus it prevents us from
testing the CONTEXT output for PL/Tcl errors, since the OIDs shown
in the regression tests wouldn't be stable.

Instead, base the internal name on the result of format_procedure(),
which will be unique in most cases.  For the edge cases where it's
not, we can append the function OID to make it unique.

Sadly, the pltcl_trigger.sql test script still has to suppress the
context reports, because they'd include trigger arguments which
contain relation OIDs per PL/Tcl's longstanding API for triggers.

I had to modify one existing test case to throw a different error
than before, because I found that Tcl 8.5 and Tcl 8.6 spell the
context message for the original error slightly differently.
We might have to make more adjustments in that vein once this
gets wider testing.

Patch by me; thanks to Pavel Stehule for the idea to use
format_procedure() rather than just the proname.

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

9 months agoDoc: minor improvements for our "Brief History" chapter.
Tom Lane [Fri, 5 Jul 2024 17:12:34 +0000 (13:12 -0400)]
Doc: minor improvements for our "Brief History" chapter.

Add a link to Joe Hellerstein's paper "Looking Back at Postgres",
which is quite an interesting take on the history of Postgres.

The reference to Appendix E was written when we were still keeping
the entire release-note history there, which we stopped doing some
years ago when the O(N^2) cost of that started to become apparent.
Instead, point to the release note archives on the website.
(This per suggestion from Daniel Gustafsson.)

In passing, move the "ports12" biblioentry to be in alphabetical
order within that section.

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

9 months agoSupport loading of injection points
Michael Paquier [Fri, 5 Jul 2024 08:41:49 +0000 (17:41 +0900)]
Support loading of injection points

This can be used to load an injection point and prewarm the
backend-level cache before running it, to avoid issues if the point
cannot be loaded due to restrictions in the code path where it would be
run, like a critical section where no memory allocation can happen
(load_external_function() can do allocations when expanding a library
name).

Tests can use a macro called INJECTION_POINT_LOAD() to load an injection
point.  The test module injection_points gains some tests, and a SQL
function able to load an injection point.

Based on a request from Andrey Borodin, who has implemented a test for
multixacts requiring this facility.

Reviewed-by: Andrey Borodin
Discussion: https://postgr.es/m/[email protected]

9 months agoLift limitation that PGPROC->links must be the first field
Heikki Linnakangas [Fri, 5 Jul 2024 08:21:46 +0000 (11:21 +0300)]
Lift limitation that PGPROC->links must be the first field

Since commit 5764f611e1, we've been using the ilist.h functions for
handling the linked list. There's no need for 'links' to be the first
element of the struct anymore, except for one call in InitProcess
where we used a straight cast from the 'dlist_node *' to PGPROC *,
without the dlist_container() macro. That was just an oversight in
commit 5764f611e1, fix it.

There no imminent need to move 'links' from being the first field, but
let's be tidy.

Reviewed-by: Aleksander Alekseev, Andres Freund
Discussion: https://www.postgresql.org/message-id/22aa749e-cc1a-424a-b455-21325473a794@iki.fi

9 months agoImprove memory management and performance of tuplestore.c
David Rowley [Fri, 5 Jul 2024 05:51:27 +0000 (17:51 +1200)]
Improve memory management and performance of tuplestore.c

Here we make tuplestore.c use a generation.c memory context rather than
allocating tuples into the CurrentMemoryContext, which primarily is the
ExecutorState or PortalHoldContext memory context.  Not having a
dedicated context can cause the CurrentMemoryContext context to become
bloated when pfree'd chunks are not reused by future tuples.  Using
generation speeds up users of tuplestore.c, such as the Materialize,
WindowAgg and CTE Scan executor nodes.  The main reason for the speedup is
due to generation.c being more memory efficient than aset.c memory
contexts.  Specifically, generation does not round sizes up to the next
power of 2 value.  This both saves memory, allowing more tuples to fit in
work_mem, but also makes the memory usage more compact and fit on fewer
cachelines.  One benchmark showed up to a 22% performance increase in a
query containing a Materialize node.  Much higher gains are possible if
the memory reduction prevents tuplestore.c from spilling to disk.  This is
especially true for WindowAgg nodes where improvements of several thousand
times are possible if the memory reductions made here prevent tuplestore
from spilling to disk.

Additionally, a generation.c memory context is much better suited for this
job as it works well with FIFO palloc/pfree patterns, which is exactly how
tuplestore.c uses it.  Because of the way generation.c allocates memory,
tuples consecutively stored in tuplestores are much more likely to be
stored consecutively in memory.  This allows the CPU's hardware prefetcher
to work more efficiently as it provides a more predictable pattern to
allow cachelines for the next tuple to be loaded from RAM in advance of
them being needed by the executor.

Using a dedicated memory context for storing tuples also allows us to more
efficiently clean up the memory used by the tuplestore as we can reset or
delete the context rather than looping over all stored tuples and
pfree'ing them one by one.

Also, remove a badly placed USEMEM call in readtup_heap().  The tuple
wasn't being allocated in the Tuplestorestate's context, so no need to
adjust the memory consumed by the tuplestore there.

Author: David Rowley
Reviewed-by: Matthias van de Meent, Dmitry Dolgov
Discussion: https://postgr.es/m/CAApHDvp5Py9g4Rjq7_inL3-MCK1Co2CRt_YWFwTU2zfQix0p4A@mail.gmail.com

9 months agoFix newly introduced issue in EXPLAIN for Materialize nodes
David Rowley [Fri, 5 Jul 2024 04:56:16 +0000 (16:56 +1200)]
Fix newly introduced issue in EXPLAIN for Materialize nodes

The code added in 1eff8279d was lacking a check to see if the tuplestore
had been created.  In nodeMaterial.c this is done by ExecMaterial() rather
than by ExecInitMaterial(), so the tuplestore won't be created unless
the node has been executed at least once, as demonstrated by Alexander
in his report.

Here we skip showing any of the new EXPLAIN ANALYZE information when the
Materialize node has not been executed.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/fe7fc8fb-86e5-ecb0-3cb2-dd2c9a6c482f@gmail.com

9 months agoAdd simple codepoint redirections to unaccent.rules.
Thomas Munro [Fri, 5 Jul 2024 03:25:31 +0000 (15:25 +1200)]
Add simple codepoint redirections to unaccent.rules.

Previously we searched for code points where the Unicode data file
listed an equivalent combining character sequence that added accents.
Some codepoints redirect to a single other codepoint, instead of doing
any combining.  We can follow those references recursively to get the
answer.

Per bug report #18362, which reported missing Ancient Greek characters.
Specifically, precomposed characters with oxia (from the polytonic
accent system used for old Greek) just point to precomposed characters
with tonos (from the monotonic accent system for modern Greek), and we
have to follow the extra hop to find out that they are composed with
an acute accent.

Besides those, the new rule also:

* pulls in a lot of 'Mathematical Alphanumeric Symbols', which are
  copies of the Latin and Greek alphabets and numbers rendered
  in different typefaces, and

* corrects a single mathematical letter that previously came from the
  CLDR transliteration file, but the new rule extracts from the main
  Unicode database file, where clearly the latter is right and the
  former is a wrong (reported to CLDR).

Reported-by: Cees van Zeeland <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/18362-be6d0cfe122b6354%40postgresql.org

9 months agoAdd memory/disk usage for Material nodes in EXPLAIN
David Rowley [Fri, 5 Jul 2024 02:05:08 +0000 (14:05 +1200)]
Add memory/disk usage for Material nodes in EXPLAIN

Up until now, there was no ability to easily determine if a Material
node caused the underlying tuplestore to spill to disk or even see how
much memory the tuplestore used if it didn't.

Here we add some new functions to tuplestore.c to query this information
and add some additional output in EXPLAIN ANALYZE to display this
information for the Material node.

There are a few other executor node types that use tuplestores, so we
could also consider adding these details to the EXPLAIN ANALYZE for
those nodes too.  Let's consider those independently from this.  Having
the tuplestore.c infrastructure in to allow that is step 1.

Author: David Rowley
Reviewed-by: Matthias van de Meent, Dmitry Dolgov
Discussion: https://postgr.es/m/CAApHDvp5Py9g4Rjq7_inL3-MCK1Co2CRt_YWFwTU2zfQix0p4A@mail.gmail.com

9 months agoSupport "Right Semi Join" plan shapes
Richard Guo [Fri, 5 Jul 2024 00:26:48 +0000 (09:26 +0900)]
Support "Right Semi Join" plan shapes

Hash joins can support semijoin with the LHS input on the right, using
the existing logic for inner join, combined with the assurance that only
the first match for each inner tuple is considered, which can be
achieved by leveraging the HEAP_TUPLE_HAS_MATCH flag.  This can be very
useful in some cases since we may now have the option to hash the
smaller table instead of the larger.

Merge join could likely support "Right Semi Join" too.  However, the
benefit of swapping inputs tends to be small here, so we do not address
that in this patch.

Note that this patch also modifies a test query in join.sql to ensure it
continues testing as intended.  With this patch the original query would
result in a right-semi-join rather than semi-join, compromising its
original purpose of testing the fix for neqjoinsel's behavior for
semi-joins.

Author: Richard Guo
Reviewed-by: wenhui qiu, Alena Rybakina, Japin Li
Discussion: https://postgr.es/m/CAMbWs4_X1mN=ic+SxcyymUqFx9bB8pqSLTGJ-F=MHy4PW3eRXw@mail.gmail.com

9 months agoDoc: small improvements in discussion of geometric data types.
Tom Lane [Thu, 4 Jul 2024 17:23:32 +0000 (13:23 -0400)]
Doc: small improvements in discussion of geometric data types.

State explicitly that the coordinates in our geometric data types are
float8.  Also explain that polygons store their bounding box.

While here, fix the table of geometric data types to show type
"line"'s size correctly: it's 24 bytes not 32.  This has somehow
escaped notice since that table was made in 1998.

Per suggestion from Sebastian Skałacki.  The size error seems
important enough to justify back-patching.

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

9 months agoFix copy/paste mistake in comment
Alvaro Herrera [Thu, 4 Jul 2024 11:57:47 +0000 (13:57 +0200)]
Fix copy/paste mistake in comment

Backpatch to 17

Author: Yugo NAGATA <[email protected]>
Discussion: https://postgr.es/m/20240704134638.355ad44a445fa1e764a220cd@sranhm.sraoss.co.jp

9 months agoRemove bogus assertion in pg_atomic_monotonic_advance_u64
Alvaro Herrera [Thu, 4 Jul 2024 11:25:31 +0000 (13:25 +0200)]
Remove bogus assertion in pg_atomic_monotonic_advance_u64

This code wanted to ensure that the 'exchange' variable passed to
pg_atomic_compare_exchange_u64 has correct alignment, but apparently
platforms don't actually require anything that doesn't come naturally.

While messing with pg_atomic_monotonic_advance_u64: instead of using
Max() to determine the value to return, just use
pg_atomic_compare_exchange_u64()'s return value to decide; also, use
pg_atomic_compare_exchange_u64 instead of the _impl version; also remove
the unnecessary underscore at the end of variable name "target".

Backpatch to 17, where this code was introduced by commit bf3ff7bf83bc.

Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/36796438-a718-cf9b-2071-b2c1b947c1b5@gmail.com

9 months agodoc: Specify when ssl_prefer_server_ciphers was added
Daniel Gustafsson [Thu, 4 Jul 2024 09:38:37 +0000 (11:38 +0200)]
doc: Specify when ssl_prefer_server_ciphers was added

The ssl_prefer_server_ciphers setting is quite important from a
security point of view, so simply stating that older versions
doesn't have it isn't very helpful.  This adds the version when
the GUC was added to help readers.

Backpatch to all supported versions since this setting has been
around since 9.4.

Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/5D7E0F5E-E620-4D54-8788-66D421AC76F0@yesql.se
Backpatch-through: v12

9 months agoAdd pg_get_acl() to get the ACL for a database object
Michael Paquier [Thu, 4 Jul 2024 08:09:06 +0000 (17:09 +0900)]
Add pg_get_acl() to get the ACL for a database object

This function returns the ACL for a database object, specified by
catalog OID and object OID.  This is useful to be able to
retrieve the ACL associated to an object specified with a
(class_id,objid) couple, similarly to the other functions for object
identification, when joined with pg_depend or pg_shdepend.

Original idea by Álvaro Herrera.

Bump catalog version.

Author: Joel Jacobson
Reviewed-by: Isaac Morland, Michael Paquier, Ranier Vilela
Discussion: https://postgr.es/m/80b16434-b9b1-4c3d-8f28-569f21c2c102@app.fastmail.com

9 months agoSQL/JSON: Fix some obsolete comments.
Amit Langote [Fri, 28 Jun 2024 06:09:59 +0000 (15:09 +0900)]
SQL/JSON: Fix some obsolete comments.

JSON_OBJECT(), JSON_OBJETAGG(), JSON_ARRAY(), and JSON_ARRAYAGG()
added in 7081ac46ace are not transformed into direct calls to
user-defined functions as the comments claim. Fix by mentioning
instead that they are transformed into JsonConstructorExpr nodes,
which may call them, for example, for the *AGG() functions.

Reported-by: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/058c856a-e090-ac42-ff00-ffe394f52a87%40gmail.com
Backpatch-through: 16

9 months agoAssign error codes where missing for user-facing failures
Michael Paquier [Thu, 4 Jul 2024 00:48:40 +0000 (09:48 +0900)]
Assign error codes where missing for user-facing failures

All the errors triggered in the code paths patched here would cause the
backend to issue an internal_error errcode, which is a state that should
be used only for "can't happen" situations.  However, these code paths
are reachable by the regression tests, and could be seen by users in
valid cases.  Some regression tests expect internal errcodes as they
manipulate the backend state to cause corruption (like checksums), or
use elog() because it is more convenient (like injection points), these
have no need to change.

This reduces the number of internal failures triggered in a check-world
by more than half, while providing correct errcodes for these valid
cases.

Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/[email protected]

9 months agoOptimize memory access in GetRunningTransactionData()
Alexander Korotkov [Wed, 3 Jul 2024 23:05:37 +0000 (02:05 +0300)]
Optimize memory access in GetRunningTransactionData()

e85662df44 made GetRunningTransactionData() calculate the oldest running
transaction id within the current database.  This commit optimized this
calculation by performing a cheap transaction id comparison before fetching
the process database id, while the latter could cause extra cache misses.

Reported-by: Noah Misch
Discussion: https://postgr.es/m/20240630231816.bf.nmisch%40google.com

9 months agoFix typo in GetRunningTransactionData()
Alexander Korotkov [Wed, 3 Jul 2024 23:05:27 +0000 (02:05 +0300)]
Fix typo in GetRunningTransactionData()

e85662df44 made GetRunningTransactionData() calculate the oldest running
transaction id within the current database.  However, because of the typo,
the new code uses oldestRunningXid instead of oldestDatabaseRunningXid
in comparison before updating oldestDatabaseRunningXid.  This commit fixes
that issue.

Reported-by: Noah Misch
Discussion: https://postgr.es/m/20240630231816.bf.nmisch%40google.com
Backpatch-through: 17

9 months agoRemove incorrect Asserts in buffile.c
David Rowley [Wed, 3 Jul 2024 21:44:34 +0000 (09:44 +1200)]
Remove incorrect Asserts in buffile.c

Both BufFileSize() and BufFileAppend() contained Asserts to ensure the
given BufFile(s) had a valid fileset.  A valid fileset isn't required in
either of these functions, so remove the Asserts and adjust the
comments accordingly.

This was noticed while work was being done on a new patch to call
BufFileSize() on a BufFile without a valid fileset.  It seems there's
currently no code in the tree which could trigger these Asserts, so no
need to backpatch this, for now.

Reviewed-by: Peter Geoghegan, Matthias van de Meent, Tom Lane
Discussion: https://postgr.es/m/CAApHDvofgZT0VzydhyGH5MMb-XZzNDqqAbzf1eBZV5HDm3%2BosQ%40mail.gmail.com

9 months agoImprove performance of binary_upgrade_set_pg_class_oids().
Nathan Bossart [Wed, 3 Jul 2024 19:21:50 +0000 (14:21 -0500)]
Improve performance of binary_upgrade_set_pg_class_oids().

This function generates the commands that preserve the OIDs and
relfilenodes of relations during pg_upgrade.  It is called once per
relevant relation, and each such call executes a relatively
expensive query to retrieve information for a single pg_class_oid.
This can cause pg_dump to take significantly longer when
--binary-upgrade is specified, especially when there are many
tables.

This commit improves the performance of this function by gathering
all the required pg_class information with a single query at the
beginning of pg_dump.  This information is stored in a sorted array
that binary_upgrade_set_pg_class_oids() can bsearch() for what it
needs.  This follows a similar approach as commit d5e8930f50, which
introduced a sorted array for role information.

With this patch, 'pg_dump --binary-upgrade' will use more memory,
but that isn't expected to be too egregious.  Per the mailing list
discussion, folks feel that this is worth the trade-off.

Reviewed-by: Corey Huinker, Michael Paquier, Daniel Gustafsson
Discussion: https://postgr.es/m/20240418041712.GA3441570%40nathanxps13

9 months agoRemove is_index parameter from binary_upgrade_set_pg_class_oids().
Nathan Bossart [Wed, 3 Jul 2024 15:58:26 +0000 (10:58 -0500)]
Remove is_index parameter from binary_upgrade_set_pg_class_oids().

Since commit 9a974cbcba, this function retrieves the relkind before
it needs to know whether the relation is an index, so we no longer
need callers to provide this information.

Suggested-by: Daniel Gustafsson
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/20240418041712.GA3441570%40nathanxps13

9 months agoAvoid 0-length memcpy to NULL with EXEC_BACKEND
Heikki Linnakangas [Wed, 3 Jul 2024 12:58:14 +0000 (15:58 +0300)]
Avoid 0-length memcpy to NULL with EXEC_BACKEND

memcpy(NULL, src, 0) is forbidden by POSIX, even though every
production version of libc allows it. Let's be tidy.

Per report from Thomas Munro, running UBSan with EXEC_BACKEND.
Backpatch to v17, where this code was added.

Discussion: https://www.postgresql.org/message-id/CA%2BhUKG%2Be-dV7YWBzfBZXsgovgRuX5VmvmOT%[email protected]

9 months agoTighten check for --forkchild argument when spawning child process
Heikki Linnakangas [Wed, 3 Jul 2024 12:53:30 +0000 (15:53 +0300)]
Tighten check for --forkchild argument when spawning child process

Commit aafc05de1b removed all the other --fork* arguments. Altough
this is inconsequential, backpatch to v17 since this is new.

Author: Nathan Bossart
Discussion: https://www.postgresql.org/message-id/ZnCCEN0l3qWv-XpW@nathan

9 months agoFix the testcase introduced in commit 81d20fbf7a.
Amit Kapila [Wed, 3 Jul 2024 09:34:59 +0000 (15:04 +0530)]
Fix the testcase introduced in commit 81d20fbf7a.

The failed test was syncing failover replication slot to standby to test
that we remove such slots after the standby is converted to subscriber by
pg_createsubscriber.

In one of the buildfarm members, the sync of the slot failed because the
LSN on the standby was before the syncslot's LSN. We need to wait for
standby to catch up before trying to sync the slot with
pg_sync_replication_slots().

The other buildfarm failed because autovacuum generated a xid which is
replicated to the standby at some random point making slots at primary
lag behind standby during slot sync.

Both these failures wouldn't have occurred if we had used built-in
slotsync worker as it would have waited for the standby to sync with
primary but for this test, it is sufficient to use
pg_sync_replication_slots().

Reported-by: Alexander Lakhin as per buildfarm
Author: Kuroda Hayato
Reviewed-by: Amit Kapila
Backpatch-through: 17
Discussion: https://postgr.es/m/0dffca12-bf17-4a7a-334d-225569de5e6e@gmail.com
Discussion: https://postgr.es/m/OSBPR01MB25528300C71FDD83EA1DCA12F5DD2@OSBPR01MB2552.jpnprd01.prod.outlook.com

9 months agoReplace hardcoded identifiers of pgstats file by #defines
Michael Paquier [Wed, 3 Jul 2024 04:09:20 +0000 (13:09 +0900)]
Replace hardcoded identifiers of pgstats file by #defines

This changes pgstat.c so as the three types of entries that can exist in
a pgstats file are not hardcoded anymore, replacing them with
descriptively-named macros, when reading and writing stats files:
- 'N' for named entries, like replication slot stats.
- 'S' for entries identified by a hash.
- 'E' for the end-of-file

This has come up while working on making this area of the code more
pluggable.  The format of the stats file is unchanged, hence there is no
need to bump PGSTAT_FILE_FORMAT_ID.

Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/[email protected]

9 months agoClean up more unused variables in perl code
Michael Paquier [Wed, 3 Jul 2024 03:43:57 +0000 (12:43 +0900)]
Clean up more unused variables in perl code

This is a continuation of 0c1aca461481, with some cleanup in:
- msvc_gendef.pl
- pgindent
- 005_negotiate_encryption.pl, as of an oversight of d39a49c1e459 that
has removed %params in test_matrix(), making also $server_config
useless.

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

9 months agoAdd CODE_OF_CONDUCT.md, CONTRIBUTING.md, and SECURITY.md.
Nathan Bossart [Tue, 2 Jul 2024 18:03:58 +0000 (13:03 -0500)]
Add CODE_OF_CONDUCT.md, CONTRIBUTING.md, and SECURITY.md.

These "community health files" provide important information about
the project and will be displayed prominently on the PostgreSQL
GitHub mirror.  For now, they just point to the website, but we may
want to expand on the content in the future.

Reviewed-by: Peter Eisentraut, Alvaro Herrera, Tom Lane
Discussion: https://postgr.es/m/20240417023609.GA3228660%40nathanxps13

9 months agoRemove redundant SetProcessingMode(InitProcessing) calls
Heikki Linnakangas [Tue, 2 Jul 2024 17:14:40 +0000 (20:14 +0300)]
Remove redundant SetProcessingMode(InitProcessing) calls

After several refactoring iterations, auxiliary processes are no
longer initialized from the bootstrapper. Using the InitProcessing
mode for initializing auxiliary processes is more appropriate. Since
the global variable Mode is initialized to InitProcessing, we can just
remove the redundant calls of SetProcessingMode(InitProcessing).

Author: Xing Guo <[email protected]>
Discussion: https://www.postgresql.org/message-id/CACpMh%2BDBHVT4xPGimzvex%3DwMdMLQEu9PYhT%2BkwwD2x2nu9dU_Q%40mail.gmail.com

9 months agoMove bgworker specific logic to bgworker.c
Heikki Linnakangas [Tue, 2 Jul 2024 17:12:05 +0000 (20:12 +0300)]
Move bgworker specific logic to bgworker.c

For clarity, we've been slowly moving functions that are not called
from the postmaster process out of postmaster.c.

Author: Xing Guo <[email protected]>
Discussion: https://www.postgresql.org/message-id/CACpMh%2BDBHVT4xPGimzvex%3DwMdMLQEu9PYhT%2BkwwD2x2nu9dU_Q%40mail.gmail.com

9 months agopg_dump: Remove some unused return values.
Nathan Bossart [Tue, 2 Jul 2024 16:22:06 +0000 (11:22 -0500)]
pg_dump: Remove some unused return values.

getSchemaData() does not use the return values of many of its get*
helper functions because they store the data elsewhere.  For
example, commit 92316a4582 introduced a separate hash table for
dumpable objects that said helper functions populate.  This commit
changes these functions to return void and removes their "int *"
parameters that returned the number of objects found.

Reviewed-by: Neil Conway, Tom Lane, Daniel Gustafsson
Discussion: https://postgr.es/m/ZmCAtVaOrHpf31PJ%40nathan

9 months agoUse safe string copy routine
Daniel Gustafsson [Tue, 2 Jul 2024 09:16:56 +0000 (11:16 +0200)]
Use safe string copy routine

Using memcpy with strlen as the size parameter will not take the
NULL terminator into account, relying instead on the destination
buffer being properly initialized. Replace with strlcpy which is
a safer alternative, and more in line with how we handle copying
strings elsewhere.

Author: Ranier Vilela <[email protected]>
Discussion: https://postgr.es/m/CAEudQApAsbLsQ+gGiw-hT+JwGhgogFa_=5NUkgFO6kOPxyNidQ@mail.gmail.com

9 months agoRemove too demanding test
Peter Eisentraut [Tue, 2 Jul 2024 08:43:12 +0000 (10:43 +0200)]
Remove too demanding test

Remove the test from commit 9c2e660b07.  This test ends up allocating
quite a bit of memory, which can make the test fail with out of memory
errors on some build farm machines.

9 months agoLimit max parameter number with MaxAllocSize
Peter Eisentraut [Tue, 2 Jul 2024 07:24:04 +0000 (09:24 +0200)]
Limit max parameter number with MaxAllocSize

MaxAllocSize puts an upper bound on the largest possible parameter
number ($268435455).  Use that limit instead of INT_MAX to report that
no parameters exist beyond that point instead of reporting an error
about the maximum allocation size being exceeded.

Author: Erik Wienhold <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/5d216d1c-91f6-4cbe-95e2-b4cbd930520c@ewie.name

9 months agoFix overflow in parsing of positional parameter
Peter Eisentraut [Tue, 2 Jul 2024 07:16:36 +0000 (09:16 +0200)]
Fix overflow in parsing of positional parameter

Replace atol with pg_strtoint32_safe in the backend parser and with
strtoint in ECPG to reject overflows when parsing the number of a
positional parameter.  With atol from glibc, parameters $2147483648 and
$4294967297 turn into $-2147483648 and $1, respectively.

Author: Erik Wienhold <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Alexander Lakhin <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/5d216d1c-91f6-4cbe-95e2-b4cbd930520c@ewie.name

9 months agoDrop pre-existing subscriptions from the converted subscriber.
Amit Kapila [Tue, 2 Jul 2024 06:06:21 +0000 (11:36 +0530)]
Drop pre-existing subscriptions from the converted subscriber.

We don't need the pre-existing subscriptions on the newly formed
subscriber by using pg_createsubscriber. The apply workers corresponding
to these subscriptions can connect to other publisher nodes and either get
some unwarranted data or can lead to ERRORs in connecting to such nodes.

Author: Kuroda Hayato
Reviewed-by: Amit Kapila, Shlok Kyal, Vignesh C
Backpatch-through: 17
Discussion: https://postgr.es/m/OSBPR01MB25526A30A1FBF863ACCDDA3AF5C92@OSBPR01MB2552.jpnprd01.prod.outlook.com

9 months agoImprove some global variable declarations
Peter Eisentraut [Tue, 2 Jul 2024 04:55:56 +0000 (06:55 +0200)]
Improve some global variable declarations

We have in launch_backend.c:

    /*
     * The following need to be available to the save/restore_backend_variables
     * functions.  They are marked NON_EXEC_STATIC in their home modules.
     */
    extern slock_t *ShmemLock;
    extern slock_t *ProcStructLock;
    extern PGPROC *AuxiliaryProcs;
    extern PMSignalData *PMSignalState;
    extern pg_time_t first_syslogger_file_time;
    extern struct bkend *ShmemBackendArray;
    extern bool redirection_done;

That comment is not completely true: ShmemLock, ShmemBackendArray, and
redirection_done are not in fact NON_EXEC_STATIC.  ShmemLock once was,
but was then needed elsewhere.  ShmemBackendArray was static inside
postmaster.c before launch_backend.c was created.  redirection_done
was never static.

This patch moves the declaration of ShmemLock and redirection_done to
a header file.

ShmemBackendArray gets a NON_EXEC_STATIC.  This doesn't make a
difference, since it only exists if EXEC_BACKEND anyway, but it makes
it consistent.

After that, the comment is now correct.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

9 months agoAdd missing includes for some global variables
Peter Eisentraut [Tue, 2 Jul 2024 04:53:48 +0000 (06:53 +0200)]
Add missing includes for some global variables

src/backend/libpq/pqcomm.c: "postmaster/postmaster.h" for Unix_socket_group, Unix_socket_permissions
src/backend/utils/init/globals.c: "postmaster/postmaster.h" for MyClientSocket
src/backend/utils/misc/guc_tables.c: "utils/rls.h" for row_security
src/backend/utils/sort/tuplesort.c: "utils/guc.h" for trace_sort

Nothing currently diagnoses missing includes for global variables, but
this is being cleaned up, and these ones had an obvious header file
available.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

9 months agoConvert some extern variables to static
Peter Eisentraut [Tue, 2 Jul 2024 04:53:19 +0000 (06:53 +0200)]
Convert some extern variables to static

These probably should have been static all along, it was only
forgotten out of sloppiness.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

9 months agoRemove unused structure member in pg_createsubscriber.c.
Amit Kapila [Tue, 2 Jul 2024 04:58:51 +0000 (10:28 +0530)]
Remove unused structure member in pg_createsubscriber.c.

Author: Kuroda Hayato
Backpatch-through: 17
Discussion: https://postgr.es/m/OSBPR01MB25526A30A1FBF863ACCDDA3AF5C92@OSBPR01MB2552.jpnprd01.prod.outlook.com

9 months agoUse TupleDescAttr macro consistently
David Rowley [Tue, 2 Jul 2024 01:41:47 +0000 (13:41 +1200)]
Use TupleDescAttr macro consistently

A few places were directly accessing the attrs[] array. This goes
against the standards set by 2cd708452. Fix that.

Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com

9 months agoCleanup perl code from unused variables and routines
Michael Paquier [Tue, 2 Jul 2024 00:47:16 +0000 (09:47 +0900)]
Cleanup perl code from unused variables and routines

This commit removes unused variables and routines from some perl code
that have accumulated across the years.  This touches the following
areas:
- Wait event generation script.
- AdjustUpgrade.pm.
- TAP perl code

Author: Alexander Lakhin
Reviewed-by: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/70b340bc-244a-589d-ef8b-d8aebb707a84@gmail.com

9 months agoAdd information about access method for partitioned relations in \dP+
Michael Paquier [Tue, 2 Jul 2024 00:01:38 +0000 (09:01 +0900)]
Add information about access method for partitioned relations in \dP+

Since 374c7a229042, it is possible to set a table AM on a partitioned
table.  This information was showing up already in psql with \d+, while
\dP+ provided no information.

This commit extends \dP+ to show the access method used by a partitioned
table or index, if set.

Author: Justin Pryzby
Discussion: https://postgr.es/m/ZkyivySXnbvOogZz@pryzbyj2023

9 months agoRemove support for HPPA (a/k/a PA-RISC) architecture.
Tom Lane [Mon, 1 Jul 2024 17:55:52 +0000 (13:55 -0400)]
Remove support for HPPA (a/k/a PA-RISC) architecture.

This old CPU architecture hasn't been produced in decades, and
whatever instances might still survive are surely too underpowered
for anyone to consider running Postgres on in production.  We'd
nonetheless continued to carry code support for it (largely at my
insistence), because its unique implementation of spinlocks seemed
like a good edge case for our spinlock infrastructure.  However,
our last buildfarm animal of this type was retired last year, and
it seems quite unlikely that another will emerge.  Without the ability
to run tests, the argument that this is useful test code fails to
hold water.  Furthermore, carrying code support for an untestable
architecture has costs not to be ignored.  So, remove HPPA-specific
code, in the same vein as commits 718aa43a4 and 92d70b77e.

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

9 months agoRemove redundant privilege check from pg_sequences system view.
Nathan Bossart [Mon, 1 Jul 2024 16:47:40 +0000 (11:47 -0500)]
Remove redundant privilege check from pg_sequences system view.

This commit adjusts pg_sequence_last_value() to return NULL instead
of ERROR-ing for sequences for which the current user lacks
privileges.  This allows us to remove the call to
has_sequence_privilege() in the definition of the pg_sequences
system view.

Bumps catversion.

Suggested-by: Michael Paquier
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/20240501005730.GA594666%40nathanxps13

9 months agoPreserve CurrentMemoryContext across Start/CommitTransactionCommand.
Tom Lane [Mon, 1 Jul 2024 15:55:19 +0000 (11:55 -0400)]
Preserve CurrentMemoryContext across Start/CommitTransactionCommand.

Up to now, committing a transaction has caused CurrentMemoryContext to
get set to TopMemoryContext.  Most callers did not pay any particular
heed to this, which is problematic because TopMemoryContext is a
long-lived context that never gets reset.  If the caller assumes it
can leak memory because it's running in a limited-lifespan context,
that behavior translates into a session-lifespan memory leak.

The first-reported instance of this involved ProcessIncomingNotify,
which is called from the main processing loop that normally runs in
MessageContext.  That outer-loop code assumes that whatever it
allocates will be cleaned up when we're done processing the current
client message --- but if we service a notify interrupt, then whatever
gets allocated before the next switch to MessageContext will be
permanently leaked in TopMemoryContext.  sinval catchup interrupts
have a similar problem, and I strongly suspect that some places in
logical replication do too.

To fix this in a generic way, let's redefine the behavior as
"CommitTransactionCommand restores the memory context that was current
at entry to StartTransactionCommand".  This clearly fixes the issue
for the notify and sinval cases, and it seems to match the mental
model that's in use in the logical replication code, to the extent
that anybody thought about it there at all.

For consistency, likewise make subtransaction exit restore the context
that was current at subtransaction start (rather than always selecting
the CurTransactionContext of the parent transaction level).  This case
has less risk of resulting in a permanent leak than the outer-level
behavior has, but it would not meet the principle of least surprise
for some CommitTransactionCommand calls to restore the previous
context while others don't.

While we're here, also change xact.c so that we reset
TopTransactionContext at transaction exit and then re-use it in later
transactions, rather than dropping and recreating it in each cycle.
This probably doesn't save a lot given the context recycling mechanism
in aset.c, but it should save a little bit.  Per suggestion from David
Rowley.  (Parenthetically, the text in src/backend/utils/mmgr/README
implies that this is how I'd planned to implement it as far back as
commit 1aebc3618 --- but the code actually added in that commit just
drops and recreates it each time.)

This commit also cleans up a few places outside xact.c that were
needlessly making TopMemoryContext current, and thus risking more
leaks of the same kind.  I don't think any of them represent
significant leak risks today, but let's deal with them while the
issue is top-of-mind.

Per bug #18512 from wizardbrony.  Commit to HEAD only, as this change
seems to have some risk of breaking things for some callers.  We'll
apply a narrower fix for the known-broken cases in the back branches.

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

9 months agoAdd --no-sync to pg_upgrade's uses of pg_dump and pg_dumpall.
Nathan Bossart [Mon, 1 Jul 2024 15:18:26 +0000 (10:18 -0500)]
Add --no-sync to pg_upgrade's uses of pg_dump and pg_dumpall.

There's no reason to ensure that the files pg_upgrade generates
with pg_dump and pg_dumpall have been written safely to disk.  If
there is a crash during pg_upgrade, the upgrade must be restarted
from the beginning; dump files left behind by previous pg_upgrade
attempts cannot be reused.

Reviewed-by: Peter Eisentraut, Tom Lane, Michael Paquier, Daniel Gustafsson
Discussion: https://postgr.es/m/20240503171348.GA1731524%40nathanxps13

9 months agoRemove useless extern keywords
Peter Eisentraut [Mon, 1 Jul 2024 14:40:25 +0000 (16:40 +0200)]
Remove useless extern keywords

An extern keyword on a function definition (not declaration) is
useless and not the normal style.

Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org

10 months agoFix copy-paste mistake in PQcancelCreate
Alvaro Herrera [Mon, 1 Jul 2024 11:58:22 +0000 (13:58 +0200)]
Fix copy-paste mistake in PQcancelCreate

When an OOM occurred, this function was incorrectly setting a status of
CONNECTION_BAD on the passed in PGconn instead of on the newly created
PGcancelConn.

Mistake introduced with 61461a300c1c.  Backpatch to 17.

Author: Jelte Fennema-Nio <[email protected]>
Reported-by: Noah Misch <[email protected]>
Discussion: https://postgr.es/m/20240630190040[email protected]

10 months agoAdd context type field to pg_backend_memory_contexts
David Rowley [Mon, 1 Jul 2024 09:19:01 +0000 (21:19 +1200)]
Add context type field to pg_backend_memory_contexts

Since we now (as of v17) have 4 MemoryContext types, the type of context
seems like useful information to include in the pg_backend_memory_contexts
view.  Here we add that.

Reviewed-by: David Christensen, Michael Paquier
Discussion: https://postgr.es/m/CAApHDvrXX1OR09Zjb5TnB0AwCKze9exZN%3D9Nxxg1ZCVV8W-3BA%40mail.gmail.com

10 months agoRemove useless code
Peter Eisentraut [Mon, 1 Jul 2024 06:50:29 +0000 (08:50 +0200)]
Remove useless code

BuildDescForRelation() goes out of its way to fill in
->constr->has_not_null, but that value is not used for anything later,
so this code can all be removed.  Note that BuildDescForRelation()
doesn't make any effort to fill in the rest of ->constr, so there is
no claim that that structure is completely filled in.

Reviewed-by: Tomasz Rybak <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/a368248e-69e4-40be-9c07-6c3b5880b0a6@eisentraut.org

10 months agoRemove useless initializations
Peter Eisentraut [Mon, 1 Jul 2024 06:50:10 +0000 (08:50 +0200)]
Remove useless initializations

The struct is already initialized to all zeros right before this, and
randomly initializing a few but not all fields to zero again has no
technical or educational value.

Reviewed-by: Tomasz Rybak <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/a368248e-69e4-40be-9c07-6c3b5880b0a6@eisentraut.org

10 months agodoc: Clarify that pg_attrdef also stores generation expressions
Peter Eisentraut [Mon, 1 Jul 2024 06:39:07 +0000 (08:39 +0200)]
doc: Clarify that pg_attrdef also stores generation expressions

This was documented with pg_attribute but not with pg_attrdef.

Reported-by: jian he <[email protected]>
Discussion: https://www.postgresql.org/message-id/CACJufxE+E-iYmBnZVZHiYA+WpyZZVv7BfiBLpo=T70EZHDU9rw@mail.gmail.com

10 months agoRename standby_slot_names to synchronized_standby_slots.
Amit Kapila [Mon, 1 Jul 2024 06:06:56 +0000 (11:36 +0530)]
Rename standby_slot_names to synchronized_standby_slots.

The standby_slot_names GUC allows the specification of physical standby
slots that must be synchronized before the logical walsenders associated
with logical failover slots. However, for this purpose, the GUC name is
too generic.

Author: Hou Zhijie
Reviewed-by: Bertrand Drouvot, Masahiko Sawada
Backpatch-through: 17
Discussion: https://postgr.es/m/[email protected]

10 months agoApply COPT to CXXFLAGS as well
Peter Eisentraut [Mon, 1 Jul 2024 05:30:38 +0000 (07:30 +0200)]
Apply COPT to CXXFLAGS as well

The main use of that make variable is to pass in -Werror.  It makes
sense to apply this to C++ as well.

Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/fe3e200c-edee-44e0-a6e3-d45dca72873b%40eisentraut.org

10 months agoUse pgstat_kind_infos to read fixed shared statistics
Michael Paquier [Mon, 1 Jul 2024 05:26:25 +0000 (14:26 +0900)]
Use pgstat_kind_infos to read fixed shared statistics

Shared statistics with a fixed number of objects are read from the stats
file in pgstat_read_statsfile() using members of PgStat_ShmemControl and
following an order based on their PgStat_Kind value.

Instead of being explicit, this commit changes the stats read to iterate
over the pgstat_kind_infos array to find the memory locations to read
into, based on a new shared_ctl_off in PgStat_KindInfo that can be used
to define the position of this stats kind in shared memory.  This makes
the read logic simpler, and eases the introduction of future
improvements aimed at making this area more pluggable for external
modules.

Original idea suggested by Andres Freund.

Author: Tristan Partin
Reviewed-by: Andres Freund, Michael Paquier
Discussion: https://postgr.es/m/[email protected]

10 months agoFurther weaken new pg_createsubscriber test on Windows.
Tom Lane [Mon, 1 Jul 2024 03:20:57 +0000 (23:20 -0400)]
Further weaken new pg_createsubscriber test on Windows.

Also omit backslashes (\) in the generated database names on Windows.
As before, perhaps we can revert this after updating affected
buildfarm animals.

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

10 months agoFormat better code for xact_decode()'s XLOG_XACT_INVALIDATIONS
Michael Paquier [Mon, 1 Jul 2024 01:08:00 +0000 (10:08 +0900)]
Format better code for xact_decode()'s XLOG_XACT_INVALIDATIONS

This makes the code more consistent with the surroundings.

Author: ChangAo Chen
Reviewed-by: Ashutosh Bapat
Discussion: https://postgr.es/m/CAExHW5tNTevUh58SKddTtcX3yU_5_PDSC8Mdp-Q2hc9PpZHRJg@mail.gmail.com

10 months agodoc: Add ACL acronym for "Access Control List"
Michael Paquier [Mon, 1 Jul 2024 00:55:37 +0000 (09:55 +0900)]
doc: Add ACL acronym for "Access Control List"

Five places across the docs use this abbreviation, so let's use a proper
acronym entry for it.

Per suggestion from me.

Author: Joel Jacobson
Reviewed-by: Nathan Bossart, David G. Johnston
Discussion: https://postgr.es/m/9253b872-dbb1-42a6-a79e-b1e96effc857@app.fastmail.com

10 months agoRemove PgStat_KindInfo.named_on_disk
Michael Paquier [Mon, 1 Jul 2024 00:35:36 +0000 (09:35 +0900)]
Remove PgStat_KindInfo.named_on_disk

This field is used to track if a stats kind can use a custom format
representation on disk when reading or writing its stats case.  On HEAD,
this exists for replication slots stats, that need a mapping between an
internal index ID and the slot names.

named_on_disk is currently used nowhere and the callbacks
to_serialized_name and from_serialized_name are in charge of checking if
the serialization of the stats data should apply, so let's remove it.

Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/[email protected]

10 months agoImprove enlargeStringInfo's ERROR message
David Rowley [Mon, 1 Jul 2024 00:11:10 +0000 (12:11 +1200)]
Improve enlargeStringInfo's ERROR message

Until now, when an enlargeStringInfo() call would cause the StringInfo to
exceed its maximum size, we reported an "out of memory" error.  This is
misleading as it's no such thing.

Here we remove the "out of memory" text and replace it with something
more relevant to better indicate that it's a program limitation that's
been reached.

Reported-by: Michael Banck
Reviewed-by: Daniel Gustafsson, Tom Lane
Discussion: https://postgr.es/m/18484-3e357ade5fe50e61@postgresql.org

10 months agoStamp HEAD as 18devel.
Michael Paquier [Sun, 30 Jun 2024 22:56:10 +0000 (07:56 +0900)]
Stamp HEAD as 18devel.

Let the hacking begin ...

10 months agoRun pgperltidy
Michael Paquier [Sun, 30 Jun 2024 22:35:01 +0000 (07:35 +0900)]
Run pgperltidy

This is required before the creation of a new branch.  pgindent is
clean, as well as is reformat-dat-files.

perltidy version is v20230309, as documented in pgindent's README.

10 months agoTemporarily(?) weaken new pg_createsubscriber test on Windows.
Tom Lane [Sun, 30 Jun 2024 21:33:06 +0000 (17:33 -0400)]
Temporarily(?) weaken new pg_createsubscriber test on Windows.

Don't include double-quotes (") in the generated database names
on Windows.  Doing so tickles a bug in older versions of IPC::Run,
which fail to quote command line arguments correctly for that
platform.  Possibly we can revert this after updating affected
buildfarm animals.

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

10 months agoAdd PG_TEST_PG_COMBINEBACKUP_MODE
Tomas Vondra [Sun, 30 Jun 2024 17:26:12 +0000 (19:26 +0200)]
Add PG_TEST_PG_COMBINEBACKUP_MODE

Introduces an environment variable PG_TEST_PG_COMBINEBACKUP_MODE, that
determines copy mode used by pg_combinebackup in TAP tests. Defaults to
"--copy" but may be set to "--clone" or "--copy-file-range" to use the
alternative stategies.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/48da4a1f-ccd9-4988-9622-24f37b1de2b4%40eisentraut.org

10 months agoAdd pg_combinebackup --copy option
Tomas Vondra [Sun, 30 Jun 2024 17:20:02 +0000 (19:20 +0200)]
Add pg_combinebackup --copy option

Introduces --copy as an alternative to --clone and --copy-file-range.
This option simply picks the default mode to copy files, as if none of
the options was specified. This makes pg_combinebackup options more
consistent with pg_upgrade, and it makes testing simpler.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/48da4a1f-ccd9-4988-9622-24f37b1de2b4%40eisentraut.org

10 months agoAdd headers needed by pg_combinebackup --clone
Tomas Vondra [Sun, 30 Jun 2024 17:02:00 +0000 (19:02 +0200)]
Add headers needed by pg_combinebackup --clone

The code for file cloning existed, but was not reachable as it relied on
constants from missing headers. Due to that, on Linux --clone always
failed with

  error: file cloning not supported on this platform

Fixed by including the missing headers to relevant places. Adding the
headers revealed a couple compile errors in copy_file_clone(), so fix
those too.

Reported-by: Peter Eisentraut
Discussion: https://postgr.es/m/48da4a1f-ccd9-4988-9622-24f37b1de2b4%40eisentraut.org

10 months agoMake pg_createsubscriber warn if publisher has two-phase commit enabled.
Tom Lane [Sun, 30 Jun 2024 18:24:14 +0000 (14:24 -0400)]
Make pg_createsubscriber warn if publisher has two-phase commit enabled.

pg_createsubscriber currently always sets up logical replication
with two-phase commit disabled.  Improving that is not going to
happen for v17.  In the meantime, document the deficiency, and
adjust pg_createsubscriber so that it will emit a warning if
the source installation has max_prepared_transactions > 0.

Hayato Kuroda (some mods by Amit Kapila and me), per complaint from
Noah Misch

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

10 months agoMake pg_createsubscriber more wary about quoting connection parameters.
Tom Lane [Sun, 30 Jun 2024 17:45:24 +0000 (13:45 -0400)]
Make pg_createsubscriber more wary about quoting connection parameters.

The original coding here could fail with database names, user names,
etc that contain spaces or other special characters.

As partial test coverage, extend the 040_pg_createsubscriber.pl
test script so that it uses a generated database name containing
funny characters.

Hayato Kuroda (some mods by me), per complaint from Noah Misch

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

10 months agoFix .gitignore for new injection suite.
Noah Misch [Fri, 28 Jun 2024 18:17:50 +0000 (11:17 -0700)]
Fix .gitignore for new injection suite.

Commit c35f419d6efbdf1a050250d84b687e6705917711 missed this.

10 months agoRemove configuration-dependent output from new inplace-inval test.
Noah Misch [Fri, 28 Jun 2024 16:33:40 +0000 (09:33 -0700)]
Remove configuration-dependent output from new inplace-inval test.

Per buildfarm members prion and trilobite.  Back-patch to v12 (all
supported versions), like commit
0844b3968985447ed0a6937cfc8639e379da2fe6.

Strategy reviewed by Tom Lane.

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

10 months agopgindent, because I forgot to do that.
Robert Haas [Fri, 28 Jun 2024 14:45:51 +0000 (10:45 -0400)]
pgindent, because I forgot to do that.

Commit 065583cf460f980a182498941ac52810f709a897 should have
included these changes.

10 months agoSQL/JSON: Always coerce JsonExpr result at runtime
Amit Langote [Fri, 28 Jun 2024 12:58:13 +0000 (21:58 +0900)]
SQL/JSON: Always coerce JsonExpr result at runtime

Instead of looking up casts at parse time for converting the result
of JsonPath* query functions to the specified or the default
RETURNING type, always perform the conversion at runtime using either
the target type's input function or the function
json_populate_type().

There are two motivations for this change:

1. json_populate_type() coerces to types with typmod such that any
   string values that exceed length limit cause an error instead of
   silent truncation, which is necessary to be standard-conforming.

2. It was possible to end up with a cast expression that doesn't
   support soft handling of errors causing bugs in the of handling
   ON ERROR clause.

JsonExpr.coercion_expr which would store the cast expression is no
longer necessary, so remove.

Bump catversion because stored rules change because of the above
removal.

Reported-by: Alvaro Herrera <[email protected]>
Reviewed-by: Jian He <[email protected]>
Discussion: Discussion: https://postgr.es/m/202405271326.5a5rprki64aw%40alvherre.pgsql