postgresql.git
2 years agoDisable unstable test cases in src/test/ssl/t/001_ssltests.pl.
Tom Lane [Sun, 17 Jul 2022 01:57:32 +0000 (21:57 -0400)]
Disable unstable test cases in src/test/ssl/t/001_ssltests.pl.

Missed one in 55828a6b6084724b08675615a4e911ad4d421cd1 :-(

Discussion: https://postgr.es/m/E1oCNLk-000LCH-Af@gemulon.postgresql.org

2 years agoDisable unstable test cases in src/test/ssl/t/001_ssltests.pl.
Tom Lane [Sat, 16 Jul 2022 22:26:25 +0000 (18:26 -0400)]
Disable unstable test cases in src/test/ssl/t/001_ssltests.pl.

Some of the test cases added by commit 3a0e38504 are failing
intermittently in CI testing.  It looks like, when a connection
attempt fails, it's possible for psql to exit and the test script
to slurp up the postmaster's log file before the connected backend
has managed to write the log entry we're expecting to see.

It's not clear whether that's fixable in any robust way.  Pending
more thought, just comment out the log_like checks.  The ones in
connect_ok tests should be fine, since surely the log entry should
be emitted before we complete the client auth sequence.  I took
out all the ones in connect_fails tests though.

Discussion: https://postgr.es/m/E1oCNLk-000LCH-Af@gemulon.postgresql.org

2 years agoRemove postmaster.c's reset_shared() wrapper function.
Tom Lane [Sat, 16 Jul 2022 16:26:19 +0000 (12:26 -0400)]
Remove postc's reset_shared() wrapper function.

reset_shared just invokes CreateSharedMemoryAndSemaphores, so let's
get rid of it and invoke that directly.  This removes a confusing
seeming-inconsistency between the postmaster's startup sequence
and the startup sequence used in standalone mode.

Nathan Bossart, reviewed by Pavel Borisov

Discussion: https://postgr.es/m/20220329221702.GA559657@nathanxps13

2 years agoAttempt to fix compiler warning on old compiler
Peter Eisentraut [Sat, 16 Jul 2022 13:47:27 +0000 (15:47 +0200)]
Attempt to fix compiler warning on old compiler

A couple more like b449afb582bb9015bfbb85abc10ce122aef9ec70, per
complaints from lapwing.

2 years agoAttempt to fix compiler warning on old compiler
Peter Eisentraut [Sat, 16 Jul 2022 11:45:57 +0000 (13:45 +0200)]
Attempt to fix compiler warning on old compiler

Build farm member lapwing (using gcc 4.7.2) didn't like one part of
9fd45870c1436b477264c0c82eb195df52bc0919, raising a compiler warning.
Revert that for now.

2 years agoReplace many MemSet calls with struct initialization
Peter Eisentraut [Sat, 16 Jul 2022 06:42:15 +0000 (08:42 +0200)]
Replace many MemSet calls with struct initialization

This replaces all MemSet() calls with struct initialization where that
is easily and obviously possible.  (For example, some cases have to
worry about padding bits, so I left those.)

(The same could be done with appropriate memset() calls, but this
patch is part of an effort to phase out MemSet(), so it doesn't touch
memset() calls.)

Reviewed-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/9847b13c-b785-f4e2-75c3-12ec77a3b05c@enterprisedb.com

2 years agoEmulate sigprocmask(), not sigsetmask(), on Windows.
Thomas Munro [Sat, 16 Jul 2022 04:07:45 +0000 (16:07 +1200)]
Emulate sigprocmask(), not sigsetmask(), on Windows.

Since commit a65e0864, we've required Unix systems to have
sigprocmask().  As noted in that commit's message, we were still
emulating the historical pre-standard sigsetmask() function in our
Windows support code.  Emulate standard sigprocmask() instead, for
consistency.

The PG_SETMASK() abstraction is now redundant and all calls could in
theory be replaced by plain sigprocmask() calls, but that isn't done by
this commit.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3153247.1657834482%40sss.pgh.pa.us

2 years agoMake dsm_impl_posix_resize more future-proof.
Thomas Munro [Fri, 15 Jul 2022 22:59:52 +0000 (10:59 +1200)]
Make dsm_impl_posix_resize more future-proof.

Commit 4518c798 blocks signals for a short region of code, but it
assumed that whatever called it had the signal mask set to UnBlockSig on
entry.  That may be true today (or may even not be, in extensions in the
wild), but it would be better not to make that assumption.  We should
save-and-restore the caller's signal mask.

The PG_SETMASK() portability macro couldn't be used for that, which is
why it wasn't done before.  But... considering that commit a65e0864
established back in 9.6 that supported POSIX systems have sigprocmask(),
and that this is POSIX-only code, there is no reason not to use standard
sigprocmask() directly to achieve that.

Back-patch to all supported releases, like 4518c798 and 80845b7c.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CA%2BhUKGKx6Biq7_UuV0kn9DW%2B8QWcpJC1qwhizdtD9tN-fn0H0g%40mail.gmail.com

2 years agoLog details for client certificate failures
Peter Eisentraut [Fri, 15 Jul 2022 14:18:32 +0000 (16:18 +0200)]
Log details for client certificate failures

Currently, debugging client certificate verification failures is
mostly limited to looking at the TLS alert code on the client side.
For simple deployments, sometimes it's enough to see "sslv3 alert
certificate revoked" and know exactly what needs to be fixed, but if
you add any more complexity (multiple CA layers, misconfigured CA
certificates, etc.), trying to debug what happened based on the TLS
alert alone can be an exercise in frustration.

Luckily, the server has more information about exactly what failed in
the chain, and we already have the requisite callback implemented as a
stub.  We fill that in, collect the data, and pass the constructed
error message back to the main code via a static variable.  This lets
us add our error details directly to the final "could not accept SSL
connection" log message, as opposed to issuing intermediate LOGs.

It ends up looking like

    LOG:  connection received: host=localhost port=43112
    LOG:  could not accept SSL connection: certificate verify failed
    DETAIL:  Client certificate verification failed at depth 1: unable to get local issuer certificate.
            Failed certificate data (unverified): subject "/CN=Test CA for PostgreSQL SSL regression test client certs", serial number 2315134995201656577, issuer "/CN=Test root CA for PostgreSQL SSL regression test suite".

The length of the Subject and Issuer strings is limited to prevent
malicious client certs from spamming the logs.  In case the truncation
makes things ambiguous, the certificate's serial number is also
logged.

Author: Jacob Champion <pchampion@vmware.com>
Discussion: https://www.postgresql.org/message-id/flat/d13c4a5787c2a3f83705124f0391e0738c796751.camel@vmware.com

2 years agoConvert macros to static inline functions (xlog_internal.h)
Peter Eisentraut [Fri, 15 Jul 2022 10:05:01 +0000 (12:05 +0200)]
Convert macros to static inline functions (xlog_internal.h)

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

2 years agoSupport gcc -fkeep-inline-functions
Peter Eisentraut [Fri, 15 Jul 2022 10:05:01 +0000 (12:05 +0200)]
Support gcc -fkeep-inline-functions

For some systems, we need to avoid unsatisfied-external-reference
errors in static inlines.  See
27d2693187d1bcf2563ee7142ba37d4788c8d52b for example.  In order to
test that on other systems, the gcc option -fkeep-inline-functions can
be used.  But it actually is a bit stricter than what we currently
have in place, so fix up a few more places along the lines of the
above commit.  (This undoes part of commit
2cd2569c72b8920048e35c31c9be30a6170e1410.)

(Note, this does not add that gcc option anywhere to the build system,
it just makes it possible to use it successfully manually.)

Discussion: https://www.postgresql.org/message-id/flat/E1oBgIW-002ehP-VJ%40gemulon.postgresql.org

2 years agoFix inconsistent parameter names between prototype and declaration
David Rowley [Fri, 15 Jul 2022 03:26:34 +0000 (15:26 +1200)]
Fix inconsistent parameter names between prototype and declaration

Noticed while working in this area.  This code was introduced in PG15,
which is still in beta, so backpatch to there for consistency.

Backpatch-through: 15

2 years agodocs: make monitoring "phases" table titles consistent
Bruce Momjian [Fri, 15 Jul 2022 00:01:11 +0000 (20:01 -0400)]
docs:  make monitoring "phases" table titles consistent

Reported-by: Nitin Jadhav
Discussion: https://postgr.es/m/CAMm1aWbmTHwHKC2PERH0CCaFVPoxrtLeS8=wNuoge94qdSp3vA@mail.gmail.com

Author: Nitin Jadhav

Backpatch-through: 13

2 years agodoc: clarify how dropping of extensions affects dependent objs.
Bruce Momjian [Thu, 14 Jul 2022 21:41:03 +0000 (17:41 -0400)]
doc:  clarify how dropping of extensions affects dependent objs.

Clarify that functions/procedures are dropped when any extension that
depends on them is dropped.

Reported-by: David G. Johnston
Discussion: https://postgr.es/m/CAKFQuwbPSHMDGkisRUmewopweC1bFvytVqB=a=X4GFg=4ZWxPA@mail.gmail.com

Backpatch-through: 13

2 years agopg_upgrade doc: mention that replication slots must be recreated
Bruce Momjian [Thu, 14 Jul 2022 20:34:30 +0000 (16:34 -0400)]
pg_upgrade doc: mention that replication slots must be recreated

Reported-by: Nikhil Shetty
Discussion: https://postgr.es/m/CAFpL5Vxastip0Jei-K-=7cKXTg=5sahSe5g=om=x68NOX8+PUA@mail.gmail.com

Backpatch-through: 10

2 years agodoc: add documentation about ecpg Oracle-compatibility mode
Bruce Momjian [Thu, 14 Jul 2022 20:19:45 +0000 (16:19 -0400)]
doc:  add documentation about ecpg Oracle-compatibility mode

Reported-by: Takeshi Ideriha
Discussion: https://postgr.es/m/TYCPR01MB7041A157067208327D8DAAF9EAA59@TYCPR01MB7041.jpnprd01.prod.outlook.com

Backpatch-through: 11

2 years agodoc: move system views section to its own chapter
Bruce Momjian [Thu, 14 Jul 2022 20:07:12 +0000 (16:07 -0400)]
doc:  move system views section to its own chapter

Previously it was inside the system catalogs chapter.

Reported-by: Peter Smith
Discussion: https://postgr.es/m/CAHut+PsMc18QP60D+L0hJBOXrLQT5m88yVaCDyxLq34gfPHsow@mail.gmail.com

Backpatch-through: 15

2 years agodoc: clarify the behavior of identically-named savepoints
Bruce Momjian [Thu, 14 Jul 2022 19:44:22 +0000 (15:44 -0400)]
doc:  clarify the behavior of identically-named savepoints

Original patch by David G. Johnston.

Reported-by: David G. Johnston
Discussion: https://postgr.es/m/CAKFQuwYQCxSSuSL18skCWG8QHFswOJ3hjovHsOZUE346i4OpVQ@mail.gmail.com

Backpatch-through: 10

2 years agodoc: clarify that "excluded" ON CONFLICT is a single row
Bruce Momjian [Thu, 14 Jul 2022 19:33:28 +0000 (15:33 -0400)]
doc:  clarify that "excluded" ON CONFLICT is a single row

Original patch by David G. Johnston.

Reported-by: David G. Johnston
Discussion: https://postgr.es/m/CAKFQuwa4J0+WuO7kW1PLbjoEvzPN+Q_j+P2bXxNnCLaszY7ZdQ@mail.gmail.com

Backpatch-through: 10

2 years agodoc: mention that INSERT can block because of unique indexes
Bruce Momjian [Thu, 14 Jul 2022 19:17:19 +0000 (15:17 -0400)]
doc:  mention that INSERT can block because of unique indexes

Initial patch by David G. Johnston.

Reported-by: David G. Johnston
Discussion: https://postgr.es/m/CAKFQuwZpbdzceO41VE-xt1Xh8rWRRfgopTAK1wL9EhCo0Am-Sw@mail.gmail.com

Backpatch-through: 10

2 years agodoc: mention the pg_locks lock names in parentheses
Bruce Momjian [Thu, 14 Jul 2022 16:08:55 +0000 (12:08 -0400)]
doc:  mention the pg_locks lock names in parentheses

Reported-by: Troy Frericks
Discussion: https://postgr.es/m/165653551130.665.8240515669521441325@wrigleys.postgresql.org

Backpatch-through: 10

2 years agoDon't clobber postmaster sigmask in dsm_impl_resize.
Thomas Munro [Thu, 14 Jul 2022 13:23:29 +0000 (01:23 +1200)]
Don't clobber postmaster sigmask in dsm_impl_resize.

Commit 4518c798 intended to block signals in regular backends that
allocate DSM segments, but dsm_impl_resize() is also reached by
dsm_postmaster_startup().  It's not OK to clobber the postmaster's
signal mask, so only manipulate the signal mask when under the
postmaster.

Back-patch to all releases, like 4518c798.

Discussion: https://postgr.es/m/CA%2BhUKGKNpK%3D2OMeea_AZwpLg7Bm4%3DgYWk7eDjZ5F6YbozfOf8w%40mail.gmail.com

2 years agoTighten up parsing logic in gen_node_support.pl.
Tom Lane [Thu, 14 Jul 2022 13:04:23 +0000 (09:04 -0400)]
Tighten up parsing logic in gen_node_support.pl.

Teach this script to handle function pointer fields honestly.
Previously they were just silently ignored, but that's not likely to
be a behavior we can accept indefinitely.  This mostly entails fixing
it so that a field declaration spanning multiple lines can be parsed,
because we have a bunch of such fields that're laid out that way.
But that's a good improvement in its own right.

With that change and a minor regex adjustment, the only struct it
fails to parse in the node-defining headers is A_Const, because
of the embedded union.  The path of least resistance is to move
that union declaration outside the struct.

Having done those things, we can make it error out if it finds
any within-struct syntax it doesn't understand, which seems like
a pretty important property for robustness.

This commit doesn't change the output files at all; it's just in
the way of future-proofing.

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

2 years agoAvoid shadowing a variable in sync.c.
Thomas Munro [Tue, 12 Jul 2022 04:17:36 +0000 (16:17 +1200)]
Avoid shadowing a variable in sync.c.

It was confusing to reuse the variable name 'entry' in two scopes.
Use distinct variable names.

Reported-by: Ranier Vilela <ranier.vf@gmail.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/CAEudQArDrFyQ15Am3rgWBunGBVZFDb90onTS8SRiFAWHeiLiFA%40mail.gmail.com

2 years agoCreate a distinct wait event for POSIX DSM allocation.
Thomas Munro [Thu, 14 Jul 2022 10:52:13 +0000 (22:52 +1200)]
Create a distinct wait event for POSIX DSM allocation.

Previously we displayed "DSMFillZeroWrite" while in posix_fallocate(),
because we shared the same wait event for "mmap" and "posix" DSM types.
Let's introduce a new wait event "DSMAllocate", to be more accurate.

Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20220711174518.yldckniicknsxgzl%40awork3.anarazel.de

2 years agoRemove redundant ftruncate() for POSIX DSM memory.
Thomas Munro [Thu, 14 Jul 2022 07:23:35 +0000 (19:23 +1200)]
Remove redundant ftruncate() for POSIX DSM memory.

In early releases of the DSM infrastructure, it was possible to resize
segments.  That was removed in release 12 by commit 3c60d0fa.  Now the
ftruncate() + posix_fallocate() sequence during DSM segment creation has
a redundant step: we're always extending from zero to the desired size,
so we might as well just call posix_fallocate().

Let's also include the remaining ftruncate() call (non-Linux POSIX
systems) in the wait event reporting, for good measure.

