postgresql.git
2 years agoAdd copy/equal support for XID lists
Alvaro Herrera [Tue, 12 Jul 2022 14:11:04 +0000 (16:11 +0200)]
Add copy/equal support for XID lists

Commit f10a025cfe97 added support for List to store Xids, but didn't
handle the new type in all cases.  Add some obviously necessary pieces.
As far as I am aware, this is all dead code as far as core code is
concerned, but it seems unacceptable not to have it in case third-party
code wants to rely on this type of list.  (Some parts of the List API
remain unimplemented, but that can be fixed as and when needed -- see
lack of list_intersection_oid, list_deduplicate_int as precedents.)

Discussion: https://postgr.es/m/20220708164534.nbejhgt4ajz35p65@alvherre.pgsql

2 years agoFix out-of-bounds read in json_lex_string
John Naylor [Tue, 12 Jul 2022 04:13:41 +0000 (11:13 +0700)]
Fix out-of-bounds read in json_lex_string

Commit 3838fa269 added a lookahead loop to allow building strings multiple
bytes at a time. This loop could exit because it reached the end of input,
yet did not check for that before checking if we reached the end of a
valid string. To fix, put the end of string check back in the outer loop.

Per Valgrind animal skink

2 years agoSupport TRUNCATE triggers on foreign tables.
Fujii Masao [Tue, 12 Jul 2022 00:18:02 +0000 (09:18 +0900)]
Support TRUNCATE triggers on foreign tables.

Now some foreign data wrappers support TRUNCATE command.
So it's useful to support TRUNCATE triggers on foreign tables for
audit logging or for preventing undesired truncation.

Author: Yugo Nagata
Reviewed-by: Fujii Masao, Ian Lawrence Barwick
Discussion: https://postgr.es/m/20220630193848.5b02e0d6076b86617a915682@sraoss.co.jp

2 years agoDoc: Acknowledge historically supported CPUs and OSes.
Thomas Munro [Mon, 11 Jul 2022 22:57:52 +0000 (10:57 +1200)]
Doc: Acknowledge historically supported CPUs and OSes.

PostgreSQL/POSTGRES has run on a huge range of CPUs and OSes.  As we're
dropping some of the earliest systems the project was founded on, let's
provide a place to remember them.

Discussion: https://postgr.es/m/959917.1657522169%40sss.pgh.pa.us

2 years agoFurther tidy-up for old CPU architectures.
Thomas Munro [Mon, 11 Jul 2022 22:53:45 +0000 (10:53 +1200)]
Further tidy-up for old CPU architectures.

Further to commit 92d70b77, let's drop the code we carry for the
following untested architectures: M68K, M88K, M32R, SuperH.  We have no
idea if anything actually works there, and surely as vintage hardware
and microcontrollers they would be underpowered for modern purposes.

We could always consider re-adding SuperH based on evidence of usage and
build farm support, if someone shows up to provide it.

While here, SPARC is usually written in all caps.

Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Robert Haas <robertmhaas@gmail.com> (the idea, not the patch)
Discussion: https://postgr.es/m/959917.1657522169%40sss.pgh.pa.us

2 years agoProvide log_status_format(), useful for an emit_log_hook.
Jeff Davis [Mon, 11 Jul 2022 19:29:33 +0000 (12:29 -0700)]
Provide log_status_format(), useful for an emit_log_hook.

Refactor so that log_line_prefix() is a thin wrapper over a new
function log_status_format(), and move the implementation to the
latter. Export log_status_format() so that it can be used by an
emit_log_hook.

Discussion: https://postgr.es/m/39c8197652f4d3050aedafae79fa5af31096505f.camel%40j-davis.com
Reviewed-by: Michael Paquier, Alvaro Herrera
2 years agoRationalize order of input files for gen_node_support.pl.
Tom Lane [Mon, 11 Jul 2022 17:38:40 +0000 (13:38 -0400)]
Rationalize order of input files for gen_node_support.pl.

Per a question from Andres Freund.  While here, also make the
list of nodetag-only files easier to compare to the full list
of input files.

Discussion: https://postgr.es/m/20220710214622.haiektrjzisob6rl@awork3.anarazel.de

2 years agoFix mistake in comment.
Robert Haas [Mon, 11 Jul 2022 17:32:23 +0000 (13:32 -0400)]
Fix mistake in comment.

Kyotaro Horiguchi

Discussion: http://postgr.es/m/20220708.145951.382076151410075693.horikyota.ntt@gmail.com

2 years agoConvert macros to static inline functions (bufpage.h)
Peter Eisentraut [Mon, 11 Jul 2022 05:20:35 +0000 (07:20 +0200)]
Convert macros to static inline functions (bufpage.h)

Remove PageIsValid() and PageSizeIsValid(), which weren't used and
seem unnecessary.

Some code using these formerly-macros needs some adjustments because
it was previously playing loose with the Page vs. PageHeader types,
which is no longer possible with the functions instead of macros.

Reviewed-by: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com

2 years agoFix lock assertions in dshash.c.
Thomas Munro [Mon, 11 Jul 2022 02:47:16 +0000 (14:47 +1200)]
Fix lock assertions in dshash.c.

dshash.c previously maintained flags to be able to assert that you
didn't hold any partition lock.  These flags could get out of sync with
reality in error scenarios.

Get rid of all that, and make assertions about the locks themselves
instead.  Since LWLockHeldByMe() loops internally, we don't want to put
that inside another loop over all partition locks.  Introduce a new
debugging-only interface LWLockAnyHeldByMe() to avoid that.

This problem was noted by Tom and Andres while reviewing changes to
support the new shared memory stats system, and later showed up in
reality while working on commit 389869af.

Back-patch to 11, where dshash.c arrived.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Reviewed-by: Zhihong Yu <zyu@yugabyte.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20220311012712.botrpsikaufzteyt@alap3.anarazel.de
Discussion: https://postgr.es/m/CA%2BhUKGJ31Wce6HJ7xnVTKWjFUWQZPBngxfJVx4q0E98pDr3kAw%40mail.gmail.com

2 years agoBuild de-escaped JSON strings in larger chunks during lexing
John Naylor [Fri, 1 Jul 2022 10:28:20 +0000 (17:28 +0700)]
Build de-escaped JSON strings in larger chunks during lexing

During COPY BINARY with large JSONB blobs, it was found that half
the time was spent parsing JSON, with much of that spent in separate
appendStringInfoChar() calls for each input byte.

Add lookahead loop to json_lex_string() to allow batching multiple bytes
via appendBinaryStringInfo(). Also use this same logic when de-escaping
is not done, to avoid code duplication.

Report and proof of concept patch by Jelte Fennema, reworked by Andres
Freund and John Naylor

Discussion: https://www.postgresql.org/message-id/CAGECzQQuXbies_nKgSiYifZUjBk6nOf2%3DTSXqRjj2BhUh8CTeA%40mail.gmail.com
Discussion: https://www.postgresql.org/message-id/flat/PR3PR83MB0476F098CBCF68AF7A1CA89FF7B49@PR3PR83MB0476.EURPRD83.prod.outlook.com

2 years agoFix two portability issues with the tests of test_oat_hooks
Michael Paquier [Mon, 11 Jul 2022 03:47:52 +0000 (12:47 +0900)]
Fix two portability issues with the tests of test_oat_hooks

This addresses two issues in the tests of test_oat_hooks:
- The role regress_test_user was being left behind, preventing the test
to succeed on repeated runs.  It makes sense to leave some objects
behind to have more coverage for pg_upgrade (as does test_pg_dump), but
the role dropped here does not own any objects so there is no reason to
keep it.
- GRANT SET ON PARAMETER is issued, creating an entry in
pg_parameter_acl without cleaning up the entry created.  This causes
an overlap with unsafe_tests as both use work_mem, making the latter
fail.  This commit adds an extra REVOKE SET ON PARAMETER to clean the
contents of pg_parameter_acl, switching to maintenance_work_mem rather
than work_mem to avoid an overlap between both tests.

The tests of test_oat_hooks cannot use installcheck yet as these are
proving to be unstable with caching and the namespace search hooks, so
the issues fixed here cannot be reached yet, but they would be once the
hook issue is addressed and installcheck is allowed again in
test_oat_hooks.

