users/gsingh/postgres.git
2 years agoAdd read support for some missing raw parse nodes
Peter Eisentraut [Sat, 24 Sep 2022 22:18:33 +0000 (18:18 -0400)]
Add read support for some missing raw parse nodes

The node types A_Const, Constraint, and A_Expr had custom output
functions, but no read functions were implemented so far.

The A_Expr output format had to be tweaked a bit to make it easier to
parse.

Be a bit more cautious about applying strncmp to unterminated strings.

Also error out if an unrecognized enum value is found in each case,
instead of just printing a placeholder value.  That was maybe ok for
debugging but won't work if we want to have robust round-tripping.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us

2 years agoFix reading of BitString nodes
Peter Eisentraut [Sat, 24 Sep 2022 22:10:52 +0000 (18:10 -0400)]
Fix reading of BitString nodes

The node tokenizer went out of its way to store BitString node values
without the leading 'b'.  But everything else in the system stores the
leading 'b'.  This would break if a BitString node is
read-printed-read.

Also, the node tokenizer didn't know that BitString node tokens could
also start with 'x'.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us

2 years agoFix reading of most-negative integer value nodes
Peter Eisentraut [Sat, 24 Sep 2022 22:10:11 +0000 (18:10 -0400)]
Fix reading of most-negative integer value nodes

The main parser checks whether a literal fits into an int when
deciding whether it should be put into an Integer or Float node.  The
parser processes integer literals without signs.  So a most-negative
integer literal will not fit into Integer and will end up as a Float
node.

The node tokenizer did this differently.  It included the sign when
checking whether the literal fit into int.  So a most-negative integer
would indeed fit that way and end up as an Integer node.

In order to preserve the node structure correctly, we need the node
tokenizer to also analyze integer literals without sign.

There are a number of test cases in the regression tests that have a
most-negative integer argument of some utility statement, so this
issue is easily reproduced under WRITE_READ_PARSE_PLAN_TREES.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4159834.1657405226@sss.pgh.pa.us

2 years agoRemove uses of register due to incompatibility with C++17 and up
Andres Freund [Sat, 24 Sep 2022 19:01:06 +0000 (12:01 -0700)]
Remove uses of register due to incompatibility with C++17 and up

The use in regexec.c could remain, since we only try to keep headers C++
clean. But there really doesn't seem to be a good reason to use register in
that spot.

Discussion: https://postgr.es/m/20220308185902.ibdqmasoaunzjrfc@alap3.anarazel.de

2 years agoDe-special-case pgevent's rc file handling
Andres Freund [Sat, 24 Sep 2022 19:04:56 +0000 (12:04 -0700)]
De-special-case pgevent's rc file handling

There's really no need to build win32ver.rc as part of building
pgmsgevent.rc. This will make it sligthly easier to add rc file generation to
the meson build.

2 years agomeson: Remove non-binary targets accidentally added to bin_targets
Andres Freund [Sat, 24 Sep 2022 18:29:29 +0000 (11:29 -0700)]
meson: Remove non-binary targets accidentally added to bin_targets

2 years agoImprove terminology
Peter Eisentraut [Sat, 24 Sep 2022 01:16:08 +0000 (21:16 -0400)]
Improve terminology

Use "prepared transaction" instead of "two-phrase transaction".  This
is in line with 0e60a50e0bf158bead247731e00cee95bcf64daf.

2 years agoDoc: minor cleanups.
Tom Lane [Fri, 23 Sep 2022 22:20:11 +0000 (18:20 -0400)]
Doc: minor cleanups.

Improve a couple of things I noticed while working on v15
release notes.

2 years agopgstat: Fix transactional stats dropping for indexes
Andres Freund [Fri, 23 Sep 2022 20:00:55 +0000 (13:00 -0700)]
pgstat: Fix transactional stats dropping for indexes

Because index creation does not go through heap_create_with_catalog() we
didn't call pgstat_create_relation(), leading to index stats of a newly
created realtion not getting dropped during rollback. To fix, move the
pgstat_create_relation() to heap_create(), which indexes do use.

Similarly, because dropping an index does not go through
heap_drop_with_catalog(), we didn't drop index stats when the transaction
dropping an index committed. Here there's no convenient common path for
indexes and relations, so index_drop() now calls pgstat_drop_relation().

Add tests for transactional index stats handling.

Author: "Drouvot, Bertrand" <bdrouvot@amazon.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/51bbf286-2b4a-8998-bd12-eaae4b765d99@amazon.com
Backpatch: 15-, like 8b1dccd37c71, which introduced the bug

2 years agoRemove PQsendQuery support in pipeline mode
Alvaro Herrera [Fri, 23 Sep 2022 16:21:22 +0000 (18:21 +0200)]
Remove PQsendQuery support in pipeline mode

The extended query protocol implementation I added in commit
acb7e4eb6b1c has bugs when used in pipeline mode.  Rather than spend
more time trying to fix it, remove that code and make the function rely
on simple query protocol only, meaning it can no longer be used in
pipeline mode.

Users can easily change their applications to use PQsendQueryParams
instead.  We leave PQsendQuery in place for Postgres 14, just in case
somebody is using it and has not hit the mentioned bugs; but we should
recommend that it not be used.

Backpatch to 15.

Per bug report from Gabriele Varrazzo.
Discussion: https://postgr.es/m/CA+mi_8ZGSQNmW6-mk_iSR4JZB_LJ4ww3suOF+1vGNs3MrLsv4g@mail.gmail.com

2 years agoStop using PQsendQuery in libpq_pipeline
Alvaro Herrera [Fri, 23 Sep 2022 16:11:48 +0000 (18:11 +0200)]
Stop using PQsendQuery in libpq_pipeline

The "emulation" I wrote for PQsendQuery in pipeline mode to use extended
query protocol, in commit acb7e4eb6b1c, is problematic.  Due to numerous
bugs we'll soon remove it.  As a first step and for all branches back to
14, stop using PQsendQuery in libpq_pipeline.  Also remove a few test
lines that will no longer be relevant.

Backpatch to 14.

Discussion: https://postgr.es/m/CA+mi_8ZGSQNmW6-mk_iSR4JZB_LJ4ww3suOF+1vGNs3MrLsv4g@mail.gmail.com

2 years agoci: freebsd: Set extra_{lib,include}_dirs to /usr/local/...
Andres Freund [Fri, 23 Sep 2022 03:36:28 +0000 (20:36 -0700)]
ci: freebsd: Set extra_{lib,include}_dirs to /usr/local/...

Ommitted in e6b6ea025cc, but necessary for libintl to be found. All other
dependencies can be found via pkg-config (which searches in /usr/local/...)
and thus worked even without adding the directories.

2 years agoAllow publications with schema and table of the same schema.
Amit Kapila [Fri, 23 Sep 2022 02:51:26 +0000 (08:21 +0530)]
Allow publications with schema and table of the same schema.

We previously thought that allowing such cases can confuse users when they
specify DROP TABLES IN SCHEMA but that doesn't seem to be the case based
on discussion. This helps to uplift the restriction during
ALTER TABLE ... SET SCHEMA which used to ensure that we couldn't end up
with a publication having both a schema and the same schema's table.

To allow this, we need to forbid having any schema on a publication if
column lists on a table are specified (and vice versa). This is because
otherwise we still need a restriction during ALTER TABLE ... SET SCHEMA to
forbid cases where it could lead to a publication having both a schema and
the same schema's table with column list.

Based on suggestions by Peter Eisentraut.

Author: Hou Zhijie and Vignesh C
Reviewed-By: Peter Smith, Amit Kapila
Backpatch-through: 15, where it was introduced
Discussion: https://postgr.es/m/2729c9e2-9aac-8cda-f2f4-34f2bcc18f4e@enterprisedb.com

2 years agoDoc: adjust misleading phrasing of a few cross-references.
Tom Lane [Fri, 23 Sep 2022 02:05:09 +0000 (22:05 -0400)]
Doc: adjust misleading phrasing of a few cross-references.