Discussion: https://postgr.es/m/CA%2BhUKGJSm-nq8s%2B_59zb7NbFQF-OS%3DxTnTAiGLrQpuSmU2y_1A%40mail.gmail.com

2 years agoBlock signals while allocating DSM memory.
Thomas Munro [Wed, 13 Jul 2022 04:16:07 +0000 (16:16 +1200)]
Block signals while allocating DSM memory.

On Linux, we call posix_fallocate() on shm_open()'d memory to avoid
later potential SIGBUS (see commit 899bd785).

Based on field reports of systems stuck in an EINTR retry loop there,
there, we made it possible to break out of that loop via slightly odd
coding where the CHECK_FOR_INTERRUPTS() call was somewhat removed from
the loop (see commit 422952ee).

On further reflection, that was not a great choice for at least two
reasons:

1.  If interrupts were held, the CHECK_FOR_INTERRUPTS() would do nothing
and the EINTR error would be surfaced to the user.

2.  If EINTR was reported but neither QueryCancelPending nor
ProcDiePending was set, then we'd dutifully retry, but with a bit more
understanding of how posix_fallocate() works, it's now clear that you
can get into a loop that never terminates.  posix_fallocate() is not a
function that can do some of the job and tell you about progress if it's
interrupted, it has to undo what it's done so far and report EINTR, and
if signals keep arriving faster than it can complete (cf recovery
conflict signals), you're stuck.