Discussion: https://postgr.es/m/YrpVkADAY0knF6vM@paquier.xyz
Backpatch-through: 15

2 years agoImprove error message with JSON_SERIALIZE()
Michael Paquier [Mon, 11 Jul 2022 02:20:15 +0000 (11:20 +0900)]
Improve error message with JSON_SERIALIZE()

The error message introduced in 3c633f3 can share the same format string
with an existing message used for JSON(), reducing the translation
effort.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20220708.154135.2123613118233840495.horikyota.ntt@gmail.com
Backpatch-through: 15

2 years agoImprove two comments related to a boolean DefElem's value
Michael Paquier [Mon, 11 Jul 2022 02:07:33 +0000 (11:07 +0900)]
Improve two comments related to a boolean DefElem's value

The original comments mentioned a "parameter" as something not defined
in a fast-exit path to assume a true status.  This is rather confusing
as the parameter DefElem is defined, and the intention is to check if
its value is defined.  This improves both comments to mention the value
assigned to the DefElem's value instead, so as future patches are able
to catch the tweak if this code pattern gets copied around more.

Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+Pv0yWynWTmp4o34s0d98xVubys9fy=p0YXsZ5_sUcNnMw@mail.gmail.com

2 years agodoc: Fix inconsistent quotes in some jsonb fields
Michael Paquier [Mon, 11 Jul 2022 01:56:17 +0000 (10:56 +0900)]
doc: Fix inconsistent quotes in some jsonb fields

Single quotes are not allowed in json internals, double quotes are.

Reported-by: Eric Mutta
Discussion: https://postgr.es/m/165715362165.665.3875113264927503997@wrigleys.postgresql.org
Backpatch-through: 14

2 years agoTidy up claimed supported CPUs and OSes.
Thomas Munro [Sun, 10 Jul 2022 23:50:41 +0000 (11:50 +1200)]
Tidy up claimed supported CPUs and OSes.

 * Remove arbitrary mention of certain endianness and bitness variants;
   it's enough to say that applicable variants are expected to work.
 * List RISC-V (known to work, being tested).
 * List SuperH and M88K (code exists, unknown status, like M68K).
 * De-list VAX and remove code (known not to work).
 * Remove stray trace of Alpha (support was removed years ago).
 * List illumos, DragonFlyBSD (known to work, being tested).
 * No need to single Windows out by listing a specific version, when we
   don't do that for other OSes; it's enough to say that we support
   current versions of the listed OSes (when 16 ships, that'll be
   Windows 10+).

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Greg Stark <stark@mit.edu>
Discussion: https://postgr.es/m/CA%2BhUKGKk7NZO1UnJM0PyixcZPpCGqjBXW_0bzFZpJBGAf84XKg%40mail.gmail.com

2 years agoFix \watch's interaction with libedit on ^C.
Thomas Munro [Sun, 10 Jul 2022 04:30:03 +0000 (16:30 +1200)]
Fix \watch's interaction with libedit on ^C.

When you hit ^C, the terminal driver in Unix-like systems echoes "^C" as
well as sending an interrupt signal (depending on stty settings).  At
least libedit (but maybe also libreadline) is then confused about the
current cursor location, and corrupts the display if you try to scroll
back.  Fix, by moving to a new line before the next prompt is displayed.

Back-patch to all supported released.

Author: Pavel Stehule <pavel.stehule@gmail.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3278793.1626198638%40sss.pgh.pa.us

2 years agoExclude nodetags.h from headerscheck and cpluspluscheck.
Tom Lane [Sat, 9 Jul 2022 23:25:53 +0000 (19:25 -0400)]
Exclude nodetags.h from headerscheck and cpluspluscheck.

Since this file contains just a fragment of an enum declaration,
it can't be compiled on its own.

2 years agoMake assorted quality-of-life improvements in gen_node_support.pl.
Tom Lane [Sat, 9 Jul 2022 19:15:05 +0000 (15:15 -0400)]
Make assorted quality-of-life improvements in gen_node_support.pl.

Fix incorrect reporting of the location of errors (such as bogus
node attributes).  Add header comments to the generated files,
containing copyright notices and reminders that they are generated
files, as we do in other file-generating scripts.  Arrange to not
leave a clutter of temporary files when the script detects an error.

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

2 years agoDoc: rearrange high-level commentary about node support coverage.
Tom Lane [Sat, 9 Jul 2022 19:10:15 +0000 (15:10 -0400)]
Doc: rearrange high-level commentary about node support coverage.

copyfuncs.c and friends no longer seem like great places to put
high-level remarks about what's covered and what isn't.  Move that
material to backend/nodes/README and other more-prominent places.
Add back (versions of) some remarks that disappeared in 2be87f092.

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

2 years agoMark Scan as an abstract node type, too.
Tom Lane [Sat, 9 Jul 2022 17:58:06 +0000 (13:58 -0400)]
Mark Scan as an abstract node type, too.

On further review, this one is never instantiated either.

2 years agoMark PlanState as an abstract node type.
Tom Lane [Sat, 9 Jul 2022 17:35:37 +0000 (13:35 -0400)]
Mark PlanState as an abstract node type.

In the same vein as commit 251154beb, make it clear that we never
instantiate PlanState.

Also mark MemoryContextData as abstract.  This has no effect right now,
since memnodes.h isn't one of the files fed to gen_node_support.pl.
But it seems like good documentation and future-proofing.

2 years agoRemove code sections obsoleted by node support automation
Peter Eisentraut [Sat, 9 Jul 2022 13:06:01 +0000 (15:06 +0200)]
Remove code sections obsoleted by node support automation

This removes the code sections that were ifdef'ed out by
964d01ae90c314eb31132c2e7712d5d9fc237331.

2 years agoMove a comment
Peter Eisentraut [Sat, 9 Jul 2022 11:22:46 +0000 (13:22 +0200)]
Move a comment

Move a comment from the to-be-deleted section of nodes.h to where it
might still be useful.

2 years agoAdd generated nodes\nodetags.h to clean.bat
Peter Eisentraut [Sat, 9 Jul 2022 08:20:54 +0000 (10:20 +0200)]
Add generated nodes\nodetags.h to clean.bat

2 years agoInstall generated nodes/nodetags.h
Peter Eisentraut [Sat, 9 Jul 2022 08:20:23 +0000 (10:20 +0200)]
Install generated nodes/nodetags.h

2 years agoFix vpath build
Peter Eisentraut [Sat, 9 Jul 2022 07:44:09 +0000 (09:44 +0200)]
Fix vpath build

2 years agoAutomatically generate node support functions
Peter Eisentraut [Sat, 9 Jul 2022 06:52:19 +0000 (08:52 +0200)]
Automatically generate node support functions

Add a script to automatically generate the node support functions
(copy, equal, out, and read, as well as the node tags enum) from the
struct definitions.

For each of the four node support files, it creates two include files,
e.g., copyfuncs.funcs.c and copyfuncs.switch.c, to include in the main
file.  All the scaffolding of the main file stays in place.

I have tried to mostly make the coverage of the output match what is
currently there.  For example, one could now do out/read coverage of
utility statement nodes, but I have manually excluded those for now.
The reason is mainly that it's easier to diff the before and after,
and adding a bunch of stuff like this might require a separate
analysis and review.

Subtyping (TidScan -> Scan) is supported.

For the hard cases, you can just write a manual function and exclude
generating one.  For the not so hard cases, there is a way of
annotating struct fields to get special behaviors.  For example,
pg_node_attr(equal_ignore) has the field ignored in equal functions.

(In this patch, I have only ifdef'ed out the code to could be removed,
mainly so that it won't constantly have merge conflicts.  It will be
deleted in a separate patch.  All the code comments that are worth
keeping from those sections have already been moved to the header
files where the structs are defined.)

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/c1097590-a6a4-486a-64b1-e1f9cc0533ce%40enterprisedb.com

2 years agodoc: add examples for array_length() and jsonb_array_length()
Bruce Momjian [Sat, 9 Jul 2022 00:23:35 +0000 (20:23 -0400)]
doc:  add examples for array_length() and jsonb_array_length()

The examples show the output of array_length() and jsonb_array_length()
for empty arrays.

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

Author: David G. Johnston

Backpatch-through: 13

2 years agodoc: add pg_prewarm example
Bruce Momjian [Fri, 8 Jul 2022 22:36:27 +0000 (18:36 -0400)]
doc:  add pg_prewarm example