The pg_dump and pg_dumpall man pages referred to app-psql-patterns
as appearing "below", which I suspect was copied-and-pasted from
equivalent text in psql-ref.sgml rather than being actually thought
through.  At least to me, that phrasing means "later in this same
web page/section", which this link target is not.  Drop the
misleading and unnecessary-in-any-case adjective.

2 years agoHarmonize parameter names in pg_dump/pg_dumpall.
Peter Geoghegan [Thu, 22 Sep 2022 23:41:23 +0000 (16:41 -0700)]
Harmonize parameter names in pg_dump/pg_dumpall.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions in pg_dump/pg_dumpall
related code.

Affected code happens to be inconsistent in how it applies conventions
around how Archive and Archive Handle variables are named.  Significant
code churn is required to fully fix those inconsistencies, so take the
least invasive approach possible: treat function definition names as
authoritative, and mechanically adjust corresponding names from function
definitions to match.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAH2-Wzmma+vzcO6gr5NYDZ+sx0G14aU-UrzFutT2FoRaisVCUQ@mail.gmail.com

2 years agoHarmonize parameter names in contrib code.
Peter Geoghegan [Thu, 22 Sep 2022 20:59:20 +0000 (13:59 -0700)]
Harmonize parameter names in contrib code.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions in contrib code.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoHarmonize more lexer function parameter names.
Peter Geoghegan [Thu, 22 Sep 2022 20:27:16 +0000 (13:27 -0700)]
Harmonize more lexer function parameter names.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions for several "lexer
adjacent" backend functions.  These were missed by commit aab06442.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoHarmonize parameter names in ecpg code.
Peter Geoghegan [Thu, 22 Sep 2022 19:53:20 +0000 (12:53 -0700)]
Harmonize parameter names in ecpg code.

Make ecpg function declarations consistently use named parameters.  Also
make sure that the declarations use names that match corresponding names
from function definitions.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoFix race condition where heap_delete() fails to pin VM page.
Jeff Davis [Thu, 22 Sep 2022 17:58:49 +0000 (10:58 -0700)]
Fix race condition where heap_delete() fails to pin VM page.

Similar to 5f12bc94dc, the code must re-check PageIsAllVisible() after
buffer lock is re-acquired. Backpatching to the same version, 12.

Discussion: https://postgr.es/m/CAEP4nAw9jYQDKd_5Y+-s2E4YiUJq1vqiikFjYGpLShtp-K3gag@mail.gmail.com
Reported-by: Robins Tharakan
Reviewed-by: Robins Tharakan
Backpatch-through: 12

2 years agoRemove ALL keyword from TABLES IN SCHEMA for publication
Alvaro Herrera [Thu, 22 Sep 2022 17:02:25 +0000 (19:02 +0200)]
Remove ALL keyword from TABLES IN SCHEMA for publication

This may be a bit too subtle, but removing that word from there makes
this clause no longer a perfect parallel of the GRANT variant "ALL
TABLES IN SCHEMA": indeed, for publications what we record is the schema
itself, not the tables therein, which means that any tables added to the
schema in the future are also published.  This is completely different
to what GRANT does, which is affect only the tables that exist when the
command is executed.

There isn't resounding support for this change, but there are a few
positive votes and no opposition.  Because the time to 15 RC1 is very
short, let's get this out now.

Backpatch to 15.

Discussion: https://postgr.es/m/2729c9e2-9aac-8cda-f2f4-34f2bcc18f4e

2 years agoRestore archive_command documentation
Peter Eisentraut [Sat, 17 Sep 2022 09:34:20 +0000 (11:34 +0200)]
Restore archive_command documentation

Commit 5ef1eefd76f404ddc59b885d50340e602b70f05f, which added
archive_library, purged most mentions of archive_command from the
documentation.  This is inappropriate, since archive_command is still
a feature in use and users will want to see information about it.

This restores all the removed mentions and rephrases things so that
archive_command and archive_library are presented as alternatives of
each other.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/9366d634-a917-85a9-4991-b2a4859edaf9@enterprisedb.com

2 years agoUse min/max bounds defined by Zstd for compression level
Michael Paquier [Thu, 22 Sep 2022 11:02:40 +0000 (20:02 +0900)]
Use min/max bounds defined by Zstd for compression level

The bounds hardcoded in compression.c since ffd5365 (minimum at 1 and
maximum at 22) do not match the reality of what zstd is able to
handle, these values being available via ZSTD_maxCLevel() and
ZSTD_minCLevel() at run-time.  The maximum of 22 is actually correct
in recent versions, but the minimum was not as the library can go down
to -131720 by design.  This commit changes the code to use the run-time
values in the code instead of some hardcoded ones.

Zstd seems to assume that these bounds could change in the future, and
Postgres will be able to adapt automatically to such changes thanks to
what's being done in this commit.

Reported-by: Justin Prysby
Discussion: https://postgr.es/m/20220922033716.GL31833@telsasoft.com
Backpatch-through: 15

2 years agoFix thinko in comment.
Etsuro Fujita [Thu, 22 Sep 2022 06:55:00 +0000 (15:55 +0900)]
Fix thinko in comment.

This comment has been wrong since its introduction in commit 0d5f05cde;
backpatch to v12 where that came in.

Discussion: https://postgr.es/m/CAPmGK14VGf-xQjGQN4o1QyAbXAaxugU5%3DqfcmTDh1iufUDnV_w%40mail.gmail.com

2 years agomeson: ci: Convert some tasks to use meson
Andres Freund [Thu, 22 Sep 2022 04:53:18 +0000 (21:53 -0700)]
meson: ci: Convert some tasks to use meson