Therefore, for now, we'll simply block most signals to guarantee
progress.  SIGQUIT is not blocked (see InitPostmasterChild()), because
its expected handler doesn't return, and unblockable signals like
SIGCONT are not expected to arrive at a high rate.  For good measure,
we'll include the ftruncate() call in the blocked region, and add a
retry loop.

Back-patch to all supported releases.

Reported-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Reported-by: Nicola Contu <nicola.contu@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20220701154105.jjfutmngoedgiad3%40alvherre.pgsql

2 years agoCorrect some uses of e.g. and i.e. in message strings and documentation
John Naylor [Thu, 14 Jul 2022 02:38:06 +0000 (09:38 +0700)]
Correct some uses of e.g. and i.e. in message strings and documentation

E.g. means "for example" and i.e. means "that is". Fix a couple uses
that don't match the intended meaning.

Kyotaro Horiguchi

Reviewed by Junwang Zhao and Aleksander Alekseev, with one addition by me
Discussion: https://www.postgresql.org/message-id/flat/20220713.180943.589079824955875739.horikyota.ntt%40gmail.com

2 years agoRemove support for Visual Studio 2013
Michael Paquier [Thu, 14 Jul 2022 02:22:49 +0000 (11:22 +0900)]
Remove support for Visual Studio 2013