Discussion: https://postgr.es/m/20220618085541.ezxdaljlpo6x7msc@home-desktop

Author: Dong Wook Lee

Backpatch-through: 11

2 years agoAdd missing inequality searches to rbtree
Alexander Korotkov [Fri, 8 Jul 2022 18:51:26 +0000 (21:51 +0300)]
Add missing inequality searches to rbtree

PostgreSQL contains the implementation of the red-black tree.  The red-black
tree is the ordered data structure, and one of its advantages is the ability
to do inequality searches.  This commit adds rbt_find_less() and
rbt_find_great() functions implementing these searches.  While these searches
aren't yet used in the core code, they might be useful for extensions.

Discussion: https://postgr.es/m/CAGRrpzYE8-7GCoaPjOiL9T_HY605MRax-2jgTtLq236uksZ1Sw%40mail.gmail.com
Author: Steve Chavez, Alexander Korotkov
Reviewed-by: Alexander Korotkov
2 years agoUse C99 designator in the rbtree sentinel definition
Alexander Korotkov [Fri, 8 Jul 2022 18:51:00 +0000 (21:51 +0300)]
Use C99 designator in the rbtree sentinel definition

This change should improve the code readability.

Discussion: https://postgr.es/m/CAGRrpzYE8-7GCoaPjOiL9T_HY605MRax-2jgTtLq236uksZ1Sw%40mail.gmail.com
Author: Steve Chavez, Alexander Korotkov
Reviewed-by: Alexander Korotkov
2 years agoPreserve relfilenode of pg_largeobject and its index across pg_upgrade.
Robert Haas [Fri, 8 Jul 2022 14:15:19 +0000 (10:15 -0400)]
Preserve relfilenode of pg_largeobject and its index across pg_upgrade.

Commit 9a974cbcba005256a19991203583a94b4f9a21a9 did this for user
tables, but pg_upgrade treats pg_largeobject as a user table, and so
needs the same treatment. Without this fix, if you rewrite the
pg_largeobject table and then perform an upgrade with pg_upgrade, the
table will apparently be empty on the new cluster, while all of your
objects will end up with an orphaned file.

With this fix, instead of the old cluster's pg_largeobject files ending
up orphaned, the original files fro the new cluster do. That's mostly
harmless because we expect the table to be empty, but we might want
to arrange to remove the as part of the upgrade. Since we're still
debating the best way of doing that, I (rhaas) have decided to postpone
dealing with that problem and get the basic fix committed.

Justin Pryzby, reviewed by Shruthi Gowda and by me.

Discussion: http://postgr.es/m/20220701231413.GI13040@telsasoft.com

2 years agoAdjust node serialization tag of A_Expr for consistency
Peter Eisentraut [Fri, 8 Jul 2022 09:03:45 +0000 (11:03 +0200)]
Adjust node serialization tag of A_Expr for consistency

Changed from AEXPR to A_EXPR for consistency.

Discussion: https://www.postgresql.org/message-id/2592455.1657140387%40sss.pgh.pa.us

2 years agoRemove T_Join and T_Plan
Peter Eisentraut [Fri, 8 Jul 2022 08:38:02 +0000 (10:38 +0200)]
Remove T_Join and T_Plan

These are abstract node types that don't need to have a node tag
defined.

Discussion: https://www.postgresql.org/message-id/2592455.1657140387%40sss.pgh.pa.us

2 years agoSimplify json lexing state
John Naylor [Fri, 8 Jul 2022 07:53:20 +0000 (14:53 +0700)]
Simplify json lexing state

Instead of updating the length as we go, use a const pointer to end of
the input, which we know already at the start.

This simplifies the coding and may improve performance slightly, but
the real motivation for doing this is to make further changes in this
area easier to reason about.

Discussion: https://www.postgresql.org/message-id/CAFBsxsGhaR2KQ5eisaK%3D6Vm60t%3DaxhD8Ckj1qFoCH1pktZi%2B2w%40mail.gmail.com

2 years agoReformat some more node comments
Peter Eisentraut [Fri, 8 Jul 2022 07:22:27 +0000 (09:22 +0200)]
Reformat some more node comments

Reformat some more comments in node field definitions to avoid long
lines.  Similar to 835d476fd21bcfb60b055941dee8c3d9559af14c, based on
additional per-field annotations that will be required.

Discussion: https://www.postgresql.org/message-id/c5906b07-220a-a3d4-8ff3-8ee593009424@enterprisedb.com

2 years agoRemove HP/Intel Itanium support.
Thomas Munro [Thu, 7 Jul 2022 23:21:46 +0000 (11:21 +1200)]
Remove HP/Intel Itanium support.

This CPU architecture has been discontinued.  We already removed HP-UX
support, we never supported Windows/Itanium, and the open source
operating systems that a vintage hardware owner might hope to run have
all either ended Itanium support or never fully released support (NetBSD
may eventually).  The extra code we carry for this rare ISA is now
untested.  It seems like a good time to remove it.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/1415825.1656893299%40sss.pgh.pa.us

2 years agoRemove HP-UX port.
Thomas Munro [Thu, 7 Jul 2022 23:17:47 +0000 (11:17 +1200)]
Remove HP-UX port.

HP-UX hardware is no longer produced, build farm coverage recently
ended, and there are no known active maintainers targeting this OS.
Since there is a major rewrite of the build system in the pipeline for
PostgreSQL 16, and that requires development, testing and maintainance
for each OS and tool chain, it seems like a good time to drop support
for:

 * HP-UX, the operating system.
 * HP aCC, the HP-UX native compiler.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/1415825.1656893299%40sss.pgh.pa.us

2 years agoOnly allow returning string types or bytea from json_serialize
Andrew Dunstan [Thu, 7 Jul 2022 21:40:02 +0000 (17:40 -0400)]
Only allow returning string types or bytea from json_serialize

These are documented to be the allowed types for the RETURNING clause,
but the restriction was not being enforced, which caused a segfault if
another type was specified. Add some testing for this.

Per report from a.kozhemyakin

Backpatch to release 15.

2 years agoRemove stray references to lefttree/righttree in the executor.
Tom Lane [Thu, 7 Jul 2022 15:23:40 +0000 (11:23 -0400)]
Remove stray references to lefttree/righttree in the executor.

The general convention in the executor is to refer to child plans
and planstates via the outerPlan[State] and innerPlan[State]
macros, but a few places didn't do it like that.  For consistency
and readability, convert all the stragglers to use the macros.
(See also commit 40f42d2a3, which did some similar cleanup a few
years ago, but missed these cases.)

Richard Guo

Discussion: https://postgr.es/m/CAMbWs4-vYhh1xsa_veah4PUed2Xq=Ed_YH3=Mqt5A3Y=EgfCEg@mail.gmail.com

2 years agoAdd checkpoint and REDO LSN to log_checkpoints message.
Fujii Masao [Thu, 7 Jul 2022 13:37:54 +0000 (22:37 +0900)]
Add checkpoint and REDO LSN to log_checkpoints message.

It is useful for debugging purposes to report the checkpoint LSN and
REDO LSN in log_checkpoints message. It can give more context while
analyzing checkpoint-related issues. pg_controldata reports the last
checkpoint LSN and REDO LSN, but having this information alongside
the log message helps analyze issues that happened previously,
connect the dots and identify the root cause.

Author: Bharath Rupireddy, Kyotaro Horiguchi
Reviewed-by: Michael Paquier, Julien Rouhaud, Nathan Bossart, Fujii Masao, Greg Stark
Discussion: https://postgr.es/m/CALj2ACWt6kqriAHrO+AJj+OmP=suwbktHT5JoYAn-nqZe2gd2g@mail.gmail.com

2 years agoFix alias matching in transformLockingClause().
Dean Rasheed [Thu, 7 Jul 2022 12:08:08 +0000 (13:08 +0100)]
Fix alias matching in transformLockingClause().

When locking a specific named relation for a FOR [KEY] UPDATE/SHARE
clause, transformLockingClause() finds the relation to lock by
scanning the rangetable for an RTE with a matching eref->aliasname.
However, it failed to account for the visibility rules of a join RTE.