The Windows task is changed to use meson as there currently is no way to run
all tests in the old MSVC build system (only ninja is covered for now, we
don't have enough CI resources to test msbuild as well).

To maintain autoconf coverage, the Linux task is duplicated to test both meson
and autoconf builds (linux is currently the fastest task). FreeBSD and macOS
are also converted to meson, as it seems more important to have coverage for
meson than autoconf.

Author: Andres Freund <andres@anarazel.de>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Author: Justin Pryzby <pryzby@telsasoft.com>

2 years agomeson: Add initial version of meson based build system
Andres Freund [Thu, 22 Sep 2022 04:53:12 +0000 (21:53 -0700)]
meson: Add initial version of meson based build system

Autoconf is showing its age, fewer and fewer contributors know how to wrangle
it. Recursive make has a lot of hard to resolve dependency issues and slow
incremental rebuilds. Our home-grown MSVC build system is hard to maintain for
developers not using Windows and runs tests serially. While these and other
issues could individually be addressed with incremental improvements, together
they seem best addressed by moving to a more modern build system.

After evaluating different build system choices, we chose to use meson, to a
good degree based on the adoption by other open source projects.

We decided that it's more realistic to commit a relatively early version of
the new build system and mature it in tree.

This commit adds an initial version of a meson based build system. It supports
building postgres on at least AIX, FreeBSD, Linux, macOS, NetBSD, OpenBSD,
Solaris and Windows (however only gcc is supported on aix, solaris). For
Windows/MSVC postgres can now be built with ninja (faster, particularly for
incremental builds) and msbuild (supporting the visual studio GUI, but
building slower).

Several aspects (e.g. Windows rc file generation, PGXS compatibility, LLVM
bitcode generation, documentation adjustments) are done in subsequent commits
requiring further review. Other aspects (e.g. not installing test-only
extensions) are not yet addressed.

When building on Windows with msbuild, builds are slower when using a visual
studio version older than 2019, because those versions do not support
MultiToolTask, required by meson for intra-target parallelism.

The plan is to remove the MSVC specific build system in src/tools/msvc soon
after reaching feature parity. However, we're not planning to remove the
autoconf/make build system in the near future. Likely we're going to keep at
least the parts required for PGXS to keep working around until all supported
versions build with meson.

Some initial help for postgres developers is at
https://wiki.postgresql.org/wiki/Meson

With contributions from Thomas Munro, John Naylor, Stone Tickle and others.

Author: Andres Freund <andres@anarazel.de>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/20211012083721.hvixq4pnh2pixr3j@alap3.anarazel.de

2 years agoClear ps display of startup process at the end of recovery
Michael Paquier [Thu, 22 Sep 2022 05:25:09 +0000 (14:25 +0900)]
Clear ps display of startup process at the end of recovery

If the ps display is not cleared at this point, the process could
continue displaying "recovering NNN" even if handling end-of-recovery
steps.  df9274a has tackled that by providing some information with the
end-of-recovery checkpoint but 7ff23c6 has nullified the effect of the
first commit.

Per a suggestion from Justin, just clear the ps display when we are done
with recovery, so as no incorrect information is displayed.  This may
get extended in the future, but for now restore the pre-7ff23c6
behavior.

Author: Justin Prysby
Discussion: https://postgr.es/m/20220913223954.GU31833@telsasoft.com
Backpatch-through: 15

2 years agodocs: Fix snapshot name in SET TRANSACTION docs.
Fujii Masao [Thu, 22 Sep 2022 03:54:26 +0000 (12:54 +0900)]
docs: Fix snapshot name in SET TRANSACTION docs.

Commit 6c2003f8a1 changed the snapshot names mentioned in
SET TRANSACTION docs, however, there was one place that
the commit missed updating the name.

Back-patch to all supported versions.

Author: Japin Li
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/MEYP282MB1669BD4280044501165F8B07B64F9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

2 years agoUsed optimized linear search in more code paths
Michael Paquier [Thu, 22 Sep 2022 00:47:28 +0000 (09:47 +0900)]
Used optimized linear search in more code paths

This commit updates two code paths to use pg_lfind32() introduced by
b6ef167 with TransactionId arrays:
- At the end of TransactionIdIsInProgress(), when checking for the case
of still running but overflowed subxids.
- XidIsConcurrent(), when checking for a serializable conflict.

These cases are less impactful than 37a6e5d, but a bit of
micro-benchmarking of this API shows that linear search speeds up by
~20% depending on the number of items involved (x86_64 and amd64 looked
at here).

Author: Nathan Bossart
Reviewed-by: Richard Guo, Michael Paquier
Discussion: https://postgr.es/m/20220901185153.GA783106@nathanxps13

2 years agopsql: Improve tab-completion for MERGE.
Fujii Masao [Thu, 22 Sep 2022 00:25:29 +0000 (09:25 +0900)]
psql: Improve tab-completion for MERGE.

Commit 7103ebb7aa added the tab-completion for MERGE accidentally
in the middle of that for LOCK TABLE. This commit fixes this issue.

This also adds some tab-completion for MERGE.

Back-patch to v15 where MERGE was introduced.

Author: Kotaro Kawamoto, Fujii Masao
Reviewed-by: Shinya Kato, Álvaro Herrera
Discussion: https://postgr.es/m/9f1ad2a87a58cd5e7d64f3993130958d@oss.nttdata.com

2 years agoci: windows: set error mode to not include SEM_NOGPFAULTERRORBOX
Andres Freund [Thu, 22 Sep 2022 00:15:54 +0000 (17:15 -0700)]
ci: windows: set error mode to not include SEM_NOGPFAULTERRORBOX

Cirrus defaults to SetErrorMode(SEM_NOGPFAULTERRORBOX | ...). That prevents
crash reporting from working unless binaries do SetErrorMode()
themselves. Furthermore, it appears that either python or, more likely, the C
runtime has a bug where SEM_NOGPFAULTERRORBOX can very occasionally *trigger*
a crash on process exit - which is hard to debug, given that it explicitly
prevents crash dumps from working...

Discussion: https://postgr.es/m/20220909235836.lz3igxtkcjb5w7zb%40awork3.anarazel.de
Backpatch: 15-, where CI was added

2 years agoci: Increase requested memory size.
Thomas Munro [Wed, 21 Sep 2022 23:35:46 +0000 (11:35 +1200)]
ci: Increase requested memory size.

CI builds recently started failing with:

"Memory size for 4.0 vCPU instance should be between 3840MiB and
26624MiB, while 2048MiB is requested."

Ok then, let's ask for 4G instead of 2G.

This may be due to a change in the type of instance used to work around
an outage, per:

https://twitter.com/cirrus_labs/status/1572657320093712384

2 years agoHarmonize lexer adjacent function parameter names.
Peter Geoghegan [Wed, 21 Sep 2022 20:21:36 +0000 (13:21 -0700)]
Harmonize lexer adjacent function parameter names.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions for several "lexer
adjacent" backend functions.

These functions were missed by recent commits because they were obscured
by clang-tidy warnings about functions whose signature is directly under
the control of the lexer (flex seems to always generate function
declarations with unnamed parameters).  We probably can't fix most of
the warnings it generates for translation units that get built from .l
and .y files, but we can at least do this much.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoImprove ICU option handling in CREATE DATABASE
Peter Eisentraut [Wed, 21 Sep 2022 14:28:40 +0000 (10:28 -0400)]
Improve ICU option handling in CREATE DATABASE

We check that the ICU locale is only specified if the ICU locale
provider is selected.  But we did that too early.  We need to wait
until we load the settings of the template database, since that could
also set what the locale provider is.

Reported-by: Marina Polyakova <m.polyakova@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/9ba4cd1ea6ed6b7b15c0ff15e6f540cd@postgrespro.ru

2 years agoTighten pg_get_object_address argument checking
Peter Eisentraut [Wed, 21 Sep 2022 13:34:22 +0000 (09:34 -0400)]
Tighten pg_get_object_address argument checking

For publication schemas (OBJECT_PUBLICATION_NAMESPACE) and user
mappings (OBJECT_USER_MAPPING), pg_get_object_address() checked the
array length of the second argument, but not of the first argument.
If the first argument was too long, it would just silently ignore
everything but the first argument.  Fix that by checking the length of
the first argument as well.

Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/caaef70b-a874-1088-92ef-5ac38269c33b%40enterprisedb.com

2 years agoImprove some GUC description strings
Alvaro Herrera [Wed, 21 Sep 2022 10:29:38 +0000 (12:29 +0200)]
Improve some GUC description strings

It is not our usual style to use "we" in messages.  Also, remove some
noise words.  Backpatch to 15.

Noted by Kyotaro Horiguchi.

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

2 years agoPass Size as a 2nd argument for snprintf() in tablesync.c.
Amit Kapila [Wed, 21 Sep 2022 04:50:37 +0000 (10:20 +0530)]
Pass Size as a 2nd argument for snprintf() in tablesync.c.

Previously the following snprintf() wrappers:

* ReplicationSlotNameForTablesync()
* ReplicationOriginNameForTablesync()

... used int as a second argument of snprintf() while the actual type of it
is size_t. Although it doesn't fail at present better replace it with Size
for consistency with the rest of the system.

Author: Aleksander Alekseev
Reviewed-By: Peter Smith
Discussion: https://postgr.es/m/CAHut%2BPsa8hhfSE6ozUK-ih7GkQziAVAf4f3bqiXEj2nQiu-43g%40mail.gmail.com

2 years agoImprove some error messages.
Amit Kapila [Wed, 21 Sep 2022 04:13:59 +0000 (09:43 +0530)]
Improve some error messages.

It is not our usual style to use "we" in the error messages.

Author: Kyotaro Horiguchi
Reviewed-By: Amit Kapila
Discussion: https://postgr.es/m/20220914.111507.13049297635620898.horikyota.ntt@gmail.com

2 years agoUse \b in one more PG_TEST_EXTRA check, oversight in c3382a3c3cc
Andres Freund [Wed, 21 Sep 2022 01:11:10 +0000 (18:11 -0700)]
Use \b in one more PG_TEST_EXTRA check, oversight in c3382a3c3cc

Per off-list report from Thomas Munro.

2 years agoAdd definition pg_attribute_aligned() for MSVC
Michael Paquier [Wed, 21 Sep 2022 01:11:23 +0000 (10:11 +0900)]
Add definition pg_attribute_aligned() for MSVC

Visual Studio 2015+ has support for a macro to control the alignement of
structures as of __declspec(align(#)), and this commit adds a definition
of pg_attribute_aligned() based on that.  It happens that this was
already used in the implementation of atomics for MSVC.  Note that there
is still no definition fo pg_attribute_packed(), so this does not impact
itemptr.h.

Author: James Coleman
Discussion: https://postgr.es/m/CAAaqYe-HbtZvR3msoMtk+hYW2S0e0OapzMW8icSMYTMA+mN8Aw@mail.gmail.com

2 years agoRevise tree-walk APIs to improve spec compliance & silence warnings.
Tom Lane [Tue, 20 Sep 2022 22:03:22 +0000 (18:03 -0400)]
Revise tree-walk APIs to improve spec compliance & silence warnings.

expression_tree_walker and allied functions have traditionally
declared their callback functions as, say, "bool (*walker) ()"
to allow for variation in the declared types of the callback
functions' context argument.  This is apparently going to be
forbidden by the next version of the C standard, and the latest
version of clang warns about that.  In any case it's always
been pretty poor for error-detection purposes, so fixing it is
a good thing to do.

What we want to do is change the callback argument declarations to
be like "bool (*walker) (Node *node, void *context)", which is
correct so far as expression_tree_walker and friends are concerned,
but not change the actual callback functions.  Strict compliance with
the C standard would require changing them to declare their arguments
as "void *context" and then cast to the appropriate context struct
type internally.  That'd be very invasive and it would also introduce
a bunch of opportunities for future bugs, since we'd no longer have
any check that the correct sort of context object is passed by outside
callers or internal recursion cases.  Therefore, we're just going
to ignore the standard's position that "void *" isn't necessarily
compatible with struct pointers.  No machine built in the last forty
or so years actually behaves that way, so it's not worth introducing
bug hazards for compatibility with long-dead hardware.

Therefore, to silence these compiler warnings, introduce a layer of
macro wrappers that cast the supplied function name to the official
argument type.  Thanks to our use of -Wcast-function-type, this will
still produce a warning if the supplied function is seriously
incompatible with the required signature, without going as far as
the official spec restriction does.

This method fixes the problem without any need for source code changes
outside nodeFuncs.h/.c.  However, it is an ABI break because the
physically called functions now have names ending in "_impl".  Hence
we can only fix it this way in HEAD.  In the back branches, we'll have
to settle for disabling -Wdeprecated-non-prototype.

Discussion: https://postgr.es/m/CA+hUKGKpHPDTv67Y+s6yiC8KH5OXeDg6a-twWo_xznKTcG0kSA@mail.gmail.com

2 years agoFix recent cpluspluscheck issue in selfuncs.h.
Peter Geoghegan [Tue, 20 Sep 2022 21:08:57 +0000 (14:08 -0700)]
Fix recent cpluspluscheck issue in selfuncs.h.

Fix selfuncs.h cpluspluscheck complaint, without reintroducing a
parameter name inconsistency (restore the original declaration names,
and then make corresponding function definitions consistent with that).

Oversight in commit a601366a.

Author: Peter Geoghegan <pg@bowt.ie>
Reported-By: Andres Freund <andres@anarazel.de>
2 years agoHarmonize more parameter names in bulk.
Peter Geoghegan [Tue, 20 Sep 2022 20:09:30 +0000 (13:09 -0700)]
Harmonize more parameter names in bulk.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions in optimizer, parser,
utility, libpq, and "commands" code, as well as in remaining library
code.  Do the same for all code related to frontend programs (with the
exception of pg_dump/pg_dumpall related code).

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.  Later commits will handle
ecpg and pg_dump/pg_dumpall.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoRefactor PG_TEST_EXTRA logic in autoconf build
Andres Freund [Tue, 20 Sep 2022 18:09:30 +0000 (11:09 -0700)]
Refactor PG_TEST_EXTRA logic in autoconf build

To avoid duplicating the PG_TEST_EXTRA logic in Makefiles into the upcoming
meson based build definition, move the checks into the the tests
themselves. That also has the advantage of making skipped tests visible.

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/7dae5979-c6c0-cec5-7a36-76a85aa8053d@enterprisedb.com

2 years agoImprove comment for OAT_POST_CREATE.
Jeff Davis [Tue, 20 Sep 2022 17:41:34 +0000 (10:41 -0700)]
Improve comment for OAT_POST_CREATE.

Clarify that the command counter may or may not have been incremented.

We may want to change the behavior to be more consistent, but until
that time, at least improve the comment.

Discussion: https://postgr.es/m/CAHoZxqvN2eoic_CvjsAvpryyLyA2xG8JmsyMtKFFJz_1oFhfOg%40mail.gmail.com
Reported-by: Mary Xu
2 years agoFix `trap` in a few shell scripts
Alvaro Herrera [Tue, 20 Sep 2022 16:50:16 +0000 (18:50 +0200)]
Fix `trap` in a few shell scripts

The original `trap` lines in these scripts are incomplete: in case of
any signal, they delete the working directory but let the script run to
completion, which is useless because it will only proceed to complain
about the working directory being removed.  Add `exit` there, with the
original exit value (not rm's).

Since this is mostly just cosmetic, no backpatch.

Discussion: https://postgr.es/m/20220913181002.hzsosy7qkemb7ky7@alvherre.pgsql

2 years agoSuppress variable-set-but-not-used warnings from clang 15.
Tom Lane [Tue, 20 Sep 2022 16:04:37 +0000 (12:04 -0400)]
Suppress variable-set-but-not-used warnings from clang 15.

clang 15+ will issue a set-but-not-used warning when the only
use of a variable is in autoincrements (e.g., "foo++;").
That's perfectly sensible, but it detects a few more cases that
we'd not noticed before.  Silence the warnings with our usual
methods, such as PG_USED_FOR_ASSERTS_ONLY, or in one case by
actually removing a useless variable.

One thing that we can't nicely get rid of is that with %pure-parser,
Bison emits "yynerrs" as a local variable that falls foul of this
warning.  To silence those, I inserted "(void) yynerrs;" in the
top-level productions of affected grammars.

Per recently-established project policy, this is a candidate
for back-patching into out-of-support branches: it suppresses
annoying compiler warnings but changes no behavior.  Hence,
back-patch to 9.5, which is as far as these patches go without
issues.  (A preliminary check shows that the prior branches
need some other set-but-not-used cleanups too, so I'll leave
them for another day.)

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

2 years agoDisable autovacuum in MERGE test script
Alvaro Herrera [Tue, 20 Sep 2022 10:38:48 +0000 (12:38 +0200)]
Disable autovacuum in MERGE test script

Otherwise, it can fail given sufficient bad luck.

Backpatch to 15.

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

2 years agodoc: Fix parameter name for pg_create_logical_replication_slot()
Michael Paquier [Tue, 20 Sep 2022 10:28:37 +0000 (19:28 +0900)]
doc: Fix parameter name for pg_create_logical_replication_slot()

The parameter controlling if two-phase transactions can be decoded was
named "two_phase" in the documentation while its procedure defines
"twophase".

Author: Florin Irion
Discussion: https://postgr.es/m/5eeabd10-1aff-ea61-f92d-9fa0d9a7e207@gmail.com
Backpatch-through: 14

2 years agoFix incorrect variable types for origin IDs in decode.c
Michael Paquier [Tue, 20 Sep 2022 09:13:00 +0000 (18:13 +0900)]
Fix incorrect variable types for origin IDs in decode.c

These variables used XLogRecPtr instead of RepOriginId.

Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAD21AoBm-vNyBSXGp4bmJGvhr=S-EGc5q1dtV70cFTcJvLhC=Q@mail.gmail.com
Backpatch-through: 14

2 years agoHarmonize parameter names in storage and AM code.
Peter Geoghegan [Tue, 20 Sep 2022 02:18:36 +0000 (19:18 -0700)]
Harmonize parameter names in storage and AM code.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions in storage, catalog,
access method, executor, and logical replication code, as well as in
miscellaneous utility/library code.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.  Later commits will do the
same for other parts of the codebase.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoSplit TESTDIR into TESTLOGDIR and TESTDATADIR
Andres Freund [Tue, 20 Sep 2022 01:03:17 +0000 (18:03 -0700)]
Split TESTDIR into TESTLOGDIR and TESTDATADIR

The motivation for this is twofold. For one the meson patchset would like to
have more control over the logfiles. For another, the log file location for
tap tests (tmp_check/log) is not symmetric to the log location for
pg_regress/isolation tests (log/).

This commit does not change the default location for log files for tap tests,
as that'd break the buildfarm log collection, it just provides the
infrastructure for doing so.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/1131990.1660661896@sss.pgh.pa.us
Discussion: https://postgr.es/m/20220828170806.GN2342@telsasoft.com

2 years agoDon't hardcode tmp_check/ as test directory for tap tests
Andres Freund [Tue, 20 Sep 2022 01:00:50 +0000 (18:00 -0700)]
Don't hardcode tmp_check/ as test directory for tap tests

This is motivated by the meson patchset, which wants to put the log / data for
tests in a different place than the autoconf build. Right now log files for
tap tests have to be inside $TESTDIR/tmp_check, whereas log files for
pg_regress/isolationtester are outside of tmp_check. This change doesn't fix
the latter, but is a prerequisite.

The only test that needs adjustment is 010_tab_completion.pl, as it hardcoded
the tmp_check/ directory. Instead create a dedicated directory for the test
files.  It's also a bit cleaner independently, because it doesn't intermingle
the test files with more important things like the log/ directory.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/1131990.1660661896@sss.pgh.pa.us
Discussion: https://postgr.es/m/d861493c-ed20-c251-7a89-7924f5197341@enterprisedb.com

2 years agoHarmonize heapam and tableam parameter names.
Peter Geoghegan [Mon, 19 Sep 2022 23:46:23 +0000 (16:46 -0700)]
Harmonize heapam and tableam parameter names.

Make sure that function declarations use names that exactly match the
corresponding names from function definitions.  Having parameter names
that are reliably consistent in this way will make it easier to reason
about groups of related C functions from the same translation unit as a
module.  It will also make certain refactoring tasks easier.

Like other recent commits that cleaned up function parameter names, this
commit was written with help from clang-tidy.  Later commits will do the
same for other parts of the codebase.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoConsistently use named parameters in regex code consistently.
Peter Geoghegan [Mon, 19 Sep 2022 22:47:04 +0000 (15:47 -0700)]
Consistently use named parameters in regex code consistently.

Adjust a handful of remaining function prototypes that were overlooked
by recent commit bc2187ed.  This oversight wasn't caught by clang-tidy
because the functions in question are only built in custom REG_DEBUG
builds.

Author: Peter Geoghegan <pg@bowt.ie>
Reported-By: Tom Lane <tgl@sss.pgh.pa.us>
2 years agoExtend gendef.pl in preparation for meson
Andres Freund [Mon, 19 Sep 2022 22:34:50 +0000 (15:34 -0700)]
Extend gendef.pl in preparation for meson

The main issue with using gendef.pl as-is for meson is that with meson the
filenames are a bit longer, exceeding the max commandline length when calling
dumpbin with all objects. As it's easier to pass in a library anyway, do so.

The .def file location, input and temporary file location need to be tunable
as well.

This also fixes a bug in gendef.pl: The logic when to regenerate was broken
and never avoid regenerating.

Author: Andres Freund <andres@anarazel.de>
Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/20220809071055.rgikv3qn74ypnnbb@awork3.anarazel.de
Discussion: https://postgr.es/m/7dae5979-c6c0-cec5-7a36-76a85aa8053d@enterprisedb.com

2 years agoUpdate Unicode data to Unicode 15.0.0
Peter Eisentraut [Mon, 19 Sep 2022 22:30:05 +0000 (18:30 -0400)]
Update Unicode data to Unicode 15.0.0

2 years agoConsistently use named parameters in timezone code.
Peter Geoghegan [Mon, 19 Sep 2022 22:13:42 +0000 (15:13 -0700)]
Consistently use named parameters in timezone code.

Make our copy of the IANA timezone library use named parameters in
function declarations.  Also make sure that parameter names from each
function's declaration match corresponding definition parameter names.

This makes the timezone code follow Postgres coding standards.  The
value of having a consistent standard everywhere seems to outweigh the
cost of keeping the function declarations in sync with future IANA
releases.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoConsistently use named parameters in regex code.
Peter Geoghegan [Mon, 19 Sep 2022 22:10:24 +0000 (15:10 -0700)]
Consistently use named parameters in regex code.

Make regex code consistently use named parameters in function
declarations.  Also make sure that parameter names from each function's
declaration match corresponding definition parameter names.

This makes Henry Spencer's regex code follow Postgres coding standards.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com

2 years agoFix misleading comment for get_cheapest_group_keys_order
David Rowley [Mon, 19 Sep 2022 22:03:26 +0000 (10:03 +1200)]
Fix misleading comment for get_cheapest_group_keys_order

The header comment for get_cheapest_group_keys_order() claimed that the
output arguments were set to a newly allocated list which may be freed by
the calling function, however, this was not always true as the function
would simply leave these arguments untouched in some cases.

This tripped me up when working on 1349d2790 as I mistakenly assumed I
could perform a list_concat with the output parameters.  That turned out
bad due to list_concat modifying the original input lists.

In passing, make it more clear that the number of distinct values is
important to reduce tiebreaks during sorts.  Also, explain what the
n_preordered parameter means.

Backpatch-through: 15, where get_cheapest_group_keys_order was introduced.

2 years agoFix out-dated comment in preprocess_groupclause()
David Rowley [Mon, 19 Sep 2022 21:13:49 +0000 (09:13 +1200)]
Fix out-dated comment in preprocess_groupclause()

The comment claimed we don't consider other orders of the GROUP BY clause,
but this is no longer true as of db0d67db2.

Discussion: https://postgr.es/m/CAApHDvq65=9Ro+hLX1i9ugWEiNDvHrBibAO7ARcTnf38_JE+UQ@mail.gmail.com
Backpatch-through: 15, where db0d67db2 was introduced.

2 years agoRemove various duplicated words
David Rowley [Mon, 19 Sep 2022 20:37:02 +0000 (08:37 +1200)]
Remove various duplicated words

Author: Justin Pryzby
Discussion: https://postgr.es/m/20220919111000.GW31833@telsasoft.com

2 years agoFix icu tests with C locale
Peter Eisentraut [Mon, 19 Sep 2022 19:22:43 +0000 (15:22 -0400)]
Fix icu tests with C locale

Similar to 1e08576691bf1a25c0e28745e5e800c44f2a1c76, but for the icu
test suite.

Reported-by: Christoph Berg <myon@debian.org>
Discussion: https://www.postgresql.org/message-id/YyWeU61YMFwjVdxE@msg.df7cb.de

2 years agoMake ALTER DEFAULT PRIVILEGES require privileges, not membership.
Robert Haas [Mon, 19 Sep 2022 18:21:59 +0000 (14:21 -0400)]
Make ALTER DEFAULT PRIVILEGES require privileges, not membership.

If role A is a direct or indirect member of role B but does not inherit
B's privileges (because at least one relevant grant was created WITH
INHERIT FALSE) then A should not be permitted to bypass privilege
checks that require the privileges of B. For example, A can't change
the privileges of objects owned by B, nor can A drop those objects.

However, up until now, it's been possible for A to change default
privileges for role B. That doesn't seem to be correct, because a
non-inherited role grant is only supposed to permit you to assume
the identity of the granted role via SET ROLE, and should not
otherwise permit you to exercise the privileges of that role. Most
places followed that rule, but this case was an exception.

This could be construed as a security vulnerability, but it does not
seem entirely clear cut, since older branches were fuzzy about the
distinction between is_member_of_role() and has_privs_of_role() in
a number of other ways as well. Because of this, and because
user-visible behavior changes in minor releases are to be avoided
whenever possible, no back-patch.

Discussion: http://postgr.es/m/CA+TgmobG_YUP06R_PM_2Z7wR0qv_52gQPHD8CYXbJva0cf0E+A@mail.gmail.com

2 years agowalmethods.c/h: Make WalWriteMethod more object-oriented.
Robert Haas [Mon, 19 Sep 2022 16:53:46 +0000 (12:53 -0400)]
walmethods.c/h: Make WalWriteMethod more object-oriented.

Normally when we use object-oriented programming techniques, we
provide a pointer to an object and then some way of looking up the
associated table of callbacks, but walmethods.c/h took the alternative
approach of providing only a pointer to the table of callbacks and
thus imposed the artificial restriction that there could only ever be
one object of each type, so that the callbacks could find it via a
global variable. That doesn't seem like the right idea, so revise the
approach.

Each callback which does not already have an argument of type
Walfile * now takes a pointer to the relevant WalWriteMethod *
so that these callbacks need not rely on there being only one
object of each type.

Freeing a WalWriteMethod is now performed via a callback provided
for that purpose rather than requiring the caller to know which
WAL method they want to free.

Discussion: http://postgr.es/m/CA+TgmoZS0Kw98fOoAcGz8B9iDhdqB4Be4e=vDZaJZ5A-xMYBqA@mail.gmail.com

2 years agoFuture-proof the recursion inside ExecShutdownNode().
Tom Lane [Mon, 19 Sep 2022 16:16:02 +0000 (12:16 -0400)]
Future-proof the recursion inside ExecShutdownNode().

The API contract for planstate_tree_walker() callbacks is that they
take a PlanState pointer and a context pointer.  Somebody figured
they could save a couple lines of code by ignoring that, and passing
ExecShutdownNode itself as the walker even though it has but one
argument.  Somewhat remarkably, we've gotten away with that so far.
However, it seems clear that the upcoming C2x standard means to
forbid such cases, and compilers that actively break such code
likely won't be far behind.  So spend the extra few lines of code
to do it honestly with a separate walker function.

In HEAD, we might as well go further and remove ExecShutdownNode's
useless return value.  I left that as-is in back branches though,
to forestall complaints about ABI breakage.

Back-patch, with the thought that this might become of practical
importance before our stable branches are all out of service.
It doesn't seem to be fixing any live bug on any currently known
platform, however.

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

2 years agowalmethods.c/h: Make Walfile a struct, rather than a void *
Robert Haas [Mon, 19 Sep 2022 15:20:18 +0000 (11:20 -0400)]
walmethods.c/h: Make Walfile a struct, rather than a void *

This makes the curent file position and pathname visible in a generic
way, so we no longer need current_walfile_name global variable or the
get_current_pos() method. Since that purported to be able to fail but
never actually did, this also lets us get rid of some unnecessary
error-handling code.

One risk of this change is that the get_current_pos() method
previously cleared the error indicator, and that will no longer happen
with the new approach. I looked for a way that this could cause problems
and did not find one.

The previous code was confused about whether "Walfile" was the
implementation-dependent structure representing a WAL file or
whether it was a pointer to that stucture. Some of the code used it
one way, and some in the other. The compiler tolerated that because
void * is interchangeable with void **, but now that Walfile is a
struct, it's necessary to be consistent. Hence, some references to
"Walfile" have been converted to "Walfile *".

Discussion: http://postgr.es/m/CA+TgmoZS0Kw98fOoAcGz8B9iDhdqB4Be4e=vDZaJZ5A-xMYBqA@mail.gmail.com

2 years agoAdd missing serial commas
Peter Eisentraut [Mon, 19 Sep 2022 10:35:01 +0000 (06:35 -0400)]
Add missing serial commas

2 years agoFix typos.
Amit Kapila [Mon, 19 Sep 2022 08:51:39 +0000 (14:21 +0530)]
Fix typos.

Author: Hou Zhijie and Zhang Mingli
Discussion: https://postgr.es/m/OS0PR01MB57162559C01FE2848C12E8F7944D9@OS0PR01MB5716.jpnprd01.prod.outlook.com

2 years agoFix typos referring to PGPROC
John Naylor [Mon, 19 Sep 2022 04:36:51 +0000 (11:36 +0700)]
Fix typos referring to PGPROC

Japin Li

Reviewed by Kyotaro Horiguchi
Discussion: https://www.postgresql.org/message-id/MEYP282MB1669459813B36FB5EAA38434B6499@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

2 years agoHarmonize missed reorderbuffer parameter names.
Peter Geoghegan [Sun, 18 Sep 2022 19:05:07 +0000 (12:05 -0700)]
Harmonize missed reorderbuffer parameter names.

The function ReorderBufferCommitChild() was overlooked by initial work
from commit 035ce1fe.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WzkhzFESnRo+VaGqyEZuzc33Dw09BdZBVmW896Sa22ci_A@mail.gmail.com

2 years agoRemove unused argument "isSlice" from transformAssignmentSubscripts()
Michael Paquier [Sun, 18 Sep 2022 06:33:16 +0000 (15:33 +0900)]
Remove unused argument "isSlice" from transformAssignmentSubscripts()

Since c7aba7c, the transform method used during parse analysis of a
subcripting construct has moved from transformAssignmentSubscripts() to
the per-type transform method (arrays or arbitrary types) the step that
checks for slicing support, but transformAssignmentSubscripts() has kept
traces of it.  Removing it simplifies the code, so let's clean up all
that.

Author: Zhang Mingli
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/0d7041ac-c704-48ad-86fd-e05feddf08ed@Spark

2 years agoHarmonize reorderbuffer parameter names.
Peter Geoghegan [Sun, 18 Sep 2022 00:20:17 +0000 (17:20 -0700)]
Harmonize reorderbuffer parameter names.

Make reorderbuffer.h function declarations consistently use named
parameters.  Also make sure that the declarations use names that match
corresponding names from function definitions in reorderbuffer.c.  This
makes the definitions easier to follow, especially in the case of
functions that happen to have adjoining arguments of the same type.

This patch was written with help from clang-tidy.  Specifically, its
"readability-inconsistent-declaration-parameter-name" check and its
"readability-named-parameter" check were used.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/3955318.1663377656@sss.pgh.pa.us

2 years agoMake check_usermap() parameter names consistent.
Peter Geoghegan [Sat, 17 Sep 2022 23:54:17 +0000 (16:54 -0700)]
Make check_usermap() parameter names consistent.

The function has a bool argument named "case_insensitive", but that was
spelled "case_sensitive" in the declaration.  Make them consistent now
to avoid confusion in the future.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Michael Paquiër <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAH2-WznJt9CMM9KJTMjJh_zbL5hD9oX44qdJ4aqZtjFi-zA3Tg@mail.gmail.com
Backpatch: 10-

2 years agoInclude c.h instead of postgres.h in src/port/*p{read,write}*.c
Andres Freund [Sat, 17 Sep 2022 16:21:59 +0000 (09:21 -0700)]
Include c.h instead of postgres.h in src/port/*p{read,write}*.c

Frontend code shouldn't include postgres.h. Some files in src/port/ need to
include postgres.h/postgres_fe.h, but these files don't.

Discussion: https://postgr.es/m/20220915022626.5xx3ccgkzpkqw5mq@awork3.anarazel.de
Backpatch: 12-, where 3fd2a7932ef introduced (some) of these files

2 years agoRemove DLLTOOL, DLLWRAP from configure / Makefile.global.in
Andres Freund [Sat, 17 Sep 2022 16:15:12 +0000 (09:15 -0700)]
Remove DLLTOOL, DLLWRAP from configure / Makefile.global.in

We got rid of the need for them in 4f5f485d10c and 846e91e0223.

Discussion: https://postgr.es/m/20220915022626.5xx3ccgkzpkqw5mq@awork3.anarazel.de

2 years agopgstat: Create memory contexts below TopMemoryContext
Andres Freund [Fri, 16 Sep 2022 21:08:40 +0000 (14:08 -0700)]
pgstat: Create memory contexts below TopMemoryContext

So far they were created below CacheMemoryContext. However, that's not
guaranteed to exist in all situations, leading to memory contexts created as
top-level contexts. There isn't actually a good reason anymore to create them
below CacheMemoryContext, so just creating them below TopMemoryContext seems
the best approach.

Reported-by: Reid Thompson <reid.thompson@crunchydata.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Author: "Drouvot, Bertrand" <bdrouvot@amazon.com>
Discussion: https://postgr.es/m/b948b729-42fe-f88c-2f4a-0e65d84c049b@amazon.com
Backpatch: 15-

2 years agoFix huge_pages on Windows
Michael Paquier [Sat, 17 Sep 2022 06:39:55 +0000 (15:39 +0900)]
Fix huge_pages on Windows

Since Windows 10 1703, it is additionally necessary to pass a flag
called FILE_MAP_LARGE_PAGES to MapViewOfFile() to enable large pages at
map time.  This flag is ignored on older versions of Windows, where
large pages should still be able to work properly without setting it.
Note that the flag would be set only for binaries that knew about it at
compile-time, which should be more or less all the Windows environments
these days.

Since 495ed0e, Windows 10 is the minimum version of Windows supported by
Postgres, making this change easy to reason about on HEAD.  Per
discussion, no backpatch is done for the moment.

Reported-by: Okano Naoki
Author: Thomas Munro
Reviewed-by: Tom Lane, Michael Paquier, Julien Rouhaud
Discussion: https://postgr.es/m/17448-0a96583a67edb1f7@postgresql.org

2 years agoMessage style improvements
Peter Eisentraut [Sat, 17 Sep 2022 06:10:59 +0000 (08:10 +0200)]
Message style improvements

2 years agoFix race condition in stats.sql added in 5264add7847
Andres Freund [Fri, 16 Sep 2022 17:07:12 +0000 (10:07 -0700)]
Fix race condition in stats.sql added in 5264add7847

Very occasionally the stats test failed due to the number of sessions not
being updated yet. Likely this requires that there is contention on the
database's stats entry. Solve this by forcing pending stats to be flushed
before fetching the stats.

I verified that there are no other test failures after making
pgstat_report_stat() only flush stats when force = true.

Per message from Tom Lane and buildfarm member crake.

Discussion: https://postgr.es/m/3428246.1663271992@sss.pgh.pa.us
Backpatch: 15-, where 5264add7847 added the test

2 years agoImprove plpgsql's ability to handle arguments declared as RECORD.
Tom Lane [Fri, 16 Sep 2022 17:23:01 +0000 (13:23 -0400)]
Improve plpgsql's ability to handle arguments declared as RECORD.

Treat arguments declared as RECORD as if that were a polymorphic type
(which it is, sort of), in that we substitute the actual argument type
while forming the function cache lookup key.  This allows the specific
composite type to be known in some cases where it was not before,
at the cost of making a separate function cache entry for each named
composite type that's passed to the function during a session.  The
particular symptom discussed in bug #17610 could be solved in other
more-efficient ways, but only at the cost of considerable development
work, and there are other cases where we'd still fail without this.

Per bug #17610 from Martin Jurča.  Back-patch to v11 where we first
allowed plpgsql functions to be declared as taking type RECORD.

Discussion: https://postgr.es/m/17610-fb1eef75bf6c2364@postgresql.org

2 years agoaix: xlc: Use -Wl,-b,expfull for old compiler versions
Andres Freund [Tue, 13 Sep 2022 17:55:03 +0000 (10:55 -0700)]
aix: xlc: Use -Wl,-b,expfull for old compiler versions

Unfortunately xlc 12.1 and earlier don't support -qvisibility. Therefore
be7c15b194a doesn't suffice to make extension libraries work without the
explicit mkldexport step removed in fe6a64a58ab. While 12.1 is EOL, there is
some desire to leave buildfarm animals using it run a bit longer. But instead
of adding back the complicated mkldexport step, we can use -Wl,-b,expfull to
force all symbols to be exported.

Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2490844.1663123546@sss.pgh.pa.us

2 years agoClean up minor inconsistencies in pg_attribute_printf() usage.
Tom Lane [Fri, 16 Sep 2022 15:10:48 +0000 (11:10 -0400)]
Clean up minor inconsistencies in pg_attribute_printf() usage.

For some reason we'd never decorated pg_v*printf() with
pg_attribute_printf() annotations.  There is a convention for
how to label va_list-using printf functions (write zero for the
second argument), and we use that liberally elsewhere in the
code, but these core functions lacked it.  It's not clear how
much useful checking the compiler can do for calls of these,
but we might as well add the annotations.

Also, sync win32security.c's log_error() with our normal convention
that pg_attribute_printf must be attached to a function's declaration
not definition.  Apparently this file is only compiled with compilers
that aren't picky about that, but still it'd be better to be
consistent.

No back-patch since there's little reason to think we would catch
anything.

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

2 years agoMessage wording improvements
Peter Eisentraut [Fri, 16 Sep 2022 14:37:53 +0000 (16:37 +0200)]
Message wording improvements

2 years agopostgres_fdw: Remove useless DO block in test
Peter Eisentraut [Fri, 16 Sep 2022 13:57:34 +0000 (15:57 +0200)]
postgres_fdw: Remove useless DO block in test

Discussion: https://www.postgresql.org/message-id/flat/b1f9f399-3a1a-b554-283f-4ae7f34608e2@enterprisedb.com

2 years agoAdjust assorted hint messages that list all valid options.
Peter Eisentraut [Fri, 16 Sep 2022 12:51:47 +0000 (14:51 +0200)]
Adjust assorted hint messages that list all valid options.

Instead of listing all valid options, we now try to provide one
that looks similar.  Since this may be useful elsewhere, this
change introduces a new set of functions that can be reused for
similar purposes.

Author: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/b1f9f399-3a1a-b554-283f-4ae7f34608e2@enterprisedb.com

2 years agoFix createdb tests for C locale
Peter Eisentraut [Fri, 16 Sep 2022 09:10:41 +0000 (11:10 +0200)]
Fix createdb tests for C locale

If the createdb tests run under the C locale, the database cluster
will be initialized with encoding SQL_ASCII.  With the checks added in
c7db01e325a530ec38ec7ba57cd3ed32e123e33c, this will cause several
ICU-related tests to fail because SQL_ASCII is not supported by ICU.
To work around that, use initdb option -E UTF8 for those tests to get
past that check.

2 years agoDon't allow creation of database with ICU locale with unsupported encoding
Peter Eisentraut [Fri, 16 Sep 2022 07:37:54 +0000 (09:37 +0200)]
Don't allow creation of database with ICU locale with unsupported encoding

Check in CREATE DATABASE and initdb that the selected encoding is
supported by ICU.  Before, they would pass but users would later get
an error from the server when they tried to use the database.

Also document that initdb sets the encoding to UTF8 by default if the
ICU locale provider is chosen.

Author: Marina Polyakova <m.polyakova@postgrespro.ru>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/6dd6db0984d86a51b7255ba79f111971@postgrespro.ru

2 years agoDetect format-string mistakes in the libpq_pipeline test module.
Tom Lane [Thu, 15 Sep 2022 21:17:53 +0000 (17:17 -0400)]
Detect format-string mistakes in the libpq_pipeline test module.

I happened to notice that libpq_pipeline's private implementation
of pg_fatal lacked any pg_attribute_printf decoration.  Indeed,
adding that turned up a mistake!  We'd likely never have noticed
because the error exits in this code are unlikely to get hit,
but still, it's a bug.

We're so used to having the compiler check this stuff for us that
a printf-like function without pg_attribute_printf is a land mine.
I wonder if there is a way to detect such omissions.

Back-patch to v14 where this code came in.

2 years agoCopy-edit docs for logical replication column lists
Alvaro Herrera [Thu, 15 Sep 2022 16:04:00 +0000 (18:04 +0200)]
Copy-edit docs for logical replication column lists

There was a excessive structure, leading to somewhat disorganized
presentation of the information. Remove a few tags and reorder
paragraphs to make the text flow more easily.  Also, reword some of it
to be more concise.

The bit about column list combination is not modified, other than to
remove an uninteresting (and IMO confusing and wrong) paragraph; I
intend to deal with it differently afterwards.

Backpatch to 15.

Discussion: https://postgr.es/m/20220913121138.yn7ekkfysxzhkm2u@alvherre.pgsql

2 years agoRevert ill-considered change in pg_resetwal output.
Tom Lane [Thu, 15 Sep 2022 14:58:03 +0000 (10:58 -0400)]
Revert ill-considered change in pg_resetwal output.

Commit 31dcfae83 changed one pg_resetwal output string, and a
corresponding test in pg_upgrade, without sufficient thought for
the consequences.  We can't change that output without creating
hazards for cross-version upgrades, since pg_upgrade needs to be able
to read the output of several different versions of pg_resetwal.
There may well be external tools with the same requirement.

For the moment, just revert those two changes.  What we really
ought to do here is have a separate, stable, easily machine-readable
output format for pg_resetwal and pg_controldata, as proposed
years ago by Alvaro.  Once that's in place and tools no longer
need to depend on the exact spelling of the human-readable output,
we can put back this change.

Discussion: https://postgr.es/m/fbea8c6f-415a-bad9-c3de-969c40d08a84@dunslane.net

2 years agoReset InstallXLogFileSegmentActive after walreceiver self-initiated exit.
Noah Misch [Thu, 15 Sep 2022 13:45:23 +0000 (06:45 -0700)]
Reset InstallXLogFileSegmentActive after walreceiver self-initiated exit.

After commit cc2c7d65fc27e877c9f407587b0b92d46cd6dd16 added this flag,
failure to reset it caused assertion failures.  In non-assert builds, it
made the system fail to achieve the objectives listed in that commit;
chiefly, we might emit a spurious log message.  Back-patch to v15, where
that commit first appeared.

Bharath Rupireddy and Kyotaro Horiguchi.  Reviewed by Dilip Kumar,
Nathan Bossart and Michael Paquier.  Reported by Dilip Kumar.

Discussion: https://postgr.es/m/CAFiTN-sE3ry=ycMPVtC+Djw4Fd7gbUGVv_qqw6qfzp=JLvqT3g@mail.gmail.com

2 years agoFix grammar in error message
John Naylor [Thu, 15 Sep 2022 04:40:17 +0000 (11:40 +0700)]
Fix grammar in error message

While at it, make ellipses formatting consistent when describing SQL statements.

Ekaterina Kiryanova and Alexander Lakhin

Reviewed by myself and Álvaro Herrera
Discussion: https://www.postgresql.org/message-id/eed5cec0-a542-53da-6a5e-7789c6ed9817%40postgrespro.ru
Backpatch only the grammar fix to v15

2 years agoBlind attempt to fix LLVM dependency in the backend
John Naylor [Thu, 15 Sep 2022 03:24:55 +0000 (10:24 +0700)]
Blind attempt to fix LLVM dependency in the backend

Commit ecaf7c5df5 removed gram.h from the backend's generated-headers
target. In LLVM builds, this leads to loss of dependency information
when generating .bc files. To fix, add a rule that mirrors ad-hoc .o
dependencies for .bc files as well.

Per cfbot (no buildfarm failures reported)
Analysis by Tom Lane and Andres Freund
Proposed fix by Andres Freund
Discussion: https://www.postgresql.org/message-id/20220914210427.y26tkagmxo5wwbvp%40awork3.anarazel.de

2 years agoUse the terminology "WAL file" not "log file" more consistently.
Tom Lane [Wed, 14 Sep 2022 22:40:58 +0000 (18:40 -0400)]
Use the terminology "WAL file" not "log file" more consistently.

Referring to the WAL as just "log" invites confusion with the
postmaster log, so avoid doing that in docs and error messages.
Also shorten "WAL segment file" to just "WAL file" in various
places.

Bharath Rupireddy, reviewed by Nathan Bossart and Kyotaro Horiguchi

Discussion: https://postgr.es/m/CALj2ACUeXa8tDPaiTLexBDMZ7hgvaN+RTb957-cn5qwv9zf-MQ@mail.gmail.com

2 years agoFix outdated convert_saop_to_hashed_saop comment
David Rowley [Wed, 14 Sep 2022 21:40:34 +0000 (09:40 +1200)]
Fix outdated convert_saop_to_hashed_saop comment

In 29f45e299, we added support for optimizing the execution of NOT
IN(values) by using a hash table instead of a linear search over the
array.  That commit neglected to update the header comment for
convert_saop_to_hashed_saop() to mention this fact.  Here we fix that.

Author: James Coleman
Discussion: https://postgr.es/m/CAAaqYe99NUpAPcxgchGstgM23fmiGjqQPot8627YgkBgNt=BfA@mail.gmail.com
Backpatch-through: 15, where 29f45e299 was added.

2 years agoSmall wording improvements
Peter Eisentraut [Wed, 14 Sep 2022 20:30:51 +0000 (22:30 +0200)]
Small wording improvements

2 years agoDoc: add some doco about using the libpq_pipeline test module.
Tom Lane [Wed, 14 Sep 2022 20:43:19 +0000 (16:43 -0400)]
Doc: add some doco about using the libpq_pipeline test module.

The README file here was barely a stub.  Try to make it useful.

Jelte Fennema, with some further work by me

Discussion: https://postgr.es/m/AM5PR83MB0178D3B31CA1B6EC4A8ECC42F7529@AM5PR83MB0178.EURPRD83.prod.outlook.com

2 years agopgcrypto: Remove unused code
Daniel Gustafsson [Wed, 14 Sep 2022 19:58:30 +0000 (21:58 +0200)]
pgcrypto: Remove unused code

The mbuf_tell, mbuf_rewind and pgp_get_cipher_name functions were
introduced in commit e94dd6ab91, but were never used, so remove.

Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://postgr.es/m/FCF3F14E-17D5-41F2-AC58-0A97B341193A@yesql.se

2 years agoUpdate .gitignore
Peter Eisentraut [Wed, 14 Sep 2022 19:55:28 +0000 (21:55 +0200)]
Update .gitignore

Add entry for ab393528fa4b2486237ee7aa51fac67f82fee824.  Remove one
obsolete entry.

2 years agoUse SIGNAL_ARGS consistently to declare signal handlers.
Tom Lane [Wed, 14 Sep 2022 18:44:45 +0000 (14:44 -0400)]
Use SIGNAL_ARGS consistently to declare signal handlers.

Various bits of code were declaring signal handlers manually,
using "int signum" or variants of that.  We evidently have no
platforms where that's actually wrong, but let's use our
SIGNAL_ARGS macro everywhere anyway.  If nothing else, it's
good for finding signal handlers easily.

No need for back-patch, since this is just cosmetic AFAICS.

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