No members of the buildfarm are using this version of Visual Studio,
resulting in all the code cleaned up here as being mostly dead, and
VS2017 is the oldest version still supported.

More versions could be cut, but the gain would be minimal, while
removing only VS2013 has the advantage to remove from the core code all
the dependencies on the value defined by _MSC_VER, where compatibility
tweaks have accumulated across the years mostly around locales and
strtof(), so that's a nice isolated cleanup.

Note that this commit additionally allows a revert of 3154e16.  The
versions of Visual Studio now supported range from 2015 to 2022.

Author: Michael Paquier
Reviewed-by: Juan José Santamaría Flecha, Tom Lane, Thomas Munro, Justin
Pryzby
Discussion: https://postgr.es/m/YoH2IMtxcS3ncWn+@paquier.xyz

2 years agoFix output of createuser --help with --valid-until
Michael Paquier [Wed, 13 Jul 2022 23:32:18 +0000 (08:32 +0900)]
Fix output of createuser --help with --valid-until

The argument required by --valid-until, a timestamp string, was missing
in the description of --help.

Author: Shinoda, Noriyoshi
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/DM4PR84MB1734A6CE3839A68B59BEA599EE899@DM4PR84MB1734.NAMPRD84.PROD.OUTLOOK.COM

2 years agoMop up pg_upgrade's nls.mk for commit b0a55e432.
Tom Lane [Wed, 13 Jul 2022 18:33:24 +0000 (14:33 -0400)]
Mop up pg_upgrade's nls.mk for commit b0a55e432.