If a join RTE doesn't have a user-supplied alias, it will have a
generated eref->aliasname of "unnamed_join" that is not visible as a
relation name in the parse namespace. Such an RTE needs to be skipped,
otherwise it might be found in preference to a regular base relation
with a user-supplied alias of "unnamed_join", preventing it from being
locked.

In addition, if a join RTE doesn't have a user-supplied alias, but
does have a join_using_alias, then the RTE needs to be matched using
that alias rather than the generated eref->aliasname, otherwise a
misleading "relation not found" error will be reported rather than a
"join cannot be locked" error.

Backpatch all the way, except for the second part which only goes back
to 14, where JOIN USING aliases were added.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCUY_KOBnqxbTSPf=7fz9HWPnZ5Xgb9SwYzZ8rFXe7nb=w@mail.gmail.com

2 years agopostgres_fdw: Fix grammar.
Etsuro Fujita [Thu, 7 Jul 2022 07:25:00 +0000 (16:25 +0900)]
postgres_fdw: Fix grammar.

Oversight in commit 4036bcbbb; back-patch to v15 where that appeared.

2 years agoConvert macros to static inline functions (block.h)
Peter Eisentraut [Thu, 7 Jul 2022 06:30:52 +0000 (08:30 +0200)]
Convert macros to static inline functions (block.h)

Remove BlockIdIsValid(), which wasn't used and is unnecessary.

Remove BlockIdCopy(), which wasn't used and can be done by struct
assignment.

(BlockIdEquals() also isn't used, but seems reasonable to keep
around.)

Reviewed-by: Amul Sul <sulamul@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com

2 years agoMake Windows 10 the minimal runtime requirement for WIN32
Michael Paquier [Thu, 7 Jul 2022 04:25:45 +0000 (13:25 +0900)]
Make Windows 10 the minimal runtime requirement for WIN32

This commit bumps the runtime value of _WIN32_WINNT to be 0x0A00 for any
builds on Windows.  Hence, this makes Windows 10 the minimal requirement
when running PostgreSQL under WIN32, be it for builds of Cygwin, MinGW
or Visual Studio.

The previous minimal runtime version was either Windows Vista when
building with at least Visual Studio 2015 or Windows XP for the rest.

Windows 10 is the most modern version supported by Microsoft, and per
discussion, as we don't have buildfarm members that run older versions
anymore, this is the minimal supported version that suits better for our
needs.  This will actually make easier the development of some patches,
two being async I/O and large page handling by avoiding a lot of
compatibility gotchas, on platforms that have most likely few users
anyway.

It is possible to remove MIN_WINNT in win32.h and the macros
IsWindowsXXXOrGreater() that were used in the code at runtime to check
which version of Windows was getting used.  The change in pg_locale.c
comes from Juan.  Note that all my tests passed, and that the CI is
green.  The buildfarm will quickly tell if this needs more adjustments.

Author: Michael Paquier, Juan José Santamaría Flecha
Reviewed-by: Thomas Munro
Discussion: https://postgr.es/m/Yo7tHKD8VCkeNi71@paquier.xyz

2 years agoRe-order disable_on_error in tab-complete.
Amit Kapila [Thu, 7 Jul 2022 03:30:27 +0000 (09:00 +0530)]
Re-order disable_on_error in tab-complete.

By convention, the tab-complete subscription parameters are listed in the
COMPLETE_WITH lists in alphabetical order, but when the "disable_on_error"
parameter was introduced this was not done.

This patch just tidies that up.

Reported-by: Peter Smith
Author: Peter Smith
Reviewed-by: Euler Taveira, Takamichi Osumi
Backpatch-through: 15, where it was introduced
Discussion: https://postgr.es/m/CAHut+PucvKZgg_eJzUW--iL6DXHg1Jwj6F09tQziE3kUF67uLg@mail.gmail.com

2 years agoClean up some includes and comments in TAP test scripts
Michael Paquier [Thu, 7 Jul 2022 01:13:01 +0000 (10:13 +0900)]
Clean up some includes and comments in TAP test scripts

A few tests included File::Path::rmtree without using it, and a comment
related to the segment size for replication slot limits was wrong.

Author: Pavel Borisov, Bharath Rupireddy
Reviewed-by: Maxim Orlov
Discussion: https://postgr.es/m/CALj2ACU4-aNLX=DrUM8F7QDwynJKzYRiqOj_33NhnGbhDs5-kQ@mail.gmail.com

2 years agopgstat: slru: remove outdated comment
Andres Freund [Wed, 6 Jul 2022 22:50:38 +0000 (15:50 -0700)]
pgstat: slru: remove outdated comment

That comment might have been true at some point during development, but
definitely isn't anymore.

Reported-By: Melanie Plageman <melanieplageman@gmail.com>
Backpatch: 15-

2 years agoFix wrong field order in _readMergeWhenClause().
Tom Lane [Wed, 6 Jul 2022 21:26:27 +0000 (17:26 -0400)]
Fix wrong field order in _readMergeWhenClause().

We hadn't noticed this because it's dead code: there is no
situation where we read raw parse trees from text format.
So maybe the right fix is to remove the function altogether,
but I'll forbear for now; it's not the only dead code in
readfuncs.c, I think.

Noted while comparing existing code to the results of
Peter's auto-generation script.

2 years agoOverload index_form_tuple to allow the memory context to be supplied
David Rowley [Wed, 6 Jul 2022 20:14:00 +0000 (08:14 +1200)]
Overload index_form_tuple to allow the memory context to be supplied

40af10b57 changed things so we make use of a generation memory context for
storing tuples to be sorted by tuplesort.c. That change does not play
nicely with the changes made in 9f03ca915 (back in 2014). That commit
changed things so that index_form_tuple() is called while switched into
the tuplestore's tuplecontext. In order to fetch the tuple from the index,
index_form_tuple() must do various memory allocations which are unrelated
to the storage of the final returned tuple. Although all of these
allocations are pfree'd, the fact that we now use a generation context
means that the memory for these pfree'd allocations won't be used again by
any other allocation due to generation.c's lack of freelists.  This could
result in sorts used for building indexes exceeding maintenance_work_mem
by a very large amount.

Here we fix it so we no longer allocate anything apart from the tuple
itself into the generation context by adding a new version of
index_form_tuple named index_form_tuple_context, which can be called to
specify the MemoryContext to allocate the tuple into.

Discussion: https://postgr.es/m/CAApHDvrHQkiFRHiGiAS-LMOvJN-eK-s762=tVzBz8ZqUea-a_A@mail.gmail.com
Backpatch-through: 15, where 40af10b57 was added.

2 years agopg_stat_statements: Fix test that assumes wal_records = rows.
Robert Haas [Wed, 6 Jul 2022 17:05:51 +0000 (13:05 -0400)]
pg_stat_statements: Fix test that assumes wal_records = rows.

It's not very robust to assume that each inserted row will produce
exactly one WAL record and that no other WAL records will be generated
in the process, because for example a particular transaction could
always be the one that has to extend clog.

Because these tests are not run by 'make installcheck' but only by
'make check', it may be that in our current testing infrastructure
this can't be hit, but it doesn't seem like a good idea to rely on
that, since unrelated changes to the regression tests or the way
write-ahead logging is done could easily cause it to start happening,
and debugging such failures is a pain.

Adjust the regression test to be less sensitive.

Anton Melnikov, reviewed by Julien Rouhaud

Discussion: http://postgr.es/m/1ccd00d9-1723-6b68-ae56-655aab00d406@inbox.ru

2 years agopgstat: drop subscription stats without slot as well, fix comment
Andres Freund [Wed, 6 Jul 2022 15:53:25 +0000 (08:53 -0700)]
pgstat: drop subscription stats without slot as well, fix comment

