Michael Paquier [Mon, 6 Sep 2021 01:59:20 +0000 (10:59 +0900)]
Move the shared memory size calculation to its own function
This change refactors the shared memory size calculation in
CreateSharedMemoryAndSemaphores() to its own function. This is intended
for use in a future change related to the setup of huge pages and shared
memory with some GUCs, while useful on its own for extensions.
Author: Nathan Bossart
Discussion: https://postgr.es/m/
F2772387-CE0F-46BF-B5F1-
CC55516EB885@amazon.com
Michael Paquier [Mon, 6 Sep 2021 00:25:45 +0000 (09:25 +0900)]
Remove some unused variables in TAP tests
Author: Amul Sul
Discussion: https://postgr.es/m/CAAJ_b96xuFh4JZE6p-zhLyDu7q=NbxJfb1z_yeAu6t-MqaBC+Q@mail.gmail.com
Tom Lane [Sat, 4 Sep 2021 20:29:08 +0000 (16:29 -0400)]
Further portability tweaks for float4/float8 hash functions.
Attempting to make hashfloat4() look as much as possible like
hashfloat8(), I'd figured I could replace NaNs with get_float4_nan()
before widening to float8. However, results from protosciurus
and topminnow show that on some platforms that produces a different
bit-pattern from get_float8_nan(), breaking the intent of
ce773f230.
Rearrange so that we use the result of get_float8_nan() for all NaN
cases. As before, back-patch.
Tom Lane [Sat, 4 Sep 2021 17:27:55 +0000 (13:27 -0400)]
Minor improvements for psql help output.
Fix alphabetization of the output of "\?", and improve one description.
Update PageOutput counts where needed, fixing breakage from previous
patches.
Haiying Tang (PageOutput fixes by me)
Discussion: https://postgr.es/m/OS0PR01MB61136018064660F095CB57A8FB129@OS0PR01MB6113.jpnprd01.prod.outlook.com
Alvaro Herrera [Sat, 4 Sep 2021 16:14:30 +0000 (12:14 -0400)]
Revert "Avoid creating archive status ".ready" files too early"
This reverts commit
515e3d84a0b5 and equivalent commits in back
branches. This solution to the problem has a number of problems, so
we'll try again with a different approach.
Per note from Andres Freund
Discussion: https://postgr.es/m/
20210831042949.52eqp5xwbxgrfank@alap3.anarazel.de
Tom Lane [Sat, 4 Sep 2021 01:04:44 +0000 (21:04 -0400)]
Remove arbitrary MAXPGPATH limit on command lengths in pg_ctl.
Replace fixed-length command buffers with psprintf() calls. We didn't
have anything as convenient as psprintf() when this code was written,
but now that we do, there's little reason for the limitation to
stand. Removing it eliminates some corner cases where (for example)
starting the postmaster with a whole lot of options fails.
Most individual file names that pg_ctl deals with are still restricted
to MAXPGPATH, but we've seldom had complaints about that limitation
so long as it only applies to one filename.
Back-patch to all supported branches.
Phil Krylov
Discussion: https://postgr.es/m/
567e199c6b97ee19deee600311515b86@krylov.eu
Tom Lane [Fri, 3 Sep 2021 20:38:55 +0000 (16:38 -0400)]
Disallow creating an ICU collation if the DB encoding won't support it.
Previously this was allowed, but the collation effectively vanished
into the ether because of the way lookup_collation() works: you could
not use the collation, nor even drop it. Seems better to give an
error up front than to leave the user wondering why it doesn't work.
(Because this test is in DefineCollation not CreateCollation, it does
not prevent pg_import_system_collations from creating ICU collations,
regardless of the initially-chosen encoding.)
Per bug #17170 from Andrew Bille. Back-patch to v10 where ICU support
was added.
Discussion: https://postgr.es/m/17170-
95845cf3f0a9c36d@postgresql.org
John Naylor [Fri, 3 Sep 2021 17:38:15 +0000 (13:38 -0400)]
Set the volatility of the timestamptz version of date_bin() back to immutable
543f36b43d was too hasty in thinking that the volatility of date_bin()
had to match date_trunc(), since only the latter references
session_timezone.
Bump catversion
Per feedback from Aleksander Alekseev
Backpatch to v14, as the former commit was
Tom Lane [Fri, 3 Sep 2021 14:01:02 +0000 (10:01 -0400)]
Fix portability issue in tests from commit
ce773f230.
Modern POSIX seems to require strtod() to accept "-NaN", but there's
nothing about NaN in SUSv2, and some of our oldest buildfarm members
don't like it. Let's try writing it as -'NaN' instead; that seems
to produce the same result, at least on Intel hardware.
Per buildfarm.
Peter Eisentraut [Fri, 3 Sep 2021 09:59:12 +0000 (11:59 +0200)]
Make pkg-config files cross-compile friendly
Currently the pc files use hard coded paths for "includedir" and
"libdir."
Example:
Cflags: -I/usr/include
Libs: -L/usr/lib -lpq
This is not very fortunate when cross compiling inside a buildroot,
where the includes and libs are inside a staging directory, because
this introduces host paths into the build:
checking for pkg-config... /builder/shared-workdir/build/sdk/staging_dir/host/bin/pkg-config
checking for PostgreSQL libraries via pkg_config... -L/usr/lib <----
This commit addresses this by doing the following two things:
1. Instead of hard coding the paths in "Cflags" and "Libs"
"${includedir}" and "${libdir}" are used. Note: these variables
can be overriden on the pkg-config command line
("--define-variable=libdir=/some/path").
2. Add the variables "prefix" and "exec_prefix". If "includedir"
and/or "libdir" are using these then construct them accordingly.
This is done because buildroots (for instance OpenWrt) tend to
rename the real pkg-config and call it indirectly from a script
that sets "prefix", "exec_prefix" and "bindir", like so:
pkg-config.real --define-variable=prefix=${STAGING_PREFIX} \
--define-variable=exec_prefix=${STAGING_PREFIX} \
--define-variable=bindir=${STAGING_PREFIX}/bin $@
Example #1: user calls ./configure with "--libdir=/some/lib" and
"--includedir=/some/include":
prefix=/usr/local/pgsql
exec_prefix=${prefix}
libdir=/some/lib
includedir=/some/include
Name: libpq
Description: PostgreSQL libpq library
Url: http://www.postgresql.org/
Version: 12.1
Requires:
Requires.private:
Cflags: -I${includedir}
Libs: -L${libdir} -lpq
Libs.private: -lcrypt -lm
Example #2: user calls ./configure with no arguments:
prefix=/usr/local/pgsql
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: libpq
Description: PostgreSQL libpq library
Url: http://www.postgresql.org/
Version: 12.1
Requires:
Requires.private:
Cflags: -I${includedir}
Libs: -L${libdir} -lpq
Libs.private: -lcrypt -lm
Like this the paths can be forced into the staging directory when
using a buildroot setup:
checking for pkg-config... /home/sk/tmp/openwrt/staging_dir/host/bin/pkg-config
checking for PostgreSQL libraries via pkg_config... -L/home/sk/tmp/openwrt/staging_dir/target-mips_24kc_musl/usr/lib
Author: Sebastian Kemper <sebastian_ml@gmx.net>
Co-authored-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/
20200305213827.GA25135%40darth.lan
Peter Eisentraut [Fri, 3 Sep 2021 08:52:11 +0000 (10:52 +0200)]
Fix pkg-config files for static linking
Since
ea53100d5 (PostgreSQL 12), the shipped pkg-config files have
been broken for statically linking libpq because libpgcommon and
libpgport are missing. This patch adds those two missing private
dependencies (in a non-hardcoded way).
Reported-by: Filip Gospodinov <f@gospodinov.ch>
Discussion: https://www.postgresql.org/message-id/flat/
c7108bde-e051-11d5-a234-
99beec01ce2a@gospodinov.ch
Tom Lane [Thu, 2 Sep 2021 22:53:10 +0000 (18:53 -0400)]
In count_usable_fds(), duplicate stderr not stdin.
We had a complaint that the postmaster fails to start if the invoking
program closes stdin. That happens because count_usable_fds expects
to be able to dup(0), and if it can't, we conclude there are no free
FDs and go belly-up. So far as I can find, though, there is no other
place in the server that touches stdin, and it's not unreasonable to
expect that a daemon wouldn't use that file.
As a simple improvement, let's dup FD 2 (stderr) instead. Unlike stdin,
it *is* reasonable for us to expect that stderr be open; even if we are
configured not to touch it, common libraries such as libc might try to
write error messages there.
Per gripe from Mario Emmenlauer. Given the lack of previous complaints,
I'm not excited about pushing this into stable branches, but it seems
OK to squeeze it into v14.
Discussion: https://postgr.es/m/
48bafc63-c30f-3962-2ded-
f2e985d93e86@emmenlauer.de
Tom Lane [Thu, 2 Sep 2021 21:24:41 +0000 (17:24 -0400)]
Fix float4/float8 hash functions to produce uniform results for NaNs.
The IEEE 754 standard allows a wide variety of bit patterns for NaNs,
of which at least two ("NaN" and "-NaN") are pretty easy to produce
from SQL on most machines. This is problematic because our btree
comparison functions deem all NaNs to be equal, but our float hash
functions know nothing about NaNs and will happily produce varying
hash codes for them. That causes unexpected results from queries
that hash a column containing different NaN values. It could also
produce unexpected lookup failures when using a hash index on a
float column, i.e. "WHERE x = 'NaN'" will not find all the rows
it should.
To fix, special-case NaN in the float hash functions, not too much
unlike the existing special case that forces zero and minus zero
to hash the same. I arranged for the most vanilla sort of NaN
(that coming from the C99 NAN constant) to still have the same
hash code as before, to reduce the risk to existing hash indexes.
I dithered about whether to back-patch this into stable branches,
but ultimately decided to do so. It's a clear improvement for
queries that hash internally. If there is anybody who has -NaN
in a hash index, they'd be well advised to re-index after applying
this patch ... but the misbehavior if they don't will not be much
worse than the misbehavior they had before.
Per bug #17172 from Ma Liangzhu.
Discussion: https://postgr.es/m/17172-
7505bea9e04e230f@postgresql.org
Daniel Gustafsson [Thu, 2 Sep 2021 11:03:21 +0000 (13:03 +0200)]
Remove superfluous variable assignment
Commit
a4205fa00 moved setting conn to NULL directly after the call
to PQfinish, but the original conn = NULL; remained a few lines down.
Fix by removing the superfluous assignment.
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CALj2ACVRiNvMDHYQGiRrGs2Z9dOydfLh2MymEk9i8CSn23UtCg@mail.gmail.com
Fujii Masao [Thu, 2 Sep 2021 05:01:06 +0000 (14:01 +0900)]
Enhance pg_stat_reset_single_table_counters function.
This commit allows pg_stat_reset_single_table_counters() to reset statistics
for a single relation shared across all databases in the cluster to zero.
Bump catalog version.
Author: B Sadhu Prasad Patro
Reviewed-by: Mahendra Singh Thalor, Himanshu Upadhyaya, Dilip Kumar, Fujii Masao
Discussion: https://postgr.es/m/CAFF0-CGy7EHeF=AqqkGMF85cySPQBgDcvNk73G2O0vL94O5U5A@mail.gmail.com
Amit Kapila [Thu, 2 Sep 2021 02:43:46 +0000 (08:13 +0530)]
Optimize fileset usage in apply worker.
Use one fileset for the entire worker lifetime instead of using
separate filesets for each streaming transaction. Now, the
changes/subxacts files for every streaming transaction will be
created under the same fileset and the files will be deleted
after the transaction is completed.
This patch extends the BufFileOpenFileSet and BufFileDeleteFileSet
APIs to allow users to specify whether to give an error on missing
files.
Author: Dilip Kumar, based on suggestion by Thomas Munro
Reviewed-by: Hou Zhijie, Masahiko Sawada, Amit Kapila
Discussion: https://postgr.es/m/E1mCC6U-0004Ik-Fs@gemulon.postgresql.org
Michael Paquier [Thu, 2 Sep 2021 02:35:38 +0000 (11:35 +0900)]
doc: Replace some uses of "which" by "that" in parallel.sgml
This makes the documentation more accurate grammatically.
Author: Elena Indrupskaya
Discussion: https://postgr.es/m/
1c994b3d-951e-59bb-1ac2-
7b9221c0e4cf@postgrespro.ru
Backpatch-through: 9.6
Tatsuo Ishii [Thu, 2 Sep 2021 01:39:09 +0000 (10:39 +0900)]
Use COPY FREEZE in pgbench for faster benchmark table population.
While populating the pgbench_accounts table, plain COPY was
unconditionally used. By changing it to COPY FREEZE, the time for
VACUUM is significantly reduced, thus the total time of "pgbench -i"
is also reduced. This only happens if pgbench runs against PostgreSQL
14 or later because COPY FREEZE in previous versions of PostgreSQL does
not bring the benefit. Also if partitioning is used, COPY FREEZE
cannot be used. In this case plain COPY will be used too.
Author: Tatsuo Ishii
Discussion: https://postgr.es/m/
20210308.143907.
2014279678657453983.t-ishii@gmail.com
Reviewed-by: Fabien COELHO, Laurenz Albe, Peter Geoghegan, Dean Rasheed
Tom Lane [Wed, 1 Sep 2021 21:24:59 +0000 (17:24 -0400)]
Doc: clarify how triggers relate to transactions.
Laurenz Albe, per gripe from Nathan Long.
Discussion: https://postgr.es/m/
161953360822.695.
15805897835151971142@wrigleys.postgresql.org
Tom Lane [Wed, 1 Sep 2021 20:21:13 +0000 (16:21 -0400)]
Refactor postgresImportForeignSchema to avoid code duplication.
Avoid repeating fragments of the query we're building, along the
same lines as recent cleanup in pg_dump. I got annoyed about this
because
aa769f80e broke my pending patch to change postgres_fdw's
collation handling, due to each of us having incompletely done
this same refactoring. Let's finish that job in hopes of having
a more stable base.
Tomas Vondra [Wed, 1 Sep 2021 15:41:54 +0000 (17:41 +0200)]
Identify simple column references in extended statistics
Until now, when defining extended statistics, everything except a plain
column reference was treated as complex expression. So for example "a"
was a column reference, but "(a)" would be an expression. In most cases
this does not matter much, but there were a couple strange consequences.
For example
CREATE STATISTICS s ON a FROM t;
would fail, because extended stats require at least two columns. But
CREATE STATISTICS s ON (a) FROM t;
would succeed, because that requirement does not apply to expressions.
Moreover, that statistics object is useless - the optimizer will always
use the regular statistics collected for attribute "a".
So do a bit more work to identify those expressions referencing a single
column, and translate them to a simple column reference. Backpatch to
14, where support for extended statistics on expressions was introduced.
Reported-by: Justin Pryzby
Backpatch-through: 14
Discussion: https://postgr.es/m/
20210816013255.GS10479%40telsasoft.com
Fujii Masao [Wed, 1 Sep 2021 13:01:15 +0000 (22:01 +0900)]
Improve tab-completion for CREATE PUBLICATION.
Author: Peter Smith
Reviewed-by: Vignesh C
Discussion: https://postgr.es/m/CAHut+Ps-vkmnWAShWSRVCB3gx8aM=bFoDqWgBNTzofK0q1LpwA@mail.gmail.com
Peter Eisentraut [Wed, 1 Sep 2021 08:43:55 +0000 (10:43 +0200)]
Fix incorrect format placeholders
Fujii Masao [Wed, 1 Sep 2021 08:05:13 +0000 (17:05 +0900)]
pgbench: Fix bug in measurement of disconnection delays.
When -C/--connect option is specified, pgbench establishes and closes
the connection for each transaction. In this case pgbench needs to
measure the times taken for all those connections and disconnections,
to include the average connection time in the benchmark result.
But previously pgbench could not measure those disconnection delays.
To fix the bug, this commit makes pgbench measure the disconnection
delays whenever the connection is closed at the end of transaction,
if -C/--connect option is specified.
Back-patch to v14. Per discussion, we concluded not to back-patch to v13
or before because changing that behavior in stable branches would
surprise users rather than providing benefits.
Author: Yugo Nagata
Reviewed-by: Fabien COELHO, Tatsuo Ishii, Asif Rehman, Fujii Masao
Discussion: https://postgr.es/m/
20210614151155.
a393bc7d8fed183e38c9f52a@sraoss.co.jp
Amit Kapila [Wed, 1 Sep 2021 04:48:23 +0000 (10:18 +0530)]
Fix the random test failure in 001_rep_changes.
The check to test whether the subscription workers were restarting after a
change in the subscription was failing. The reason was that the test was
assuming the walsender started before it reaches the 'streaming' state and
the walsender was exiting due to an error before that. Now, the walsender
was erroring out before reaching the 'streaming' state because it tries to
acquire the slot before the previous walsender has exited.
In passing, improve the die messages so that it is easier to investigate
the failures in the future if any.
Reported-by: Michael Paquier, as per buildfarm
Author: Ajin Cherian
Reviewed-by: Masahiko Sawada, Amit Kapila
Backpatch-through: 10, where this test was introduced
Discussion: https://postgr.es/m/YRnhFxa9bo73wfpV@paquier.xyz
Peter Geoghegan [Wed, 1 Sep 2021 03:37:18 +0000 (20:37 -0700)]
VACUUM VERBOSE: Don't report "pages removed".
It doesn't make any sense to report this information, since VACUUM
VERBOSE reports on heap relation truncation directly. This was an
oversight in commit
7ab96cf6, which made VACUUM VERBOSE output a little
more consistent with nearby autovacuum-specific log output. Adjust
comments that describe how this is supposed to work in passing.
Also bring truncation-related VACUUM VERBOSE output in line with the
convention established for VACUUM VERBOSE output by commit
f4f4a649.
Author: Peter Geoghegan <pg@bowt.ie>
Backpatch: 14-, where VACUUM VERBOSE's output changed.
Michael Paquier [Wed, 1 Sep 2021 02:48:08 +0000 (11:48 +0900)]
Refactor one conversion of SQLSTATE to string in elog.c
unpack_sql_state() has been introduced in
d46bc44 to refactor the
unpacking of a SQLSTATE into a string, but it forgot one code path when
sending error reports to clients that could make use of it. This
changes the code to also use unpack_sql_state() there, simplifying a bit
the code.
Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+PuYituuD1-VVZUNcmCQuc3ZzZMPoO57POgm8tnXOkwJAA@mail.gmail.com
Michael Paquier [Wed, 1 Sep 2021 01:28:01 +0000 (10:28 +0900)]
Add PostgresNode::command_fails_like()
This is useful to test for a command failure with some default
connection parameters associated to a node, in combination with checks
on error patterns expected. This routine will be used by an upcoming
future patch, but could be also plugged into some of the existing
tests.
Extracted from a larger patch by the same author.
Author: Ronan Dunklau
Discussion: https://postgr.es/m/
5742739.ga3mSNWIix@aivenronan
Peter Geoghegan [Tue, 31 Aug 2021 23:55:39 +0000 (16:55 -0700)]
Remove obsolete nbtree relation extension comment.
Commit
0d1fe9f7 improved the approach that vacuumlazy.c takes when it
encounters an empty heap page. It no acquires the relation extension
lock.
Peter Geoghegan [Tue, 31 Aug 2021 23:35:01 +0000 (16:35 -0700)]
vacuumlazy.c: Correct prune state comment.
Oversight in commit
7ab96cf6b3.
Tomas Vondra [Tue, 31 Aug 2021 22:42:32 +0000 (00:42 +0200)]
Don't print extra parens around expressions in extended stats
The code printing expressions for extended statistics doubled the
parens, producing results like ((a+1)), which is unnecessary and not
consistent with how we print expressions elsewhere.
Fixed by tweaking the code to produce just a single set of parens.
Reported by Mark Dilger, fix by me. Backpatch to 14, where support for
extended statistics on expressions was added.
Reported-by: Mark Dilger
Discussion: https://postgr.es/m/
20210122040101.GF27167%40telsasoft.com
Peter Geoghegan [Tue, 31 Aug 2021 21:59:52 +0000 (14:59 -0700)]
Remove unneeded old_rel_pages VACUUM state field.
The field hasn't been used since commit
3d351d91, which redefined
pg_class.reltuples to be -1 before the first VACUUM or ANALYZE.
Also rename a local variable of the same name ("old_rel_pages"). This is
used by relation truncation to represent the original relation size at
the start of the ongoing VACUUM operation. Rename it to orig_rel_pages,
since that's a lot clearer. (This name matches similar nearby code.)
Peter Geoghegan [Tue, 31 Aug 2021 19:57:52 +0000 (12:57 -0700)]
Add historic commit to git-blame-ignore-revs file.
Add a historic pgindent commit that was missed by the initial work done
in commit
8e638845.
John Naylor [Tue, 31 Aug 2021 18:15:22 +0000 (14:15 -0400)]
Mark the timestamptz variant of date_bin() as stable
Previously, it was immutable by lack of marking. This is not
correct, since the time zone could change.
Bump catversion
Discussion: https://www.postgresql.org/message-id/CAFBsxsG2UHk8mOWL0tca%3D_cg%2B_oA5mVRNLhDF0TBw980iOg5NQ%40mail.gmail.com
Backpatch to v14, when this function came in
Tom Lane [Tue, 31 Aug 2021 19:04:05 +0000 (15:04 -0400)]
In pg_dump, avoid doing per-table queries for RLS policies.
For no particularly good reason, getPolicies() queried pg_policy
separately for each table. We can collect all the policies in
a single query instead, and attach them to the correct TableInfo
objects using findTableByOid() lookups. On the regression
database, this reduces the number of queries substantially, and
provides a visible savings even when running against a local
server.
Per complaint from Hubert Depesz Lubaczewski. Since this is such
a simple fix and can have a visible performance benefit, back-patch
to all supported branches.
Discussion: https://postgr.es/m/
20210826084430.GA26282@depesz.com
Tom Lane [Tue, 31 Aug 2021 17:53:33 +0000 (13:53 -0400)]
Cache the results of format_type() queries in pg_dump.
There's long been a "TODO: there might be some value in caching
the results" annotation on pg_dump's getFormattedTypeName function;
but we hadn't gotten around to checking what it was costing us to
repetitively look up type names. It turns out that when dumping the
current regression database, about 10% of the total number of queries
issued are duplicative format_type() queries. However, Hubert Depesz
Lubaczewski reported a not-unusual case where these account for over
half of the queries issued by pg_dump. Individually these queries
aren't expensive, but when network lag is a factor, they add up to a
problem. We can very easily add some caching to getFormattedTypeName
to solve it.
Since this is such a simple fix and can have a visible performance
benefit, back-patch to all supported branches.
Discussion: https://postgr.es/m/
20210826084430.GA26282@depesz.com
Tomas Vondra [Tue, 31 Aug 2021 17:21:29 +0000 (19:21 +0200)]
Rename the role in stats_ext to have regress_ prefix
Commit
5be8ce82e8 added a new role to the stats_ext regression suite,
but the role name did not start with regress_ causing failures when
running with ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS. Fixed by
renaming the role to start with the expected regress_ prefix.
Backpatch-through: 10, same as the new regression test
Discussion: https://postgr.es/m/
1F238937-7CC2-4703-A1B1-
6DC225B8978A%40enterprisedb.com
Tomas Vondra [Tue, 31 Aug 2021 16:03:05 +0000 (18:03 +0200)]
Fix lookup error in extended stats ownership check
When an ownership check on extended statistics object failed, the code
was calling aclcheck_error_type to report the failure, which is clearly
wrong, resulting in cache lookup errors. Fix by calling aclcheck_error.
This issue exists since the introduction of extended statistics, so
backpatch all the way back to PostgreSQL 10. It went unnoticed because
there were no tests triggering the error, so add one.
Reported-by: Mark Dilger
Backpatch-through: 10, where extended stats were introduced
Discussion: https://postgr.es/m/
1F238937-7CC2-4703-A1B1-
6DC225B8978A%40enterprisedb.com
Tom Lane [Tue, 31 Aug 2021 16:02:36 +0000 (12:02 -0400)]
Fix missed lock acquisition while inlining new-style SQL functions.
When starting to use a query parsetree loaded from the catalogs,
we must begin by applying AcquireRewriteLocks(), to obtain the same
relation locks that the parser would have gotten if the query were
entered interactively, and to do some other cleanup such as dealing
with later-dropped columns. New-style SQL functions are just as
subject to this rule as other stored parsetrees; however, of the
places dealing with such functions, only init_sql_fcache had gotten
the memo. In particular, if we successfully inlined a new-style
set-returning SQL function that contained any relation references,
we'd either get an assertion failure or attempt to use those
relation(s) sans locks.
I also added AcquireRewriteLocks calls to fmgr_sql_validator and
print_function_sqlbody. Desultory experiments didn't demonstrate any
failures in those, but I suspect that I just didn't try hard enough.
Certainly we don't expect nearby code paths to operate without locks.
On the same logic of it-ought-to-have-the-same-effects-as-the-old-code,
call pg_rewrite_query() in fmgr_sql_validator, too. It's possible
that neither code path there needs to bother with rewriting, but
doing the analysis to prove that is beyond my goals for today.
Per bug #17161 from Alexander Lakhin.
Discussion: https://postgr.es/m/17161-
048a1cdff8422800@postgresql.org
Daniel Gustafsson [Tue, 31 Aug 2021 09:07:04 +0000 (11:07 +0200)]
Prohibit map and grep in void context
map and grep are not intended to be used as mutators, iterating
with side-effects should be done with for or foreach loops. This
fixes the one occurrence of the pattern, and bumps the perlcritic
policy to severity 5 for the map and grep policies.
Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://postgr.es/m/87fsvzhhc4.fsf@wibble.ilmari.org
Michael Paquier [Tue, 31 Aug 2021 03:07:20 +0000 (12:07 +0900)]
Add tab completion for data types after ALTER TABLE ADD [COLUMN] in psql
This allows finding data types that can be used for the creation of a
new column, completing
d3fa876.
Author: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/87h7f7uk6s.fsf@wibble.ilmari.org
Michael Paquier [Tue, 31 Aug 2021 01:19:38 +0000 (10:19 +0900)]
Refactor one use of IDENTIFY_SYSTEM in WAL streaming code of pg_basebackup
0c013e0 has done a large refactoring to unify all the code paths using
replication commands, but forgot one code path doing WAL streaming that
checks the validity of a cluster connecting to with IDENTIFY_SYSTEM.
There is a generic routine able to handle that, so make use of it in
this code path. This impacts pg_receivewal and pg_basebackup.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACVKKYUMC8GE72Y7BP9g1batrrq3sEwUh+1_i2krWZC_2Q@mail.gmail.com
Alvaro Herrera [Mon, 30 Aug 2021 20:29:12 +0000 (16:29 -0400)]
Report tuple address in data-corruption error message
Most data-corruption reports mention the location of the problem, but
this one failed to. Add it.
Backpatch all the way back. In 12 and older, also assign the
ERRCODE_DATA_CORRUPTED error code as was done in commit
fd6ec93bf890 for
13 and later.
Discussion: https://postgr.es/m/
202108191637.oqyzrdtnheir@alvherre.pgsql
Alvaro Herrera [Mon, 30 Aug 2021 18:01:29 +0000 (14:01 -0400)]
psql: Fix name quoting on extended statistics
Per our message style guidelines, for human consumption we quote
qualified names as a whole rather than each part separately; but commits
bc085205c8a4 introduced a deviation for extended statistics and
a4d75c86bf15 copied it. I don't agree with this policy applying to
names shown by psql, but that's a poor reason to deviate from the
practice only in two obscure corners, so make said corners use the same
style as everywhere else.
Backpatch to 14. The first of these is older, but I'm not sure we want
to destabilize the psql output in the older branches for such a small
thing.
Discussion: https://postgr.es/m/
20210828181618.GS26465@telsasoft.com
Fujii Masao [Mon, 30 Aug 2021 12:35:24 +0000 (21:35 +0900)]
pgbench: Avoid unnecessary measurement of connection delays.
Commit
547f04e734 changed pgbench so that it used the measurement result
of connection delays in its benchmark report only when -C/--connect option
is specified. But previously those delays were unnecessarily measured
even when that option is not specified. Which was a waste of cycles.
This commit improves pgbench so that it avoids such unnecessary measurement.
Back-patch to v14 where commit
547f04e734 first appeared.
Author: Yugo Nagata
Reviewed-by: Fabien COELHO, Asif Rehman, Fujii Masao
Discussion: https://postgr.es/m/
20210614151155.
a393bc7d8fed183e38c9f52a@sraoss.co.jp
Amit Kapila [Mon, 30 Aug 2021 03:44:31 +0000 (09:14 +0530)]
Fix incorrect error code in StartupReplicationOrigin().
ERRCODE_CONFIGURATION_LIMIT_EXCEEDED was used for checksum failure, use
ERRCODE_DATA_CORRUPTED instead.
Reported-by: Tatsuhito Kasahara
Author: Tatsuhito Kasahara
Backpatch-through: 9.6, where it was introduced
Discussion: https://postgr.es/m/CAP0=ZVLHtYffs8SOWcFJWrBGoRzT9QQbk+_aP+E5AHLNXiOorA@mail.gmail.com
Amit Kapila [Mon, 30 Aug 2021 03:15:35 +0000 (08:45 +0530)]
Refactor sharedfileset.c to separate out fileset implementation.
Move fileset related implementation out of sharedfileset.c to allow its
usage by backends that don't want to share filesets among different
processes. After this split, fileset infrastructure is used by both
sharedfileset.c and worker.c for the named temporary files that survive
across transactions.
Author: Dilip Kumar, based on suggestion by Andres Freund
Reviewed-by: Hou Zhijie, Masahiko Sawada, Amit Kapila
Discussion: https://postgr.es/m/E1mCC6U-0004Ik-Fs@gemulon.postgresql.org
Michael Paquier [Mon, 30 Aug 2021 00:46:20 +0000 (09:46 +0900)]
Add more tab completion support for ALTER TABLE ADD in psql
This includes the detection of new patterns for various constraint
types, with the addition of USING INDEX for unique indexes of a table
on primary keys and unique constraints.
Author: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/87bl6ehhpl.fsf@wibble.ilmari.org
Tom Lane [Sun, 29 Aug 2021 16:48:49 +0000 (12:48 -0400)]
Doc: add a little about LACON execution to src/backend/regex/README.
I wrote this while thinking about a possible optimization, but it's
a useful description of the existing code regardless of whether the
optimization ever happens. So push it separately.
Alvaro Herrera [Sat, 28 Aug 2021 19:58:23 +0000 (15:58 -0400)]
Keep stats up to date for partitioned tables
In the long-going saga for analyze on partitioned tables, one thing I
missed while reverting
0827e8af70f4 is the maintenance of analyze count
and last analyze time for partitioned tables. This is a mostly trivial
change that enables users assess the need for invoking manual ANALYZE on
partitioned tables.
This patch, posted by Justin and modified a bit by me (Álvaro), can be
mostly traced back to Hosoya-san, though any problems introduced with
the scissors are mine.
Backpatch to 14, in line with
6f8127b73901.
Co-authored-by: Yuzuko Hosoya <yuzukohosoya@gmail.com>
Co-authored-by: Justin Pryzby <pryzby@telsasoft.com>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/
20210816222810.GE10479@telsasoft.com
Alvaro Herrera [Sat, 28 Aug 2021 16:04:15 +0000 (12:04 -0400)]
psql \dX: reference regclass with "pg_catalog." prefix
Déjà vu of commit
fc40ba1296a7, for another backslash command.
Strictly speaking this isn't a bug, but since all references to catalog
objects are schema-qualified, we might as well be consistent. The
omission first appeared in commit
ad600bba0422 and replicated in
a4d75c86bf15; backpatch to 14.
Author: Justin Pryzby <pryzbyj@telsasoft.com>
Discussion: https://postgr.es/m/
20210827193151.GN26465@telsasoft.com
Alvaro Herrera [Sat, 28 Aug 2021 15:45:47 +0000 (11:45 -0400)]
psql \dP: reference regclass with "pg_catalog." prefix
Strictly speaking this isn't a bug, but since all references to catalog
objects are schema-qualified, we might as well be consistent. The
omission first appeared in commit
1c5d9270e339, so backpatch to 12.
Author: Justin Pryzby <pryzbyj@telsasoft.com>
Discussion: https://postgr.es/m/
20210827193151.GN26465@telsasoft.com
Noah Misch [Sat, 28 Aug 2021 06:33:23 +0000 (23:33 -0700)]
Fix data loss in wal_level=minimal crash recovery of CREATE TABLESPACE.
If the system crashed between CREATE TABLESPACE and the next checkpoint,
the result could be some files in the tablespace unexpectedly containing
no rows. Affected files would be those for which the system did not
write WAL; see the wal_skip_threshold documentation. Before v13, a
different set of conditions governed the writing of WAL; see v12's
<sect2 id="populate-pitr">. (The v12 conditions were broader in some
ways and narrower in others.) Users may want to audit non-default
tablespaces for unexpected short files. The bug could have truncated an
index without affecting the associated table, and reindexing the index
would fix that particular problem.
This fixes the bug by making create_tablespace_directories() more like
TablespaceCreateDbspace(). create_tablespace_directories() was
recursively removing tablespace contents, reasoning that WAL redo would
recreate everything removed that way. That assumption holds for other
wal_level values. Under wal_level=minimal, the old approach could
delete files for which no other copy existed. Back-patch to 9.6 (all
supported versions).
Reviewed by Robert Haas and Prabhat Sahu. Reported by Robert Haas.
Discussion: https://postgr.es/m/CA+TgmoaLO9ncuwvr2nN-J4VEP5XyAcy=zKiHxQzBbFRxxGxm0w@mail.gmail.com
Tom Lane [Fri, 27 Aug 2021 23:42:42 +0000 (19:42 -0400)]
Count SP-GiST index scans in pg_stat statistics.
Somehow, spgist overlooked the need to call pgstat_count_index_scan().
Hence, pg_stat_all_indexes.idx_scan and equivalent columns never
became nonzero for an SP-GiST index, although the related per-tuple
counters worked fine.
This fix works a bit differently from other index AMs, in that the
counter increment occurs in spgrescan not spggettuple/spggetbitmap.
It looks like this won't make the user-visible semantics noticeably
different, so I won't go to the trouble of introducing an is-this-
the-first-call flag just to make the counter bumps happen in the
same places.
Per bug #17163 from Christian Quest. Back-patch to all supported
versions.
Discussion: https://postgr.es/m/17163-
b8c5cc88322a5e92@postgresql.org
Stephen Frost [Fri, 27 Aug 2021 23:23:14 +0000 (19:23 -0400)]
Use maintenance_io_concurrency for ANALYZE prefetch
When prefetching pages for ANALYZE, we should be using
maintenance_io_concurrenty (by calling
get_tablespace_maintenance_io_concurrency(), not
get_tablespace_io_concurrency()).
ANALYZE prefetching was introduced in
c6fc50c, so back-patch to 14.
Backpatch-through: 14
Reported-By: Egor Rogov
Discussion: https://postgr.es/m/
9beada99-34ce-8c95-fadb-
451768d08c64%40postgrespro.ru
Stephen Frost [Fri, 27 Aug 2021 22:25:26 +0000 (18:25 -0400)]
docs: Add command tags for SQL commands
Commit
6c3ffd6 added a couple new predefined roles but didn't properly
wrap the SQL commands mentioned in the description of those roles with
command tags, so add them now.
Backpatch-through: 14
Reported-by: Michael Banck
Discussion: https://postgr.es/m/
606d8b1c.
1c69fb81.3df04.1a99@mx.google.com
Daniel Gustafsson [Fri, 27 Aug 2021 20:50:19 +0000 (22:50 +0200)]
docs: clarify bgw_restart_time documentation
Author: Dave Cramer <davecramer@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CADK3HHLZmqAQZ2ByPDQQ9yhGqax36kksq6sDkV0yYzsxw6ipvQ@mail.gmail.com
Peter Geoghegan [Fri, 27 Aug 2021 20:34:00 +0000 (13:34 -0700)]
track_io_timing logging: Don't special case 0 ms.
Adjust track_io_timing related logging code added by commit
94d13d474d.
Make it consistent with other nearby autovacuum and autoanalyze logging
code by removing logic that suppressed zero millisecond outputs.
log_autovacuum_min_duration log output now reliably shows "read:" and
"write:" millisecond-based values in its report (when track_io_timing is
enabled).
Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-By: Stephen Frost <sfrost@snowman.net>
Discussion: https://postgr.es/m/CAH2-WznW0FNxSVQMSRazAMYNfZ6DR_gr5WE78hc6E1CBkkJpzw@mail.gmail.com
Backpatch: 14-, where the track_io_timing logging was introduced.
Peter Geoghegan [Fri, 27 Aug 2021 20:08:41 +0000 (13:08 -0700)]
Reorder log_autovacuum_min_duration log output.
This order seems more natural. It starts with details that are
particular to heap and index data structures, and ends with system-level
costs incurred during the autovacuum worker's VACUUM/ANALYZE operation.
Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WzkzxK6ahA9xxsOftRtBX_R0swuHZsvo4QUbak1Bz7hb7Q@mail.gmail.com
Backpatch: 14-, which enhanced the log output in various ways.
Peter Geoghegan [Fri, 27 Aug 2021 16:47:16 +0000 (09:47 -0700)]
vacuumlazy.c: Remove unnecessary parentheses.
This was arguably a minor oversight in commit
b4af70cb, which cleaned up
the function signatures of functions that modify IndexBulkDeleteResult
variables.
Peter Eisentraut [Fri, 27 Aug 2021 16:15:57 +0000 (18:15 +0200)]
Change Texinfo output to UTF-8
Since the whole documentation tool chain is now UTF-8 and there is an
increasing number of non-ISO-8859-1 characters in the text, keeping
the Texinfo output in ISO 8859-1 just creates unnecessary
complications. Depending on the platform, there are conversion
failures and thus build failures, or weirdly converted characters. By
changing the output to UTF-8, the whole encoding conversion business
is sidestepped.
Tom Lane [Fri, 27 Aug 2021 16:18:58 +0000 (12:18 -0400)]
Handle interaction of regexp's makesearch and MATCHALL more honestly.
Second thoughts about commit
824bf7190: we apply makesearch() to
an NFA after having determined whether it is a MATCHALL pattern.
Prepending ".*" doesn't make it non-MATCHALL, but it does change the
maximum possible match length, and makesearch() failed to update that.
This has no ill effects given the stylized usage of search NFAs, but
it seems like it's better to keep the data structure consistent. In
particular, fixing this allows more honest handling of the MATCHALL
check in matchuntil(): we can now assert that maxmatchall is infinity,
instead of lamely assuming that it should act that way.
In passing, improve the code in dump[c]nfa so that infinite maxmatchall
is printed as "inf" not a magic number.
Daniel Gustafsson [Fri, 27 Aug 2021 14:24:33 +0000 (16:24 +0200)]
Avoid invoking PQfnumber in loop constructs
When looping over the resultset from a SQL query, extracting the field
number before the loop body to avoid repeated calls to PQfnumber is an
established pattern. On very wide tables this can have a performance
impact, but it wont be noticeable in the common case. This fixes a few
queries which were extracting the field number in the loop body.
Author: Hou Zhijie <houzj.fnst@fujitsu.com>
Reviewed-by: Nathan Bossart <bossartn@amazon.com>
Discussion: https://postgr.es/m/OS0PR01MB57164C392783F29F6D0ECA0B94139@OS0PR01MB5716.jpnprd01.prod.outlook.com
Amit Kapila [Fri, 27 Aug 2021 03:00:23 +0000 (08:30 +0530)]
Add logical change details to logical replication worker errcontext.
Previously, on the subscriber, we set the error context callback for the
tuple data conversion failures. This commit replaces the existing error
context callback with a comprehensive one so that it shows not only the
details of data conversion failures but also the details of logical change
being applied by the apply worker or table sync worker. The additional
information displayed will be the command, transaction id, and timestamp.
The error context is added to an error only when applying a change but not
while doing other work like receiving data etc.
This will help users in diagnosing the problems that occur during logical
replication. It also can be used for future work that allows skipping a
particular transaction on the subscriber.
Author: Masahiko Sawada
Reviewed-by: Hou Zhijie, Greg Nancarrow, Haiying Tang, Amit Kapila
Tested-by: Haiying Tang
Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
Peter Geoghegan [Fri, 27 Aug 2021 01:42:20 +0000 (18:42 -0700)]
contrib/amcheck: Add heapam CHECK_FOR_INTERRUPTS().
Add a CHECK_FOR_INTERRUPTS() call to make heap relation verification
responsive to query cancellations.
Author: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://postgr.es/m/CAH2-Wzk-9RtQgb2QiuLv8j2O0j9tSFKPmmch5nWSZhguUxvbrw%40mail.gmail.com
Backpatch: 14-, where amcheck heap verification was introduced.
John Naylor [Thu, 26 Aug 2021 17:07:34 +0000 (13:07 -0400)]
Extend collection of Unicode combining characters to beyond the BMP
The former limit was perhaps a carryover from an older hand-coded
table. Since commit
bab982161 we have enough space in mbinterval to
store larger codepoints, so collect all combining characters.
Discussion: https://www.postgresql.org/message-id/
49ad1fa0-174e-c901-b14c-
c484b60907f1%40enterprisedb.com
John Naylor [Thu, 26 Aug 2021 14:53:56 +0000 (10:53 -0400)]
Update display widths as part of updating Unicode
The hardcoded "wide character" set in ucs_wcwidth() was last updated
around the Unicode 5.0 era. This led to misalignment when printing
emojis and other codepoints that have since been designated
wide or full-width.
To fix and keep up to date, extend update-unicode to download the list
of wide and full-width codepoints from the offical sources.
In passing, remove some comments about non-spacing characters that
haven't been accurate since we removed the former hardcoded logic.
Jacob Champion
Reported and reviewed by Pavel Stehule
Discussion: https://www.postgresql.org/message-id/flat/CAFj8pRCeX21O69YHxmykYySYyprZAqrKWWg0KoGKdjgqcGyygg@mail.gmail.com
John Naylor [Thu, 26 Aug 2021 14:06:12 +0000 (10:06 -0400)]
Revert "Rename unicode_combining_table to unicode_width_table"
This reverts commit
eb0d0d2c7300c9c5c22b35975c11265aa4becc84.
After I had committed
eb0d0d2c7 and
78ab944cd, I decided to add
a sanity check for a "can't happen" scenario just to be cautious.
It turned out that it already happened in the official Unicode source
data, namely that a character can be both wide and a combining
character. This fact renders the aforementioned commits unnecessary,
so revert both of them.
Discussion: https://www.postgresql.org/message-id/CAFBsxsH5ejH4-1xaTLpSK8vWoK1m6fA1JBtTM6jmBsLfmDki1g%40mail.gmail.com
John Naylor [Thu, 26 Aug 2021 13:58:28 +0000 (09:58 -0400)]
Revert "Change mbbisearch to return the character range"
This reverts commit
78ab944cd4b9977732becd9d0bc83223b88af9a2.
After I had committed
eb0d0d2c7 and
78ab944cd, I decided to add
a sanity check for a "can't happen" scenario just to be cautious.
It turned out that it already happened in the official Unicode source
data, namely that a character can be both wide and a combining
character. This fact renders the aforementioned commits unnecessary,
so revert both of them.
Discussion:
https://www.postgresql.org/message-id/CAFBsxsH5ejH4-1xaTLpSK8vWoK1m6fA1JBtTM6jmBsLfmDki1g%40mail.gmail.com
Peter Eisentraut [Thu, 26 Aug 2021 06:48:07 +0000 (08:48 +0200)]
Fix handling of partitioned index in RelationGetNumberOfBlocksInFork()
Since a partitioned index doesn't have storage, getting the number of
blocks from it will not give sensible results. Existing callers
already check that they don't call it that way, so there doesn't
appear to be a live problem. But for correctness, handle
RELKIND_PARTITIONED_INDEX together with the other non-storage
relkinds.
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/
1d3a5fbe-f48b-8bea-80da-
9a5c4244aef9@enterprisedb.com
John Naylor [Fri, 20 Aug 2021 15:10:17 +0000 (11:10 -0400)]
Change mbbisearch to return the character range
Add a width field to mbinterval and have mbbisearch return a
pointer to the found range rather than just bool for success.
A future commit will add another width besides zero, and this
will allow that to use the same search.
Reviewed by Jacob Champion
Discussion: https://www.postgresql.org/message-id/CAFBsxsGOCpzV7c-f3a8ADsA1n4uZ%3D8puCctQp%2Bx7W0vgkv%3Dw%2Bg%40mail.gmail.com
John Naylor [Fri, 20 Aug 2021 14:34:26 +0000 (10:34 -0400)]
Rename unicode_combining_table to unicode_width_table
No functional changes. A future commit will use this table for
other purposes besides combining characters.
Tom Lane [Wed, 25 Aug 2021 15:06:34 +0000 (11:06 -0400)]
Remove redundant test.
The condition "context_start < context_end" is strictly weaker
than "context_end - context_start >= 50", so we don't need both.
Oversight in commit
ffd3944ab, noted by tanghy.fnst.
In passing, line-wrap a nearby test to make it more readable.
Discussion: https://postgr.es/m/OS0PR01MB61137C4054774F44E3A9DC89FBC69@OS0PR01MB6113.jpnprd01.prod.outlook.com
Robert Haas [Wed, 25 Aug 2021 12:32:04 +0000 (08:32 -0400)]
Fix broken snapshot handling in parallel workers.
Pengchengliu reported an assertion failure in a parallel woker while
performing a parallel scan using an overflowed snapshot. The proximate
cause is that TransactionXmin was set to an incorrect value. The
underlying cause is incorrect snapshot handling in parallel.c.
In particular, InitializeParallelDSM() was unconditionally calling
GetTransactionSnapshot(), because I (rhaas) mistakenly thought that
was always retrieving an existing snapshot whereas, at isolation
levels less than REPEATABLE READ, it's actually taking a new one. So
instead do this only at higher isolation levels where there actually
is a single snapshot for the whole transaction.
By itself, this is not a sufficient fix, because we still need to
guarantee that TransactionXmin gets set properly in the workers. The
easiest way to do that seems to be to install the leader's active
snapshot as the transaction snapshot if the leader did not serialize a
transaction snapshot. This doesn't affect the results of future
GetTrasnactionSnapshot() calls since those have to take a new snapshot
anyway; what we care about is the side effect of setting TransactionXmin.
Report by Pengchengliu. Patch by Greg Nancarrow, except for some comment
text which I supplied.
Discussion: https://postgr.es/m/
002f01d748ac$
eaa781a0$
bff684e0$@tju.edu.cn
Peter Eisentraut [Wed, 25 Aug 2021 09:54:58 +0000 (11:54 +0200)]
psql: Make cancel test more timing robust
The previous coding relied on the PID file appearing and the query
starting "fast enough", which can fail on slow machines. Also, there
might have been an undocumented interference between alarm and
IPC::Run. This new coding doesn't rely on any of these concurrency
mechanisms. Instead, we wait unitl the PID file is complete before
proceeding, and then also wait until the sleep query is registered by
the server.
Discussion: https://www.postgresql.org/message-id/flat/E1mH14Q-0002gh-HS%40gemulon.postgresql.org
Peter Eisentraut [Wed, 25 Aug 2021 08:14:51 +0000 (10:14 +0200)]
Fix typo
Michael Paquier [Wed, 25 Aug 2021 06:16:31 +0000 (15:16 +0900)]
Fix incorrect merge in ECPG code with DECLARE
The same condition was repeated twice when comparing the connection used
by existing declared statement with the one coming from a fresh DECLARE
statement. This had no consequences, but let's keep the code clean.
Oversight in
f576de1.
Author: Shenhao Wang
Discussion: https://postgr.es/m/OSBPR01MB42149653BC0AB0A49D23C1B8F2C69@OSBPR01MB4214.jpnprd01.prod.outlook.com
Backpatch-through: 14
Amit Kapila [Wed, 25 Aug 2021 04:23:07 +0000 (09:53 +0530)]
Fix toast rewrites in logical decoding.
Commit
325f2ec555 introduced pg_class.relwrite to skip operations on
tables created as part of a heap rewrite during DDL. It links such
transient heaps to the original relation OID via this new field in
pg_class but forgot to do anything about toast tables. So, logical
decoding was not able to skip operations on internally created toast
tables. This leads to an error when we tried to decode the WAL for the
next operation for which it appeared that there is a toast data where
actually it didn't have any toast data.
To fix this, we set pg_class.relwrite for internally created toast tables
as well which allowed skipping operations on them during logical decoding.
Author: Bertrand Drouvot
Reviewed-by: David Zhang, Amit Kapila
Backpatch-through: 11, where it was introduced
Discussion: https://postgr.es/m/
b5146fb1-ad9e-7d6e-f980-
98ed68744a7c@amazon.com
Etsuro Fujita [Wed, 25 Aug 2021 04:00:00 +0000 (13:00 +0900)]
Doc: Tweak function prototype indentation for consistency.
Michael Paquier [Wed, 25 Aug 2021 03:00:31 +0000 (12:00 +0900)]
Add tab completion for EXPLAIN .. EXECUTE in psql
Author: Dagfinn Ilmari Mannsåker
Discussion: https://posgr.es/m/871r75gd0i.fsf@wibble.ilmari.org
Fujii Masao [Wed, 25 Aug 2021 02:46:25 +0000 (11:46 +0900)]
Avoid using ambiguous word "positive" in error message.
There are two identical error messages about valid value of modulus for
hash partition, in PostgreSQL source code. Commit
0e1275fb07 improved
only one of them so that ambiguous word "positive" was avoided there,
and forgot to improve the other. This commit improves the other.
Which would reduce translator burden.
Back-pach to v11 where the error message exists.
Author: Kyotaro Horiguchi
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/
20210819.170315.
1413060634876301811.horikyota.ntt@gmail.com
Fujii Masao [Wed, 25 Aug 2021 02:43:56 +0000 (11:43 +0900)]
Improve error message about valid value for distance in phrase operator.
The distance in phrase operator must be an integer value between zero
and MAXENTRYPOS inclusive. But previously the error message about
its valid value included the information about its upper limit
but not lower limit (i.e., zero). This commit improves the error message
so that it also includes the information about its lower limit.
Back-patch to v9.6 where full-text phrase search was supported.
Author: Kyotaro Horiguchi
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/
20210819.170315.
1413060634876301811.horikyota.ntt@gmail.com
Fujii Masao [Wed, 25 Aug 2021 00:56:04 +0000 (09:56 +0900)]
ecpg: Remove trailing period from error message.
This commit improves the ecpg's error message that commit
f576de1db1 updated,
so that it gets rid of trailing period and uppercases the command name
in the error message.
Author: Kyotaro Horiguchi
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/
20210819.170315.
1413060634876301811.horikyota.ntt@gmail.com
Tom Lane [Tue, 24 Aug 2021 20:37:26 +0000 (16:37 -0400)]
Fix regexp misbehavior with capturing parens inside "{0}".
Regexps like "(.){0}...\1" drew an "invalid backreference number".
That's not unreasonable on its face, since the capture group will
never be matched if it's iterated zero times. However, other engines
such as Perl's don't complain about this, nor do we throw an error for
related cases such as "(.)|\1", even though that backref can never
succeed either. Also, if the zero-iterations case happens at runtime
rather than compile time --- say, "(x)*...\1" when there's no "x" to
be found --- that's not an error, we just deem the backref to not
match. Making this even less defensible, no error was thrown for
nested cases such as "((.)){0}...\2"; and to add insult to injury,
those cases could result in assertion failures instead. (It seems
that nothing especially bad happened in non-assert builds, though.)
Let's just fix it so that no error is thrown and instead the backref
is deemed to never match, so that compile-time detection of no
iterations behaves the same as run-time detection.
Per report from Mark Dilger. This appears to be an aboriginal error
in Spencer's library, so back-patch to all supported versions.
Pre-v14, it turns out to also be necessary to back-patch one aspect of
commits
cb76fbd7e/
00116dee5, namely to create capture-node subREs with
the begin/end states of their subexpressions, not the current lp/rp
of the outer parseqatom invocation. Otherwise delsub complains that
we're trying to disconnect a state from itself. This is a bit scary
but code examination shows that it's safe: in the pre-v14 code, if we
want to wrap iteration around the subexpression, the first thing we do
is overwrite the atom's begin/end fields with new states. So the
bogus values didn't survive long enough to be used for anything, except
if no iteration is required, in which case it doesn't matter.
Discussion: https://postgr.es/m/
A099E4A8-4377-4C64-A98C-
3DEDDC075502@enterprisedb.com
Amit Kapila [Tue, 24 Aug 2021 02:55:21 +0000 (08:25 +0530)]
Fix Alter Subscription's Add/Drop Publication behavior.
The current refresh behavior tries to just refresh added/dropped
publications but that leads to removing wrong tables from subscription. We
can't refresh just the dropped publication because it is quite possible
that some of the tables are removed from publication by that time and now
those will remain as part of the subscription. Also, there is a chance
that the tables that were part of the publication being dropped are also
part of another publication, so we can't remove those.
So, we decided that by default, add/drop commands will also act like
REFRESH PUBLICATION which means they will refresh all the publications. We
can keep the old behavior for "add publication" but it is better to be
consistent with "drop publication".
Author: Hou Zhijie
Reviewed-by: Masahiko Sawada, Amit Kapila
Backpatch-through: 14, where it was introduced
Discussion: https://postgr.es/m/OS0PR01MB5716935D4C2CC85A6143073F94EF9@OS0PR01MB5716.jpnprd01.prod.outlook.com
Tom Lane [Mon, 23 Aug 2021 21:41:07 +0000 (17:41 -0400)]
Prevent regexp back-refs from sometimes matching when they shouldn't.
The recursion in cdissect() was careless about clearing match data
for capturing parentheses after rejecting a partial match. This
could allow a later back-reference to succeed when by rights it
should fail for lack of a defined referent.
To fix, think a little more rigorously about what the contract
between different levels of cdissect's recursion needs to be.
With the right spec, we can fix this using fewer rather than more
resets of the match data; the key decision being that a failed
sub-match is now explicitly responsible for clearing any matches
it may have set.
There are enough other cross-checks and optimizations in the code
that it's not especially easy to exhibit this problem; usually, the
match will fail as-expected. Plus, regexps that are even potentially
vulnerable are most likely user errors, since there's just not much
point in writing a back-ref that doesn't always have a referent.
These facts perhaps explain why the issue hasn't been detected,
even though it's almost certainly a couple of decades old.
Discussion: https://postgr.es/m/151435.
1629733387@sss.pgh.pa.us
Alvaro Herrera [Mon, 23 Aug 2021 19:50:35 +0000 (15:50 -0400)]
Avoid creating archive status ".ready" files too early
WAL records may span multiple segments, but XLogWrite() does not
wait for the entire record to be written out to disk before
creating archive status files. Instead, as soon as the last WAL page of
the segment is written, the archive status file is created, and the
archiver may process it. If PostgreSQL crashes before it is able to
write and flush the rest of the record (in the next WAL segment), the
wrong version of the first segment file lingers in the archive, which
causes operations such as point-in-time restores to fail.
To fix this, keep track of records that span across segments and ensure
that segments are only marked ready-for-archival once such records have
been completely written to disk.
This has always been wrong, so backpatch all the way back.
Author: Nathan Bossart <bossartn@amazon.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Ryo Matsumura <matsumura.ryo@fujitsu.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://postgr.es/m/
CBDDFA01-6E40-46BB-9F98-
9340F4379505@amazon.com
Bruce Momjian [Mon, 23 Aug 2021 16:33:38 +0000 (12:33 -0400)]
Improve defaults shown in postgresql.conf.sample and pg_settings
Previously, these showed unlikely default values. The new default value
128MB (since PG 10) is not always accurate since initdb tries several
increasing values, but it likely to be accurate.
Reported-by: Zhangjie <zhangjie2@fujitsu.com>
Discussion: https://postgr.es/m/TYWPR01MB7678772FD8640C404F1DC882F9079@TYWPR01MB7678.jpnprd01.prod.outlook.com
Author: Zhangjie
Backpatch-through: master
Michael Paquier [Mon, 23 Aug 2021 02:09:33 +0000 (11:09 +0900)]
Fix backup manifests to generate correct WAL-Ranges across timelines
In a backup manifest, WAL-Ranges stores the range of WAL that is
required for the backup to be valid. pg_verifybackup would then
internally use pg_waldump for the checks based on this data.
When the timeline where the backup started was more than 1 with a
history file looked at for the manifest data generation, the calculation
of the WAL range for the first timeline to check was incorrect. The
previous logic used as start LSN the start position of the first
timeline, but it needs to use the start LSN of the backup. This would
cause failures with pg_verifybackup, or any tools making use of the
backup manifests.
This commit adds a test based on a logic using a self-promoted node,
making it rather cheap.
Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/
20210818.143031.
1867083699202617521.horikyota.ntt@gmail.com
Backpatch-through: 13
Peter Eisentraut [Sun, 22 Aug 2021 16:41:31 +0000 (18:41 +0200)]
psql: Improve portability of query cancel test
Some shells apparently don't support $PPID, so skip the test in that
case.
David Rowley [Sun, 22 Aug 2021 13:44:20 +0000 (01:44 +1200)]
Fix broken regression test caused by
22c4e88eb
Per buildfarm members hoverfly and thorntail
David Rowley [Sun, 22 Aug 2021 11:31:16 +0000 (23:31 +1200)]
Allow parallel DISTINCT
We've supported parallel aggregation since
e06a38965. At the time, we
didn't quite get around to also adding parallel DISTINCT. So, let's do
that now.
This is implemented by introducing a two-phase DISTINCT. Phase 1 is
performed on parallel workers, rows are made distinct there either by
hashing or by sort/unique. The results from the parallel workers are
combined and the final distinct phase is performed serially to get rid of
any duplicate rows that appear due to combining rows for each of the
parallel workers.
Author: David Rowley
Reviewed-by: Zhihong Yu
Discussion: https://postgr.es/m/CAApHDvrjRxVKwQN0he79xS+9wyotFXL=RmoWqGGO2N45Farpgw@mail.gmail.com
Tom Lane [Sat, 21 Aug 2021 14:22:14 +0000 (10:22 -0400)]
Improve error messages about misuse of SELECT INTO.
Improve two places in plpgsql, and one in spi.c, where an error
message would confusingly tell you that you couldn't use a SELECT
query, when what you had written *was* a SELECT query. The actual
problem is that you can't use SELECT ... INTO in these contexts,
but the messages failed to make that apparent. Special-case
SELECT INTO to make these errors more helpful.
Also, fix the same spots in plpgsql, as well as several messages
in exec_eval_expr(), to not quote the entire complained-of query or
expression in the primary error message. That behavior very easily
led to violating our message style guideline about keeping the primary
error message short and single-line. Also, since the important part
of the message was after the inserted text, it could make the real
problem very hard to see. We can report the query or expression as
the first line of errcontext instead.
Per complaint from Roger Mason. Back-patch to v14, since (a) some
of these messages are new in v14 and (b) v14's translatable strings
are still somewhat in flux. The problem's older than that of
course, but I'm hesitant to change the behavior further back.
Discussion: https://postgr.es/m/
1914708.
1629474624@sss.pgh.pa.us
Tom Lane [Fri, 20 Aug 2021 18:19:04 +0000 (14:19 -0400)]
Fix performance bug in regexp's citerdissect/creviterdissect.
After detecting a sub-match "dissect" failure (i.e., a backref match
failure) in the i'th sub-match of an iteration node, we should proceed
by adjusting the attempted length of the i'th submatch. As coded,
though, these functions changed the attempted length of the *last*
sub-match, and only after exhausting all possibilities for that would
they back up to adjust the next-to-last sub-match, and then the
second-from-last, etc; all of which is wasted effort, since only
changing the start or length of the i'th sub-match can possibly make
it succeed. This oversight creates the possibility for exponentially
bad performance. Fortunately the problem is masked in most cases by
optimizations or constraints applied elsewhere; which explains why
we'd not noticed it before. But it is possible to reach the problem
with fairly simple, if contrived, regexps.
Oversight in my commit
173e29aa5. That's pretty ancient now,
so back-patch to all supported branches.
Discussion: https://postgr.es/m/
1808998.
1629412269@sss.pgh.pa.us
Daniel Gustafsson [Fri, 20 Aug 2021 10:44:54 +0000 (12:44 +0200)]
Remove --quiet option from pg_amcheck
Using --quiet in combination with --no-strict-names didn't work as
documented, a warning message was still emitted. Since the --quiet
flag was working in an unconventional way to other utilities, fix
by removing the functionality instead.
Backpatch through 14 where pg_amcheck was introduced.
Bug: 17148
Reported-by: Chen Jiaoqian <chenjq.jy@fujitsu.com>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://postgr.es/m/17148-
b5087318e2b04fc6@postgresql.org
Backpatch-through: 14
Peter Eisentraut [Fri, 20 Aug 2021 09:28:56 +0000 (11:28 +0200)]
psql: Add test for query canceling
Query canceling in psql was accidentally broken by
3a5130672296ed4e682403a77a9a3ad3d21cef75 (since reverted), so having
some test coverage for that seems useful.
Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr>
Discussion: https://www.postgresql.org/message-id/
18c78a01-4a34-9dd4-f78b-
6860f1420c8e@enterprisedb.com
Peter Eisentraut [Fri, 20 Aug 2021 05:54:23 +0000 (07:54 +0200)]
pg_resetwal: Improve numeric command-line argument parsing
Check errno after strtoul()/strtol() to handle out of range errors
better. For out of range, strtoul() returns ULONG_MAX, and the
previous code would proceed with that result.
Reported-by: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/
6a10a211-872b-3c4c-106b-
909ae5fefa61%40enterprisedb.com
Peter Eisentraut [Fri, 20 Aug 2021 05:48:22 +0000 (07:48 +0200)]
pg_amcheck: Fix block number parsing on command line
The previous code wouldn't handle higher block numbers on systems
where sizeof(long) == 4.
Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/
6a10a211-872b-3c4c-106b-
909ae5fefa61%40enterprisedb.com
Tom Lane [Thu, 19 Aug 2021 16:12:35 +0000 (12:12 -0400)]
Avoid trying to lock OLD/NEW in a rule with FOR UPDATE.
transformLockingClause neglected to exclude the pseudo-RTEs for
OLD/NEW when processing a rule's query. This led to odd errors
or even crashes later on. This bug is very ancient, but it's
not terribly surprising that nobody noticed, since the use-case
for SELECT FOR UPDATE in a non-view rule is somewhere between
thin and non-existent. Still, crashing is not OK.
Per bug #17151 from Zhiyong Wu. Thanks to Masahiko Sawada
for analysis of the problem.
Discussion: https://postgr.es/m/17151-
c03a3e6e4ec9aadb@postgresql.org
Andres Freund [Thu, 19 Aug 2021 11:59:06 +0000 (04:59 -0700)]
Unset MyBEEntry, making elog.c's call to pgstat_get_my_query_id() safe.
Previously log messages late during shutdown could end up using either another
backend's PgBackendStatus (multi user) or segfault (single user) because
pgstat_get_my_query_id()'s check for !MyBEEntry didn't filter out use after
pgstat_beshutdown_hook().
This became a bug in
4f0b0966c86, but was a bit fishy before. But given
there's no known problematic cases before 14, it doesn't seem worth
backpatching further.
Also fixes a wrong filename in a comment, introduced in
e1025044.
Reported-By: Andres Freund <andres@anarazel.de>
Reviewed-By: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://postgr.es/m/Julien Rouhaud <rjuju123@gmail.com>
Backpatch: 14-