We'll do this the hard way for today.

Discussion: https://postgr.es/m/20220713.160853.453362706160476128.horikyota.ntt@gmail.com

2 years agoRevert "Use wildcards instead of manually-maintained file lists in */nls.mk."
Tom Lane [Wed, 13 Jul 2022 18:29:10 +0000 (14:29 -0400)]
Revert "Use wildcards instead of manually-maintained file lists in */nls.mk."

This reverts commit 617d69141220f277170927e03a19d2f1b77aed77.
While I still think the basic idea is attractive, we need to sort
out what happens with built .c files, and there also seem to be
VPATH issues.

2 years agoAvoid unsatisfied-external-reference errors in static inlines.
Tom Lane [Wed, 13 Jul 2022 17:37:10 +0000 (13:37 -0400)]
Avoid unsatisfied-external-reference errors in static inlines.

Commit 9c727360b neglected the lesson we've learned before:
protect references to backend global variables with #ifndef FRONTEND.

Since there's already a place for static inlines in this file,
move the just-converted functions to that stanza.  Undo the
entirely gratuitous de-macroization of RelationGetNumberOfBlocks
(that one may be okay, since it has no global variable references,
but it's also pointless).

Per buildfarm.

2 years agoUse wildcards instead of manually-maintained file lists in */nls.mk.
Tom Lane [Wed, 13 Jul 2022 16:56:42 +0000 (12:56 -0400)]
Use wildcards instead of manually-maintained file lists in */nls.mk.

The backend already used a mechanically-generated list of *.c files,
but everywhere else we had a manually-written-out list of files in
which to seek translatable messages.  Commit b0a55e432 contains the
latest in a long line of failures to update those lists.  Rather than
manually fix its oversight, let's change to using "$(wildcard *.c)"
in all these nls.mk files.

Many of these files also have manual references to some *.c files
in other directories, most often src/common/.  Perhaps we should try
to improve that situation too; but it's a bit less clear how, so for
now just fix the local file references.

Kyotaro Horiguchi and Tom Lane

Discussion: https://postgr.es/m/20220713.160853.453362706160476128.horikyota.ntt@gmail.com

2 years agoRemove artificial restrictions on which node types have out/read funcs.
Tom Lane [Wed, 13 Jul 2022 15:48:17 +0000 (11:48 -0400)]
Remove artificial restrictions on which node types have out/read funcs.

The initial version of gen_node_support.pl manually excluded most
utility statement node types from having out/read support, and
also some raw-parse-tree-only node types.  That was mostly to keep
the output comparable to the old hand-maintained code.  We'd like
to have out/read support for utility statements, for debugging
purposes and so that they can be included in new-style SQL functions;
so it's time to lift that restriction.

Most if not all of the previously-excluded raw-parse-tree-only node
types can appear in expression subtrees of utility statements, so
they have to be handled too.

We don't quite have full read support yet; certain custom_read_write
node types need to have their handwritten read functions implemented
before that will work.

Doing this allows us to drop the previous hack in _outQuery to not
dump the utilityStmt field in most cases, which means we no longer
need manually-maintained out/read functions for Query, so get rid
of those in favor of auto-generating them.

Fix a couple of omissions in gen_node_support.pl that are exposed
through having to handle more node types.

catversion bump forced because somebody was sloppy about the field
order in the manually-maintained Query out/read functions.
(Committers should note that almost all changes in parsenodes.h
are now grounds for a catversion bump.)

2 years agoConvert macros to static inline functions (bufmgr.h)
Peter Eisentraut [Wed, 13 Jul 2022 12:33:03 +0000 (14:33 +0200)]
Convert macros to static inline functions (bufmgr.h)

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

2 years agoConvert macros to static inline functions (itemptr.h)
Peter Eisentraut [Wed, 13 Jul 2022 12:33:03 +0000 (14:33 +0200)]
Convert macros to static inline functions (itemptr.h)

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

2 years agoPlug memory leak
Alvaro Herrera [Wed, 13 Jul 2022 10:10:03 +0000 (12:10 +0200)]
Plug memory leak

Commit 054325c5eeb3 created a memory leak in PQsendQueryInternal in case
an error occurs while sending the message.  Repair.

Backpatch to 14, like that commit.  Reported by Coverity.

2 years agoFix flag tests in src/test/modules/test_oat_hooks
Alvaro Herrera [Wed, 13 Jul 2022 09:57:25 +0000 (11:57 +0200)]
Fix flag tests in src/test/modules/test_oat_hooks

In what must have been a copy'n paste mistake, all the flag tests use
the same flag rather than a different flag each.  The bug is not
suprising, considering that it's dead code; add a minimal, testimonial
line to cover it.

This is all pretty inconsequential, because this is just example code,
but it had better be correct.

Discussion: https://postgr.es/m/20220712152059.fwli2majwgzdmh4r@alvherre.pgsql

2 years agoAllow specifying STORAGE attribute for a new table
Peter Eisentraut [Wed, 13 Jul 2022 10:21:45 +0000 (12:21 +0200)]
Allow specifying STORAGE attribute for a new table

Previously, the STORAGE specification was only available in ALTER
TABLE.  This makes it available in CREATE TABLE as well.

Also make the code and the documentation for STORAGE and COMPRESSION
attributes consistent.

Author: Teodor Sigaev <teodor@sigaev.ru>
Author: Aleksander Alekseev <aleksander@timescale.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: wenjing zeng <wjzeng2012@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/de83407a-ae3d-a8e1-a788-920eb334f25b@sigaev.ru

2 years agoRemove useless assertions
Peter Eisentraut [Wed, 13 Jul 2022 09:40:00 +0000 (11:40 +0200)]
Remove useless assertions

We don't need Assert(IsA(foo, String)) right before running
strVal(foo), since strVal() already does the assertion internally (via
castNode()).

2 years agoFix XID list support some more
Alvaro Herrera [Wed, 13 Jul 2022 08:34:54 +0000 (10:34 +0200)]
Fix XID list support some more

Read/out support in 5ca0fe5c8ad7 was missing/incomplete, per Tom Lane.
Again, as far as core is concerned, this is not only dead code but also
untested; however, third parties may come to rely on it, so the standard
features should work.

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

2 years agoFix for make unportability
Peter Eisentraut [Wed, 13 Jul 2022 07:15:01 +0000 (09:15 +0200)]
Fix for make unportability

88dad06b47eb80f699211c9b0b7a1c6d9016ad19 contains a make $(shell)
construct that apparently confuses older GNU make versions (possibly
because of the # inside the shell command?).  This construct, which
would allow # comments inside LINGUAS files, was adapted from gettext
recommendations, but we don't actually need that functionality, so
sidestep this whole issue by just using plain "cat".

In passing, make this code work with vpath.

2 years agoNLS: Put list of available languages into LINGUAS files
Peter Eisentraut [Wed, 13 Jul 2022 05:51:43 +0000 (07:51 +0200)]
NLS: Put list of available languages into LINGUAS files

This moves the list of available languages from nls.mk into a separate
file called po/LINGUAS.  Advantages:

- It keeps the parts notionally managed by programmers (nls.mk)
  separate from the parts notionally managed by translators (LINGUAS).

- It's the standard practice recommended by the Gettext manual
  nowadays.

- The Meson build system also supports this layout (and of course
  doesn't know anything about our custom nls.mk), so this would enable
  sharing the list of languages between the two build systems.

(The MSVC build system currently finds all po files by globbing, so it
is not affected by this change.)

Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/557a9f5c-e871-edc7-2f58-a4140fb65b7b@enterprisedb.com

2 years agoSmall cleanup of create_list_bounds()
David Rowley [Wed, 13 Jul 2022 05:01:01 +0000 (17:01 +1200)]
Small cleanup of create_list_bounds()

When checking for interleaved partitions, we mark the partition as
interleaved when;

1. we find an earlier partition index when looping over the
sorted-by-Datum indexes[] array, or;

2. we find that the NULL partition allows some non-NULL Datum value.

In the code, as it was written in db632fbca we'll continue to check for
case 2 when we've already marked the partition as interleaved for case 1.
Here we make it so we don't bother marking the partition as interleaved
for case 2 when it's already been marked due to case 1.

Really all this saves is a useless call to bms_add_member(), but since
this code is new to PG15, it seems worth fixing it now to save anyone the
trouble of complaining at some time in the future.  We have the
opportunity to improve this now before PG15 is out.  This might ease some
future back-patching pain.

Per report and patch by Zhihong Yu.  However, I slightly revised the
comments and altered the bms_add_member() code to match in both locations.
We already know that index is equal to boundinfo->null_index from the if
condition.

Author: Zhihong Yu
Discussion: https://postgr.es/m/CALNJ-vQbZR0pYxz9zQ5bqXVcwtGgNgVupeEpNT65HZ+yWZnc4g@mail.gmail.com
Backpatch-through: 15, same as db632fbca.

2 years agocreateuser: Add support for more clause types through new options
Michael Paquier [Wed, 13 Jul 2022 03:21:20 +0000 (12:21 +0900)]
createuser: Add support for more clause types through new options

The following options are added to createuser:
* --valid-until to generate a VALID UNTIL clause for the role created.
* --bypassrls/--no-bypassrls for BYPASSRLS/NOBYPASSRLS.
* -m/--member to make the new role a member of an existing role, with an
extra ROLE clause generated.  The clause generated overlaps with
-g/--role, but per discussion this was the most popular choice as option
name.
* -a/--admin for the addition of an ADMIN clause.

These option names are chosen to be completely new, so as they do not
impact anybody relying on the existing option set.  Tests are added for
the new options and extended a bit, while on it, to cover more patterns
where quotes are added to various elements of the query generated.

Author: Shinya Kato
Reviewed-by: Nathan Bossart, Daniel Gustafsson, Robert Haas, Kyotaro
Horiguchi, David G. Johnston, Przemysław Sztoch
Discussion: https://postgr.es/m/69a9851035cf0f0477bcc5d742b031a3@oss.nttdata.com

2 years agoUse list_copy_head() instead of list_truncate(list_copy(...), ...)
David Rowley [Wed, 13 Jul 2022 03:03:47 +0000 (15:03 +1200)]
Use list_copy_head() instead of list_truncate(list_copy(...), ...)

Truncating off the end of a freshly copied List is not a very efficient
way of copying the first N elements of a List.

In many of the cases that are updated here, the pattern was only being
used to remove the final element of a List.  That's about the best case
for it, but there were many instances where the truncate trimming the List
down much further.

4cc832f94 added list_copy_head(), so let's use it in cases where it's
useful.

Author: David Rowley
Discussion: https://postgr.es/m/1986787.1657666922%40sss.pgh.pa.us

2 years agocreateuser: Cleanup and fix internal option ordering
Michael Paquier [Wed, 13 Jul 2022 02:29:02 +0000 (11:29 +0900)]
createuser: Cleanup and fix internal option ordering

This utility supports 23 options that are not really ordered in the
code, making the addition of new things more complicated than necessary.
This cleanup is in preparation for a patch to add even more options.

Discussion: https://postgr.es/m/69a9851035cf0f0477bcc5d742b031a3@oss.nttdata.com

2 years agoTidy up code in get_cheapest_group_keys_order()
David Rowley [Wed, 13 Jul 2022 02:02:20 +0000 (14:02 +1200)]
Tidy up code in get_cheapest_group_keys_order()

There are a few things that we could do a little better within
get_cheapest_group_keys_order():

1. We should be using list_free() rather than pfree() on a List.

2. We should use for_each_from() instead of manually coding a for loop to
skip the first n elements of a List

3. list_truncate(list_copy(...), n) is not a great way to copy the first n
elements of a list. Let's invent list_copy_head() for that.  That way we
don't need to copy the entire list just to truncate it directly
afterwards.

4. We can simplify finding the cheapest cost by setting the cheapest cost
variable to DBL_MAX.  That allows us to skip special-casing the initial
iteration of the loop.

Author: David Rowley
Discussion: https://postgr.es/m/CAApHDvrGyL3ft8waEkncG9y5HDMu5TFFJB1paoTC8zi9YK97Nw@mail.gmail.com
Backpatch-through: 15, where get_cheapest_group_keys_order was added.

2 years agoFix ECPG's handling of type names that match SQL keywords.
Tom Lane [Tue, 12 Jul 2022 21:05:46 +0000 (17:05 -0400)]
Fix ECPG's handling of type names that match SQL keywords.

Previously, ECPG could only cope with variable declarations whose
type names either weren't any SQL keyword, or were at least partially
reserved.  If you tried to use something in the unreserved_keyword
category, you got a syntax error.

This is pretty awful, not only because it says right on the tin that
those words are not reserved, but because the set of such keywords
tends to grow over time.  Thus, an ECPG program that was just fine
last year could fail when recompiled with a newer SQL grammar.
We had to work around this recently when STRING became a keyword,
but it's time for an actual fix instead of a band-aid.

To fix, borrow a trick from C parsers and make the lexer's behavior
change when it sees a word that is known as a typedef.  This is not
free of downsides: if you try to use such a name as a SQL keyword
in EXEC SQL later in the program, it won't be recognized as a SQL
keyword, leading to a syntax error there instead.  So in a real
sense this is just trading one hazard for another.  But there is an
important difference: with this, whether your ECPG program works
depends only on what typedef names and SQL commands are used in the
program text.  If it compiles today it'll still compile next year,
even if more words have become SQL keywords.

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

2 years agoInvent qsort_interruptible().
Tom Lane [Tue, 12 Jul 2022 20:30:36 +0000 (16:30 -0400)]
Invent qsort_interruptible().

Justin Pryzby reported that some scenarios could cause gathering
of extended statistics to spend many seconds in an un-cancelable
qsort() operation.  To fix, invent qsort_interruptible(), which is
just like qsort_arg() except that it will also do CHECK_FOR_INTERRUPTS
every so often.  This bloats the backend by a couple of kB, which
seems like a good investment.  (We considered just enabling
CHECK_FOR_INTERRUPTS in the existing qsort and qsort_arg functions,
but there are some callers for which that'd demonstrably be unsafe.
Opt-in seems like a better way.)

For now, just apply qsort_interruptible() in statistics collection.
There's probably more places where it could be useful, but we can
always change other call sites as we find problems.

Back-patch to v14.  Before that we didn't have extended stats on
expressions, so that the problem was less severe.  Also, this patch
depends on the sort_template infrastructure introduced in v14.

Tom Lane and Justin Pryzby

Discussion: https://postgr.es/m/20220509000108.GQ28830@telsasoft.com

2 years agoImprove error reporting from validate_exec().
Tom Lane [Tue, 12 Jul 2022 19:37:39 +0000 (15:37 -0400)]
Improve error reporting from validate_exec().

validate_exec() didn't guarantee to set errno to something appropriate
after a failure, leading to callers not being able to print an on-point
message.  Improve that.

Noted by Kyotaro Horiguchi, though this isn't exactly his proposal.

Discussion: https://postgr.es/m/20220615.131403.1791191615590453058.horikyota.ntt@gmail.com

2 years agoRemove trailing newlines in pg_upgrade's message strings.
Tom Lane [Tue, 12 Jul 2022 19:17:44 +0000 (15:17 -0400)]
Remove trailing newlines in pg_upgrade's message strings.

pg_upgrade does not use common/logging.c, which is unfortunate
but changing it to do so seems like more work than is justified.
However, we really need to make it work more like common/logging.c
in one respect: the latter expects supplied message strings to not
end with a newline, instead adding one internally.  As it stands,
pg_upgrade's logging facilities expect a caller-supplied newline
in some cases and not others, which is already an invitation to bugs,
but the inconsistency with our other frontend code makes it worse.
There are already several places with missing or extra newlines,
and it's inevitable that there won't be more if we let this stand.

Hence, run around and get rid of all trailing newlines in message
strings, and add an Assert that there's not one, similar to the
existing Assert in common/logging.c.  Adjust the logging functions
to supply a newline at the right places.

(Some of these strings also have a *leading* newline, which would
be a good thing to get rid of too; but this patch doesn't attempt
that.)

There are some consequent minor changes in output.  The ones that
aren't outright bug fixes are generally removal of extra blank
lines that the original coding intentionally inserted.  It didn't
seem worth being bug-compatible with that.

Patch by me, reviewed by Kyotaro Horiguchi and Peter Eisentraut

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

2 years agoAdd defenses against unexpected changes in the NodeTag enum list.
Tom Lane [Tue, 12 Jul 2022 15:22:52 +0000 (11:22 -0400)]
Add defenses against unexpected changes in the NodeTag enum list.

Having different build systems producing different contents of the
NodeTag enum would be catastrophic for extension ABI stability.
But that ordering depends on the order in which gen_node_support.pl
processes its input files.  It seems too fragile to let the Makefiles,
MSVC build scripts, and soon meson build scripts all set this order
independently.  As a klugy but serviceable solution, put a canonical
copy of the file list into gen_node_support.pl itself, and check that
against the files given on the command line.

Also, while it's fine to add and delete node tags during development,
we must not let the assigned NodeTag values change unexpectedly in
stable branches.  Add a cross-check that can be enabled when a branch
is forked off (or later, but that is a time when we're unlikely to
miss doing it).  It just checks that the last auto-assigned number
doesn't change, which is simplistic but will catch the most likely
sorts of mistakes.

From time to time we do need to add a node tag in a stable branch.
To support doing that without changing the branch's auto-assigned
tag numbers, invent pg_node_attr(nodetag_number(VALUE)) which can
be used to give such a node a hand-assigned tag above the last
auto-assigned one.

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

2 years agoInvent nodetag_only attribute for Nodes.
Tom Lane [Tue, 12 Jul 2022 14:46:58 +0000 (10:46 -0400)]
Invent nodetag_only attribute for Nodes.

This allows explaining gen_node_support.pl's handling of execnodes.h
and some other input files as being a shortcut for explicit marking
of all their node declarations as pg_node_attr(nodetag_only).
I foresee that someday we might need to be more fine-grained about
that, and this change provides the infrastructure needed to do so.
For now, it just allows removal of the script's klugy special case
for CallContext and InlineCodeBlock.

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

2 years agoRename some functions to mention Relation instead of RelFileLocator.
Robert Haas [Tue, 12 Jul 2022 14:26:48 +0000 (10:26 -0400)]
Rename some functions to mention Relation instead of RelFileLocator.

This is definitely shorter, and hopefully clearer.

Kyotaro Horiguchi, reviewed by Dilip Kumar and by me

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

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.