There's no reason anymore to only drop subscription stats if associated with a
slot, now that stats drops are transactional. And since there's now no other
cleanup of stats, this would lead to stats for slot-less subscriptions to get
leaked (however most slot-less subs won't have stats).

Additionally, the comment referring to autovacuum cleaning up stats was
clearly outdated.

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/CAD21AoAwiby3HeJE7vJe16Gr75RFfJ640dyHqvsiUhyKJTXPtw@mail.gmail.com
Backpatch: 15-

2 years agoChange internal RelFileNode references to RelFileNumber or RelFileLocator.
Robert Haas [Wed, 6 Jul 2022 15:39:09 +0000 (11:39 -0400)]
Change internal RelFileNode references to RelFileNumber or RelFileLocator.

We have been using the term RelFileNode to refer to either (1) the
integer that is used to name the sequence of files for a certain relation
within the directory set aside for that tablespace/database combination;
or (2) that value plus the OIDs of the tablespace and database; or
occasionally (3) the whole series of files created for a relation
based on those values. Using the same name for more than one thing is
confusing.

Replace RelFileNode with RelFileNumber when we're talking about just the
single number, i.e. (1) from above, and with RelFileLocator when we're
talking about all the things that are needed to locate a relation's files
on disk, i.e. (2) from above. In the places where we refer to (3) as
a relfilenode, instead refer to "relation storage".

Since there is a ton of SQL code in the world that knows about
pg_class.relfilenode, don't change the name of that column, or of other
SQL-facing things that derive their name from it.

On the other hand, do adjust closely-related internal terminology. For
example, the structure member names dbNode and spcNode appear to be
derived from the fact that the structure itself was called RelFileNode,
so change those to dbOid and spcOid. Likewise, various variables with
names like rnode and relnode get renamed appropriately, according to
how they're being used in context.

Hopefully, this is clearer than before. It is also preparation for
future patches that intend to widen the relfilenumber fields from its
current width of 32 bits. Variables that store a relfilenumber are now
declared as type RelFileNumber rather than type Oid; right now, these
are the same, but that can now more easily be changed.

Dilip Kumar, per an idea from me. Reviewed also by Andres Freund.
I fixed some whitespace issues, changed a couple of words in a
comment, and made one other minor correction.

Discussion: http://postgr.es/m/CA+TgmoamOtXbVAQf9hWFzonUo6bhhjS6toZQd7HZ-pmojtAmag@mail.gmail.com
Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com
Discussion: http://postgr.es/m/CAFiTN-vTe79M8uDH1yprOU64MNFE+R3ODRuA+JWf27JbhY4hJw@mail.gmail.com

2 years agoRemove LLVM_CONFIG from Makefile.global.in
Andres Freund [Wed, 6 Jul 2022 15:11:39 +0000 (08:11 -0700)]
Remove LLVM_CONFIG from Makefile.global.in

LLVM_CONFIG is only used inside configure.

Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/0e81e45c-c9a5-e95b-2782-ab2dfec8bf57@enterprisedb.com

2 years agoTiny capitalization adjustment in pkg-config files
Peter Eisentraut [Wed, 6 Jul 2022 08:32:40 +0000 (10:32 +0200)]
Tiny capitalization adjustment in pkg-config files

This makes the output match that produced by meson (and also matches
other packages and pkg-config's own documentation better).

2 years agoRemove size increase in ExprEvalStep caused by hashed saops
David Rowley [Wed, 6 Jul 2022 07:40:32 +0000 (19:40 +1200)]
Remove size increase in ExprEvalStep caused by hashed saops

50e17ad28 increased the size of ExprEvalStep from 64 bytes up to 88 bytes.
Lots of effort was spent during the development of the current expression
evaluation code to make an instance of this struct as small as possible.
Making this struct larger than needed reduces CPU cache efficiency during
expression evaluation which causes noticeable slowdowns during query
execution.

In order to reduce the size of the struct, here we remove the fn_addr
field. The values from this field can be obtained via fcinfo, just with
some extra pointer dereferencing. The extra indirection does not seem to
cause any noticeable slowdowns.

Various other fields have been moved into the ScalarArrayOpExprHashTable
struct. These fields are only used when the ScalarArrayOpExprHashTable
pointer has already been dereferenced, so no additional pointer
dereferences occur for these. Here we also make hash_fcinfo_data the last
field in ScalarArrayOpExprHashTable so that we can avoid a further pointer
dereference to get the FunctionCallInfoBaseData. This also saves a call to
palloc().

50e17ad28 was added in 14, but it's too late to adjust the size of the
ExprEvalStep in that version, so here we just backpatch to 15, which is
currently in beta.

Author: Andres Freund, David Rowley
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Backpatch-through: 15

2 years agoRefactor sending of DataRow messages in replication protocol
Peter Eisentraut [Wed, 6 Jul 2022 06:28:02 +0000 (08:28 +0200)]
Refactor sending of DataRow messages in replication protocol

Some routines open-coded the construction of DataRow messages.  Use
TupOutputState struct and associated functions instead, which was
already done in some places.

SendTimeLineHistory() is a bit more complicated and isn't converted by
this.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/7e4fdbdc-699c-4cd0-115d-fb78a957fc22@enterprisedb.com

2 years agoUnify DLSUFFIX on Darwin
Peter Eisentraut [Wed, 6 Jul 2022 05:30:16 +0000 (07:30 +0200)]
Unify DLSUFFIX on Darwin

macOS has traditionally used extension .dylib for shared libraries
(used at build time) and .so for dynamically loaded modules (used by
dlopen()).  This complicates the build system a bit.  Also, Meson uses
.dylib for both, so it would be worth unifying this in order to be
able to get equal build output.

There doesn't appear to be any reason to use any particular extension
for dlopened modules, since dlopen() will accept anything and
PostgreSQL is well-factored to be able to deal with any extension.
Other software packages that I have handy appear to be about 50/50
split on which extension they use for their plugins.  So it seems
possible to change this safely.

Discussion: https://www.postgresql.org/message-id/flat/bcc45f78-e3c3-8fb3-7c42-5371b48b5266%40enterprisedb.com

2 years agoReorder ecpg_config.h.in alphabetically
Peter Eisentraut [Wed, 6 Jul 2022 05:16:46 +0000 (07:16 +0200)]
Reorder ecpg_config.h.in alphabetically

This makes it easier to maintain the order if we automate the
generation of this file.

2 years agoautho_explain: Add GUC to log query parameters
Michael Paquier [Wed, 6 Jul 2022 00:55:30 +0000 (09:55 +0900)]
autho_explain: Add GUC to log query parameters

auto_explain.log_parameter_max_length is a new GUC part of the
extension, similar to the corresponding core setting, that controls the
inclusion of query parameters in the logged explain output.

More tests are added to check the behavior of this new parameter: when
parameters logged in full (the default of -1), when disabled (value of
0) and when partially truncated (value different than the two others).

Author: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/87ee09mohb.fsf@wibble.ilmari.org

2 years agoTighten pg_upgrade's new check for non-upgradable anyarray usages.
Tom Lane [Tue, 5 Jul 2022 22:23:19 +0000 (18:23 -0400)]
Tighten pg_upgrade's new check for non-upgradable anyarray usages.

We only need to reject cases when the aggregate or operator is
itself declared with a polymorphic type.  Per buildfarm.

Discussion: https://postgr.es/m/3383880.QJadu78ljV@vejsadalnx

2 years agopgstat: reduce timer overhead by leaving timer running.
Andres Freund [Fri, 17 Jun 2022 19:48:34 +0000 (12:48 -0700)]
pgstat: reduce timer overhead by leaving timer running.

Previously the timer was enabled whenever there were any pending stats after
executing a statement, just to then be disabled again when not idle
anymore. That lead to an increase in GetCurrentTimestamp() calls from within
timeout.c compared to 14.

To avoid that increase, leave the timer enabled until stats are reported,
rather than until idle. The timer is only disabled once the pending stats have
been reported.

For me this fixes the increase in GetCurrentTimestamp() calls, there now are
fewer calls in 15 than in 14, in the previously slowed down workload.

While at it, also update assertion in pgstat_report_stat() to be more precise.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Backpatch: 15-

2 years agoexpression eval: Fix EEOP_JSON_CONSTRUCTOR and EEOP_JSONEXPR size.
Andres Freund [Fri, 17 Jun 2022 01:33:42 +0000 (18:33 -0700)]
expression eval: Fix EEOP_JSON_CONSTRUCTOR and EEOP_JSONEXPR size.

The new expression step types increased the size of ExprEvalStep by ~4 for all
types of expression steps, slowing down expression evaluation noticeably. Move
them out of line.

There's other issues with these expression steps, but addressing them is
largely independent of this aspect.

Author: Andres Freund <andres@anarazel.de>
Reviewed-By: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Backpatch: 15-

2 years agoRevert 019_replslot_limit.pl related debugging aids.
Andres Freund [Tue, 5 Jul 2022 18:01:10 +0000 (11:01 -0700)]
Revert 019_replslot_limit.pl related debugging aids.

This reverts most of 91c0570a791f28bf667f60fe0972ee5e6afdeff10526. The
only thing left is the retry loop in 019_replslot_limit.pl that avoids
spurious failures by retrying a couple times.

We haven't seen any hard evidence that this is caused by anything but slow
process shutdown. We did not find any cases where walsenders did not vanish
after waiting for longer. Therefore there's no reason for this debugging code
to remain.

Discussion: https://postgr.es/m/20220530190155.47wr3x2prdwyciah@alap3.anarazel.de
Backpatch: 15-

2 years agoRename pg_checkpointer predefined role to pg_checkpoint.
Robert Haas [Tue, 5 Jul 2022 17:31:42 +0000 (13:31 -0400)]
Rename pg_checkpointer predefined role to pg_checkpoint.

This is more consistent with how other predefined roles that confer
specific privileges are named.

Nathan Bosart

Discussion: http://postgr.es/m/CA+TgmoatH7+yYe+A8uJFNogg3VUDtFE6c-77yHAY8TRWR7oqyw@mail.gmail.com

2 years agoFix pg_upgrade to detect non-upgradable anyarray usages.
Tom Lane [Tue, 5 Jul 2022 17:06:31 +0000 (13:06 -0400)]
Fix pg_upgrade to detect non-upgradable anyarray usages.

When we changed some built-in functions to use anycompatiblearray
instead of anyarray, we created a dump/restore hazard for user-defined
operators and aggregates relying on those functions: the user objects
have to be modified to change their signatures similarly.  This causes
pg_upgrade to fail partway through if the source installation contains
such objects.  We generally try to have pg_upgrade detect such hazards
and fail before it does anything exciting, so add logic to detect
this case too.

Back-patch to v14 where the change was made.

Justin Pryzby, reviewed by Andrey Borodin

Discussion: https://postgr.es/m/3383880.QJadu78ljV@vejsadalnx

2 years agoFix errors in copyfuncs/equalfuncs support for JSON node types.
Tom Lane [Tue, 5 Jul 2022 15:12:33 +0000 (11:12 -0400)]
Fix errors in copyfuncs/equalfuncs support for JSON node types.

Noted while comparing existing code to the output of the proposed
patch to automate creation of these functions.  Some of the changes
are just cosmetic, but others represent real bugs.  I've not
attempted to analyze the user-visible impact.

Back-patch to v15 where this code came in.

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

2 years agolibpq: Improve idle state handling in pipeline mode
Alvaro Herrera [Tue, 5 Jul 2022 12:21:20 +0000 (14:21 +0200)]
libpq: Improve idle state handling in pipeline mode

We were going into IDLE state too soon when executing queries via
PQsendQuery in pipeline mode, causing several scenarios to misbehave in
different ways -- most notably, as reported by Daniele Varrazzo, that a
warning message is produced by libpq:
  message type 0x33 arrived from server while idle
But it is also possible, if queries are sent and results consumed not in
lockstep, for the expected mediating NULL result values from PQgetResult
to be lost (a problem which has not been reported, but which is more
serious).

Fix this by introducing two new concepts: one is a command queue element
PGQUERY_CLOSE to tell libpq to wait for the CloseComplete server
response to the Close message that is sent by PQsendQuery.  Because the
application is not expecting any PGresult from this, the mechanism to
consume it is a bit hackish.

The other concept, authored by Horiguchi-san, is a PGASYNC_PIPELINE_IDLE
state for libpq's state machine to differentiate "really idle" from
merely "the idle state that occurs in between reading results from the
server for elements in the pipeline".  This makes libpq not go fully
IDLE when the libpq command queue contains entries; in normal cases, we
only go IDLE once at the end of the pipeline, when the server response
to the final SYNC message is received.  (However, there are corner cases
it doesn't fix, such as terminating the query sequence by
PQsendFlushRequest instead of PQpipelineSync; this sort of scenario is
what requires PGQUERY_CLOSE bit above.)

This last bit helps make the libpq state machine clearer; in particular
we can get rid of an ugly hack in pqParseInput3 to avoid considering
IDLE as such when the command queue contains entries.

A new test mode is added to libpq_pipeline.c to tickle some related
problematic cases.

Reported-by: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Co-authored-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/CA+mi_8bvD0_CW3sumgwPvWdNzXY32itoG_16tDYRu_1S2gV2iw@mail.gmail.com

2 years agoBRIN: improve documentation on summarization
Alvaro Herrera [Tue, 5 Jul 2022 11:38:26 +0000 (13:38 +0200)]
BRIN: improve documentation on summarization

The existing wording wasn't clear enough and some details weren't
anywhere, such as the fact that autosummarization is off by default.
Improve.

Authors: Roberto Mello, Jaime Casanova, Justin Pryzby, Álvaro Herrera
Discussion: https://postgr.es/m/CAKz==bK_NoJytRyQfX8K-erCW3Ff7--oGYpiB8+ePVS7dRVW_A@mail.gmail.com
Discussion: https://postgr.es/m/20220224193520.GY9008@telsasoft.com

2 years agoFix pg_prepared_statements.result_types for DML statements
Peter Eisentraut [Tue, 5 Jul 2022 08:26:36 +0000 (10:26 +0200)]
Fix pg_prepared_statements.result_types for DML statements

Amendment to 84ad713cf85aeffee5dd39f62d49a1b9e34632da: Not all
prepared statements have a result descriptor.  As currently coded,
this would crash when reading pg_prepared_statements.  Make those
cases return null for result_types instead.  Also add a test case for
it.

2 years agoSimplify a bit the special rules generating unaccent.rules
Michael Paquier [Tue, 5 Jul 2022 07:17:51 +0000 (16:17 +0900)]
Simplify a bit the special rules generating unaccent.rules

As noted by Thomas Munro, CLDR 36 has added SOUND RECORDING COPYRIGHT
(U+2117), and we use CLDR 41, so this can be removed from the set of
special cases.

The set of regression tests is expanded for degree signs, which are two
of the special cases, and a fancy case with U+210C in Latin-ASCII.xml
that we have discovered about when diving into what could be done for
Cyrillic characters (this last part is material for a future patch, not
tackled yet).

While on it, some of the assertions of generate_unaccent_rules.py are
expanded to report the codepoint on which a failure is found, something
useful for debugging.

Extracted from a larger patch by the same author.

Author: Przemysław Sztoch
Discussion: https://postgr.es/m/8478da0d-3b61-d24f-80b4-ce2f5e971c60@sztoch.pl

2 years agoAdd result_types column to pg_prepared_statements view
Peter Eisentraut [Tue, 5 Jul 2022 05:21:40 +0000 (07:21 +0200)]
Add result_types column to pg_prepared_statements view

Containing the types of the columns returned by the prepared
statement.

Prompted by question from IRC user mlvzk.

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/871qwpo7te.fsf@wibble.ilmari.org

2 years agoRemove durable_rename_excl()
Michael Paquier [Tue, 5 Jul 2022 03:54:25 +0000 (12:54 +0900)]
Remove durable_rename_excl()

A previous commit replaced all the calls to this function with
durable_rename() as of dac1ff3, making it used nowhere in the tree.
Using it in extension code is also risky based on the issues described
in this previous commit, so let's remove it.  This makes possible the
removal of HAVE_WORKING_LINK.

Author: Nathan Bossart
Reviewed-by: Robert Haas, Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20220407182954.GA1231544@nathanxps13

2 years agoReplace durable_rename_excl() by durable_rename(), take two
Michael Paquier [Tue, 5 Jul 2022 01:16:12 +0000 (10:16 +0900)]
Replace durable_rename_excl() by durable_rename(), take two

durable_rename_excl() attempts to avoid overwriting any existing files
by using link() and unlink(), and it falls back to rename() on some
platforms (aka WIN32), which offers no such overwrite protection.  Most
callers use durable_rename_excl() just in case there is an existing
file, but in practice there shouldn't be one (see below for more
details).

Furthermore, failures during durable_rename_excl() can result in
multiple hard links to the same file.  As per Nathan's tests, it is
possible to end up with two links to the same file in pg_wal after a
crash just before unlink() during WAL recycling.  Specifically, the test
produced links to the same file for the current WAL file and the next
one because the half-recycled WAL file was re-recycled upon restarting,
leading to WAL corruption.

This change replaces all the calls of durable_rename_excl() to
durable_rename().  This removes the protection against accidentally
overwriting an existing file, but some platforms are already living
without it and ordinarily there shouldn't be one.  The function itself
is left around in case any extensions are using it.  It will be removed
on HEAD via a follow-up commit.

Here is a summary of the existing callers of durable_rename_excl() (see
second discussion link at the bottom), replaced by this commit.  First,
basic_archive used it to avoid overwriting an archive concurrently
created by another server, but as mentioned above, it will still
overwrite files on some platforms.  Second, xlog.c uses it to recycle
past WAL segments, where an overwrite should not happen (origin of the
change at f0e37a8) because there are protections about the WAL segment
to select when recycling an entry.  The third and last area is related
to the write of timeline history files.  writeTimeLineHistory() will
write a new timeline history file at the end of recovery on promotion,
so there should be no such files for the same timeline.
What remains is writeTimeLineHistoryFile(), that can be used in parallel
by a WAL receiver and the startup process, and some digging of the
buildfarm shows that EEXIST from a WAL receiver can happen with an error
of "could not link file \"pg_wal/xlogtemp.NN\" to \"pg_wal/MM.history\",
which would cause an automatic restart of the WAL receiver as it is
promoted to FATAL, hence this should improve the stability of the WAL
receiver as rename() would overwrite an existing TLI history file
already fetched by the startup process at recovery.

This is a bug fix, but knowing the unlikeliness of the problem involving
one or more crashes at an exceptionally bad moment, no backpatch is
done.  Also, I want to be careful with such changes (aaa3aed did the
opposite of this change by removing HAVE_WORKING_LINK so as Windows
would do a link() rather than a rename() but this was not
concurrent-safe).  A backpatch could be revisited in the future.  This
is the second time this change is attempted, ccfbd92 being the first
one, but this time no assertions are added for the case of a TLI history
file written concurrently by the WAL receiver or the startup process
because we can expect one to exist (some of the TAP tests are able to
trigger with a proper timing).

Author: Nathan Bossart
Reviewed-by: Robert Haas, Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/20220407182954.GA1231544@nathanxps13
Discussion: https://postgr.es/m/Ym6GZbqQdlalSKSG@paquier.xyz

2 years agoRefactor sending of RowDescription messages in replication protocol
Peter Eisentraut [Mon, 4 Jul 2022 05:25:26 +0000 (07:25 +0200)]
Refactor sending of RowDescription messages in replication protocol

Some routines open-coded the construction of RowDescription messages.
Instead, we have support for doing this using tuple descriptors and
DestRemoteSimple, so use that instead.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/7e4fdbdc-699c-4cd0-115d-fb78a957fc22@enterprisedb.com

2 years agoImplement List support for TransactionId
Alvaro Herrera [Mon, 4 Jul 2022 12:52:12 +0000 (14:52 +0200)]
Implement List support for TransactionId

Use it for RelationSyncEntry->streamed_txns, which is currently using an
integer list.

The API support is not complete, not because it is hard to write but
because it's unclear that it's worth the code space, there being so
little use of XID lists.

Discussion: https://postgr.es/m/202205130830.g5ntonhztspb@alvherre.pgsql
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
2 years agoPrevent write operations on large objects in read-only transactions
Michael Paquier [Mon, 4 Jul 2022 06:48:52 +0000 (15:48 +0900)]
Prevent write operations on large objects in read-only transactions

Attempting such an operation would already fail, but in various and
confusing ways.  For example, while in recovery, some elog() messages
would be reported, but these should never be user-facing.  This commit
restricts any write operations done on large objects in a read-only
context, so as the errors generated are more user-friendly.  This is per
the discussion done with Tom Lane and Robert Haas.

Some regression tests are added to check the case of all the SQL
functions working on large objects (including an update of the test's
alternate output).

Author: Yugo Nagata
Discussion: https://postgr.es/m/20220527153028.61a4608f66abcd026fd3806f@sraoss.co.jp

2 years agoFix for change timeline field of IDENTIFY_SYSTEM to int8
Peter Eisentraut [Mon, 4 Jul 2022 06:06:05 +0000 (08:06 +0200)]
Fix for change timeline field of IDENTIFY_SYSTEM to int8

Amendment to ec40f3422412cfdc140b5d3f67db7fd2dac0f1e2: We also need to
change the way the datum is supplied to int8.  Otherwise, the value is
still cut off as an int4, and it will crash on 32-bit platforms.

2 years agoChange timeline field of IDENTIFY_SYSTEM to int8
Peter Eisentraut [Mon, 4 Jul 2022 05:25:26 +0000 (07:25 +0200)]
Change timeline field of IDENTIFY_SYSTEM to int8

It was int4, but in the other replication commands, timelines are
returned as int8.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/7e4fdbdc-699c-4cd0-115d-fb78a957fc22@enterprisedb.com

2 years agoFix attlen in RowDescription of BASE_BACKUP response
Peter Eisentraut [Mon, 4 Jul 2022 05:25:26 +0000 (07:25 +0200)]
Fix attlen in RowDescription of BASE_BACKUP response

Should be 8 for int8, not -1.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/7e4fdbdc-699c-4cd0-115d-fb78a957fc22@enterprisedb.com

2 years agoUse a short socket directory path in pg_upgrade testing.
Tom Lane [Mon, 4 Jul 2022 01:38:32 +0000 (21:38 -0400)]
Use a short socket directory path in pg_upgrade testing.

Several buildfarm members are failing the pg_upgrade test in
REL_15_STABLE, though the identical test is fine in HEAD.
On thorntail it's possible to see that the problem is an
overlength socket path name, and I bet the same is true
on the others.

The normally-started postmasters used in the test are already
set up with short socket directory paths, but we neglected to
tell pg_upgrade itself to do likewise when starting child
postmasters, and indeed it seems to be explicitly selecting
the test directory instead.

Back-patch to v15 where the current test script was introduced.
(The previous script might have the same issue, because I don't
see any use of -s/--socketdir in it either; but we've had no
complaints, so leave it alone for now.)

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

2 years agoRemove %error-verbose directive from jsonpath parser
Andrew Dunstan [Sun, 3 Jul 2022 21:08:25 +0000 (17:08 -0400)]
Remove %error-verbose directive from jsonpath parser

None of the other bison parsers contains this directive, and it gives
rise to some unfortunate and impenetrable messages, so just remove it.

Backpatch to release 12, where it was introduced.

Per gripe from Erik Rijkers

Discussion: https://postgr.es/m/ba069ce2-a98f-dc70-dc17-2ccf2a9bf7c7@xs4all.nl

2 years agoAllow makeaclitem() to accept multiple privilege names.
Tom Lane [Sun, 3 Jul 2022 20:49:12 +0000 (16:49 -0400)]
Allow makeaclitem() to accept multiple privilege names.

Interpret its privileges argument as a comma-separated list of
privilege names, as in has_table_privilege and other functions.
This is actually net less code, since the support routine to
parse that already exists, and we can drop convert_priv_string()
which had no other use-case.

Robins Tharakan

Discussion: https://postgr.es/m/e5a05dc54ba64408b3dd260171c1abaf@EX13D05UWC001.ant.amazon.com

2 years agoAdd Windows file version information to libpq/test programs.
Noah Misch [Sun, 3 Jul 2022 20:07:17 +0000 (13:07 -0700)]
Add Windows file version information to libpq/test programs.

Back-patch to v15, the first version to install these programs.

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

2 years agoSimplify tab completion of extension versions, redux.
Tom Lane [Sun, 3 Jul 2022 19:27:27 +0000 (15:27 -0400)]
Simplify tab completion of extension versions, redux.

After commit 662dbe2c8, psql tab completion didn't conveniently
support the case of "ALTER EXTENSION foo UPDATE".  It'd always
add "TO", which is fine if you want to specify a target version
but not if you don't ... and surely the latter is the much more
common case.

To fix, remove "TO" from the initially offered completion; you now
need to press TAB one additional time to get that.  We won't try to
duplicate the old behavior of attempting initial completion on the
target version along with TO.  It's too squirrelly to get the quoting
right, and this is such an infrequent usage that it doesn't seem worth
expending a lot of effort and special code on.

Noted by Noah Misch.  Back-patch to v15.

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

2 years agoRemove redundant null pointer checks before PQclear and PQconninfoFree
Peter Eisentraut [Sun, 3 Jul 2022 18:11:05 +0000 (20:11 +0200)]
Remove redundant null pointer checks before PQclear and PQconninfoFree

These functions already had the free()-like behavior of handling null
pointers as a no-op.  But it wasn't documented, so add it explicitly
to the documentation, too.

Discussion: https://www.postgresql.org/message-id/flat/dac5d2d0-98f5-94d9-8e69-46da2413593d%40enterprisedb.com

2 years agoRemove redundant null pointer checks before free()
Peter Eisentraut [Thu, 16 Jun 2022 19:50:56 +0000 (21:50 +0200)]
Remove redundant null pointer checks before free()

Per applicable standards, free() with a null pointer is a no-op.
Systems that don't observe that are ancient and no longer relevant.
Some PostgreSQL code already required this behavior, so this change
does not introduce any new requirements, just makes the code more
consistent.

Discussion: https://www.postgresql.org/message-id/flat/dac5d2d0-98f5-94d9-8e69-46da2413593d%40enterprisedb.com

2 years agoRemove redundant null pointer checks before pg_free()
Peter Eisentraut [Fri, 17 Jun 2022 09:51:38 +0000 (11:51 +0200)]
Remove redundant null pointer checks before pg_free()

These are especially useless because the whole point of pg_free() was
to do that very check before calling free().

pg_free() could be removed altogether, but I'm keeping it here to keep
the API consistent.

Discussion: https://www.postgresql.org/message-id/flat/dac5d2d0-98f5-94d9-8e69-46da2413593d%40enterprisedb.com

2 years agoFix previous commit's ecpg_clocale for ppc Darwin.
Noah Misch [Sun, 3 Jul 2022 04:03:19 +0000 (21:03 -0700)]
Fix previous commit's ecpg_clocale for ppc Darwin.

Per buildfarm member prairiedog, this platform rejects uninitialized
global variables in shared libraries.  Back-patch to v10, like the
addition of the variable.

Reviewed by Tom Lane.

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

2 years agoecpglib: call newlocale() once per process.
Noah Misch [Sat, 2 Jul 2022 20:00:30 +0000 (13:00 -0700)]
ecpglib: call newlocale() once per process.

ecpglib has been calling it once per SQL query and once per EXEC SQL GET
DESCRIPTOR.  Instead, if newlocale() has not succeeded before, call it
while establishing a connection.  This mitigates three problems:
- If newlocale() failed in EXEC SQL GET DESCRIPTOR, the command silently
  proceeded without the intended locale change.
- On AIX, each newlocale()+freelocale() cycle leaked memory.
- newlocale() CPU usage may have been nontrivial.

Fail the connection attempt if newlocale() fails.  Rearrange
ecpg_do_prologue() to validate the connection before its uselocale().

The sort of program that may regress is one running in an environment
where newlocale() fails.  If that program establishes connections
without running SQL statements, it will stop working in response to this
change.  I'm betting against the importance of such an ECPG use case.
Most SQL execution (any using ECPGdo()) has long required newlocale()
success, so there's little a connection could do without newlocale().

Back-patch to v10 (all supported versions).

Reviewed by Tom Lane.  Reported by Guillaume Lelarge.

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

2 years agoEmit debug message when executing extension script.
Jeff Davis [Sat, 2 Jul 2022 18:20:45 +0000 (11:20 -0700)]
Emit debug message when executing extension script.

Allows extension authors to more easily debug problems related to the
sequence of update scripts that are executed.

Discussion: https://postgr.es/m/5636a7534a4833884172fe4369d825b26170b3cc.camel%40j-davis.com
Reviewed-by: Peter Eisentraut, Nathan Bossart
2 years agoReformat some node comments
Peter Eisentraut [Sat, 2 Jul 2022 10:33:07 +0000 (12:33 +0200)]
Reformat some node comments

Reformat some comments in node field definitions to avoid long lines.

This makes room for per-field annotations in a future patch to
generate node support functions automatically.

Discussion: https://www.postgresql.org/message-id/c5906b07-220a-a3d4-8ff3-8ee593009424@enterprisedb.com

2 years agoDefault to dynamic_shared_memory_type=sysv on Solaris.
Thomas Munro [Sat, 2 Jul 2022 04:06:47 +0000 (16:06 +1200)]
Default to dynamic_shared_memory_type=sysv on Solaris.

POSIX shm_open() can sleep for a long time and fail spuriously because
of contention on an internal lock file on Solaris (and presumably
illumos).  Commit 389869af fixed the main problem with this, namely that
we could crash, but it's now clear that "posix" is not a good default.

Therefore, choose "sysv" at initdb time on Solaris and illumos.  Other
choices are still available by editing the postgresql.conf file.

Back-patch only to 15, because contention is much less likely further
back, and it doesn't seem like a good idea to change this in released
branches.  This should clear up the failures on build farm animal
margay.

Discussion: https://postgr.es/m/CA%2BhUKGKqKrCV5xKWfh9rnm%3Do%3DDwZLTLtnsj_XpUi9g5%3DV%2B9oyg%40mail.gmail.com

2 years agoIntroduce pg_attribute_nonnull(...)
Michael Paquier [Sat, 2 Jul 2022 03:30:45 +0000 (12:30 +0900)]
Introduce pg_attribute_nonnull(...)

pg_attribute_nonnull(...) can be used to generate compiler warnings
when a function is called with the specified arguments set to NULL, as
per an idea from Andres Freund.  An empty argument list indicates that
no pointer arguments can be NULL.  pg_attribute_nonnull() only works for
compilers that support the nonnull function attribute.  If nonnull is
not supported, pg_attribute_nonnull() has no effect.

As a beginning, this commit uses it for the DefineCustomXXXVariable()
functions to generate warnings when the "name" and "value" arguments are
set to NULL.  This will likely be expanded to other places in the
future, where it makes sense.

Author: Nathan Bossart
Reviewed by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/20220525061739.ur7x535vtzyzkmqo@alap3.anarazel.de

2 years agoReplace PGISOLATIONTIMEOUT with 2 * PG_TEST_TIMEOUT_DEFAULT.
Noah Misch [Sat, 2 Jul 2022 01:27:50 +0000 (18:27 -0700)]
Replace PGISOLATIONTIMEOUT with 2 * PG_TEST_TIMEOUT_DEFAULT.

Now that the more-generic variable exists, use it.

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

2 years agoFix race condition in t/028_pitr_timelines.pl.
Noah Misch [Sat, 2 Jul 2022 01:27:18 +0000 (18:27 -0700)]
Fix race condition in t/028_pitr_timelines.pl.

Per buildfarm members sungazer and mylodon.  Back-patch to v15, which
introduced this test.

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

2 years agoRemove no-longer-used parameter for create_groupingsets_path().
Tom Lane [Fri, 1 Jul 2022 22:39:30 +0000 (18:39 -0400)]
Remove no-longer-used parameter for create_groupingsets_path().

numGroups is unused since commit b5635948a; let's get rid of it.

XueJing Zhao, reviewed by Richard Guo

Discussion: https://postgr.es/m/DM6PR05MB64923CC8B63A2CAF3B2E5D47B7AD9@DM6PR05MB6492.namprd05.prod.outlook.com

2 years agoAdd missing GETTEXT_FLAGS entry
Peter Eisentraut [Fri, 1 Jul 2022 14:41:46 +0000 (16:41 +0200)]
Add missing GETTEXT_FLAGS entry

2 years agoAdd construct_array_builtin, deconstruct_array_builtin
Peter Eisentraut [Fri, 1 Jul 2022 08:51:45 +0000 (10:51 +0200)]
Add construct_array_builtin, deconstruct_array_builtin

There were many calls to construct_array() and deconstruct_array() for
built-in types, for example, when dealing with system catalog columns.
These all hardcoded the type attributes necessary to pass to these
functions.

To simplify this a bit, add construct_array_builtin(),
deconstruct_array_builtin() as wrappers that centralize this hardcoded
knowledge.  This simplifies many call sites and reduces the amount of
hardcoded stuff that is spread around.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/2914356f-9e5f-8c59-2995-5997fc48bcba%40enterprisedb.com