Peter Eisentraut [Tue, 26 Sep 2023 10:28:57 +0000 (11:28 +0100)]
Add some const qualifiers
There was a mismatch between the const qualifiers for
excludeDirContents in src/backend/backup/basebackup.c and
src/bin/pg_rewind/filemap.c, which led to a quick search for similar
cases. We should make excludeDirContents match, but the rest of the
changes seem like a good idea as well.
Author: David Steele <david@pgmasters.net>
Discussion: https://www.postgresql.org/message-id/flat/
669a035c-d23d-2f38-7ff0-
0cb93e01d610@pgmasters.net
Peter Eisentraut [Tue, 26 Sep 2023 08:09:36 +0000 (09:09 +0100)]
Clean up MergeAttributesIntoExisting()
Make variable naming clearer and more consistent. Move some variables
to smaller scope. Remove some unnecessary intermediate variables.
Try to save some vertical space.
Apply analogous changes to nearby MergeConstraintsIntoExisting() and
RemoveInheritance() for consistency.
Discussion: https://www.postgresql.org/message-id/flat/
52a125e4-ff9a-95f5-9f61-
b87cf447e4da%40eisentraut.org
Peter Eisentraut [Thu, 24 Aug 2023 06:26:13 +0000 (08:26 +0200)]
Remove unused include
This was added in
add5cf28d4 but was apparently never used.
Discussion: https://www.postgresql.org/message-id/flat/
f84640e3-00d3-5abd-3f41-
e6a19d33c40b@eisentraut.org
Michael Paquier [Tue, 26 Sep 2023 00:29:47 +0000 (09:29 +0900)]
Fix behavior of "force" in pgstat_report_wal()
As implemented in
5891c7a8ed8f, setting "force" to true in
pgstat_report_wal() causes the routine to not wait for the pgstat
shmem lock if it cannot be acquired, in which case the WAL and I/O
statistics finish by not being flushed. The origin of the confusion
comes from pgstat_flush_wal() and pgstat_flush_io(), that use "nowait"
as sole argument. The I/O stats are new in v16.
This is the opposite behavior of what has been used in
pgstat_report_stat(), where "force" is the opposite of "nowait". In
this case, when "force" is true, the routine sets "nowait" to false,
which would cause the routine to wait for the pgstat shmem lock,
ensuring that the stats are always flushed. When "force" is false,
"nowait" is set to true, and the stats would only not be flushed if the
pgstat shmem lock can be acquired, returning immediately without
flushing the stats if the lock cannot be acquired.
This commit changes pgstat_report_wal() so as "force" has the same
behavior as in pgstat_report_stat(). There are currently three callers
of pgstat_report_wal():
- Two in the checkpointer where force=true during a shutdown and the
main checkpointer loop. Now the code behaves so as the stats are always
flushed.
- One in the main loop of the bgwriter, where force=false. Now the code
behaves so as the stats would not be flushed if the pgstat shmem lock
could not be acquired.
Before this commit, some stats on WAL and I/O could have been lost after
a shutdown, for example.
Reported-by: Ryoga Yoshida
Author: Ryoga Yoshida, Michael Paquier
Discussion: https://postgr.es/m/
f87a4d7be70530606b864fd1df91718c@oss.nttdata.com
Backpatch-through: 15
Michael Paquier [Mon, 25 Sep 2023 23:16:12 +0000 (08:16 +0900)]
doc: Tell about "vcregress taptest" for regression tests on Windows
There was no mention of this command in the documentation, and it is
useful to run the TAP tests of a target source directory.
Author: Yugo Nagata
Discussion: https://postgr.es/m/
20230925153204.
926d685d347ee1c8f527090c@sraoss.co.jp
Backpatch-through: 11
Thomas Munro [Mon, 25 Sep 2023 20:07:26 +0000 (09:07 +1300)]
Fix edge-case for xl_tot_len broken by
bae868ca.
bae868ca removed a check that was still needed. If you had an
xl_tot_len at the end of a page that was too small for a record header,
but not big enough to span onto the next page, we'd immediately perform
the CRC check using a bogus large length. Because of arbitrary coding
differences between the CRC implementations on different platforms,
nothing very bad happened on common modern systems. On systems using
the _sb8.c fallback we could segfault.
Restore that check, add a new assertion and supply a test for that case.
Back-patch to 12, like
bae868ca.
Tested-by: Tom Lane <tgl@sss.pgh.pa.us>
Tested-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKGLCkTT7zYjzOxuLGahBdQ%3DMcF%3Dz5ZvrjSOnW4EDhVjT-g%40mail.gmail.com
Nathan Bossart [Mon, 25 Sep 2023 21:12:43 +0000 (14:12 -0700)]
Add worker type to pg_stat_subscription.
Thanks to commit
2a8b40e368, the logical replication worker type is
easily determined. The worker type could already be deduced via
other columns such as leader_pid and relid, but that is unnecessary
complexity for users.
Bumps catversion.
Author: Peter Smith
Reviewed-by: Michael Paquier, Maxim Orlov, Amit Kapila
Discussion: https://postgr.es/m/CAHut%2BPtmbSMfErSk0S7xxVdZJ9XVE3xVLhqBTmT91kf57BeKDQ%40mail.gmail.com
Andres Freund [Mon, 25 Sep 2023 18:50:02 +0000 (11:50 -0700)]
pg_dump: tests: Correct test condition for invalid databases
For some reason I used not_like = { pg_dumpall_dbprivs => 1, } in the test
condition of one of the tests added in in
c66a7d75e65. That doesn't make sense
for two reasons: 1) not_like isn't a valid test condition 2) the database
should not be dumped in any of the tests. Due to 1), the test achieved its
goal, but clearly the formulation is confusing. Instead use like => {}, with
a comment explaining why.
Reported-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/
3ddf79f2-8b7b-a093-11d2-
5c739bc64f86@eisentraut.org
Backpatch: 11-, like
c66a7d75e65
Tom Lane [Mon, 25 Sep 2023 18:41:57 +0000 (14:41 -0400)]
Collect dependency information for parsed CallStmts.
Parse analysis of a CallStmt will inject mutable information,
for instance the OID of the called procedure, so that subsequent
DDL may create a need to re-parse the CALL. We failed to detect
this for CALLs in plpgsql routines, because no dependency information
was collected when putting a CallStmt into the plan cache. That
could lead to misbehavior or strange errors such as "cache lookup
failed".
Before commit
ee895a655, the issue would only manifest for CALLs
appearing in atomic contexts, because we re-planned non-atomic
CALLs every time through anyway.
It is now apparent that extract_query_dependencies() probably
needs a special case for every utility statement type for which
stmt_requires_parse_analysis() returns true. I wanted to add
something like Assert(!stmt_requires_parse_analysis(...)) when
falling out of extract_query_dependencies_walker without doing
anything, but there are API issues as well as a more fundamental
point: stmt_requires_parse_analysis is supposed to be applied to
raw parser output, so it'd be cheating to assume it will give the
correct answer for post-parse-analysis trees. I contented myself
with adding a comment.
Per bug #18131 from Christian Stork. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/18131-
576854e79c5cd264@postgresql.org
Andres Freund [Mon, 25 Sep 2023 17:36:04 +0000 (10:36 -0700)]
docs: Clarify --with-segsize-blocks documentation
Without the added "relation" it's not immediately clear that the option
relates to the relation segment size and not e.g. the WAL segment size.
The option was added in
d3b111e32.
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/837536.
1695348498@sss.pgh.pa.us
Backpatch: 16-
Tom Lane [Mon, 25 Sep 2023 16:07:32 +0000 (12:07 -0400)]
Pack struct ParsedWord more tightly.
In a 64-bit build there's an awful lot of useless pad space in
ParsedWords. Since we may allocate large arrays of these,
it's worth some effort to reduce their size.
Here we reduce the alen field from uint32 to uint16, and then re-order
the fields to avoid unnecessary padding. alen is only used to
remember the allocated size of the apos[] array, which is not allowed
to exceed MAXNUMPOS (256) elements, so uint16 is plenty of space for
it. That gets us from 40 bytes to 24 on 64-bit builds, and from 20
bytes to 16 on 32-bit builds.
Per discussion of bug #18080. Unfortunately this is an ABI break
so we can't back-patch.
Discussion: https://postgr.es/m/
1146921.
1695411070@sss.pgh.pa.us
Tom Lane [Mon, 25 Sep 2023 15:50:28 +0000 (11:50 -0400)]
Limit to_tsvector_byid's initial array allocation to something sane.
The initial estimate of the number of distinct ParsedWords is just
that: an estimate. Don't let it exceed what palloc is willing to
allocate. If in fact we need more entries, we'll eventually fail
trying to enlarge the array. But if we don't, this allows success on
inputs that currently draw "invalid memory alloc request size".
Per bug #18080 from Uwe Binder. Back-patch to all supported branches.
Discussion: https://postgr.es/m/18080-
d5c5e58fef8c99b7@postgresql.org
Tom Lane [Mon, 25 Sep 2023 15:25:19 +0000 (11:25 -0400)]
Doc: improve cross-reference in Makefile comment.
Per gripe from Japin Li.
Discussion: https://postgr.es/m/MEYP282MB16692171F13B5DF40DB768EEB6FCA@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Daniel Gustafsson [Mon, 25 Sep 2023 14:03:32 +0000 (16:03 +0200)]
vacuumdb: Reword --help message for clarity
The --help output stated that schemas were specified using PATTERN
when they in fact aren't pattern matched but are required to be
exact matches. This changes to SCHEMA to make that clear.
Backpatch through v16 where this was introduced.
Author: Kuwamura Masaki <kuwamura@db.is.i.nagoya-u.ac.jp>
Discussion: https://postgr.es/m/CAMyC8qp9mXPQd5D6s6CJxvmignsbTqGZwDDB6VYJOn1A8WG38w@mail.gmail.com
Backpatch-through: 16
Daniel Gustafsson [Mon, 25 Sep 2023 14:03:17 +0000 (16:03 +0200)]
vacuumdb: Fix excluding multiple schemas with -N
When specifying multiple schemas to exclude with -N parameters, none
of the schemas are actually excluded (a single -N worked as expected).
This fixes the catalog query to handle multiple exclusions and adds a
test for this case.
Backpatch to v16 where this was introduced.
Author: Nathan Bossart <nathandbossart@gmail.com>
Author: Kuwamura Masaki <kuwamura@db.is.i.nagoya-u.ac.jp>
Reported-by: Kuwamura Masaki <kuwamura@db.is.i.nagoya-u.ac.jp>
Discussion: https://postgr.es/m/CAMyC8qp9mXPQd5D6s6CJxvmignsbTqGZwDDB6VYJOn1A8WG38w@mail.gmail.com
Backpatch-through: 16
Alvaro Herrera [Mon, 25 Sep 2023 12:27:33 +0000 (14:27 +0200)]
pg_upgrade: check for types removed in pg12
Commit
cda6a8d01d39 removed a few datatypes, but didn't update
pg_upgrade --check to throw error if these types are used. So the users
find that pg_upgrade --check tells them that everything is fine, only to
fail when the real upgrade is attempted.
Reviewed-by: Tristan Partin <tristan@neon.tech>
Reviewed-by: Suraj Kharage <suraj.kharage@enterprisedb.com>
Discussion: https://postgr.es/m/
202309201654.ng4ksea25mti@alvherre.pgsql
Daniel Gustafsson [Mon, 25 Sep 2023 11:29:34 +0000 (13:29 +0200)]
Fix typo in numutils.c comments
s/messges/messages/
Daniel Gustafsson [Mon, 25 Sep 2023 10:41:49 +0000 (12:41 +0200)]
Add GUC for temporarily disabling event triggers
In order to troubleshoot misbehaving or buggy event triggers, the
documented advice is to enter single-user mode. In an attempt to
reduce the number of situations where single-user mode is required
(or even recommended) for non-extraordinary maintenance, this GUC
allows to temporarily suspend event triggers.
This was originally extracted from a larger patchset which aimed
at supporting event triggers on login events.
Reviewed-by: Ted Yu <yuzhihong@gmail.com>
Reviewed-by: Mikhail Gribkov <youzhick@gmail.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/
9140106E-F9BF-4D85-8FC8-
F2D3C094A6D9@yesql.se
Discussion: https://postgr.es/m/
0d46d29f-4558-3af9-9c85-
7774e14a7709@postgrespro.ru
Michael Paquier [Mon, 25 Sep 2023 00:31:48 +0000 (09:31 +0900)]
unaccent: Fix allocation size for target characters on initial load
This led to an overestimation of the size allocated for both the quoted
and non-quoted cases, while using an inconsistent style. Thinkos in
59f47fb98dab.
Per report from Coverity, with extra input from Tom Lane.
Daniel Gustafsson [Sat, 23 Sep 2023 07:56:38 +0000 (09:56 +0200)]
Fix typo in test comment
s/currect/correct/, accidentally introduced in
608b167f9f9.
Thomas Munro [Sat, 23 Sep 2023 02:13:06 +0000 (14:13 +1200)]
Don't use Perl pack('Q') in 039_end_of_wal.pl.
'Q' for 64 bit integers turns out not to work on 32 bit Perl, as
revealed by the build farm. Use 'II' instead, and deal with endianness.
Back-patch to 12, like
bae868ca.
Discussion: https://postgr.es/m/ZQ4r1vHcryBsSi_V%40paquier.xyz
Thomas Munro [Fri, 22 Sep 2023 22:26:24 +0000 (10:26 +1200)]
Don't trust unvalidated xl_tot_len.
xl_tot_len comes first in a WAL record. Usually we don't trust it to be
the true length until we've validated the record header. If the record
header was split across two pages, previously we wouldn't do the
validation until after we'd already tried to allocate enough memory to
hold the record, which was bad because it might actually be garbage
bytes from a recycled WAL file, so we could try to allocate a lot of
memory. Release 15 made it worse.
Since
70b4f82a4b5, we'd at least generate an end-of-WAL condition if the
garbage 4 byte value happened to be > 1GB, but we'd still try to
allocate up to 1GB of memory bogusly otherwise. That was an
improvement, but unfortunately release 15 tries to allocate another
object before that, so you could get a FATAL error and recovery could
fail.
We can fix both variants of the problem more fundamentally using
pre-existing page-level validation, if we just re-order some logic.
The new order of operations in the split-header case defers all memory
allocation based on xl_tot_len until we've read the following page. At
that point we know that its first few bytes are not recycled data, by
checking its xlp_pageaddr, and that its xlp_rem_len agrees with
xl_tot_len on the preceding page. That is strong evidence that
xl_tot_len was truly the start of a record that was logged.
This problem was most likely to occur on a standby, because
walreceiver.c recycles WAL files without zeroing out trailing regions of
each page. We could fix that too, but it wouldn't protect us from rare
crash scenarios where the trailing zeroes don't make it to disk.
With reliable xl_tot_len validation in place, the ancient policy of
considering malloc failure to indicate corruption at end-of-WAL seems
quite surprising, but changing that is left for later work.
Also included is a new TAP test to exercise various cases of end-of-WAL
detection by writing contrived data into the WAL from Perl.
Back-patch to 12. We decided not to put this change into the final
release of 11.
Author: Thomas Munro <thomas.munro@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com> (the idea, not the code)
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sergei Kornilov <sk@zsrv.org>
Reviewed-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/17928-
aa92416a70ff44a2%40postgresql.org
Tom Lane [Fri, 22 Sep 2023 18:52:36 +0000 (14:52 -0400)]
Doc: copy-edit the introductory para for the pg_class catalog.
The previous wording had a faint archaic whiff to it, and more
importantly used "catalogs" as a verb, which while cutely
self-referential seems likely to provoke confusion in this
particular context. Also consistently use "kind" not "type" to
refer to the different kinds of relations distinguished by relkind.
Per gripe from Martin Nash. Back-patch to supported versions.
Discussion: https://postgr.es/m/
169518739902.
3727338.
4793815593763320945@wrigleys.postgresql.org
Daniel Gustafsson [Fri, 22 Sep 2023 11:35:37 +0000 (13:35 +0200)]
Avoid using internal test methods in SSL tests
The SSL tests for pg_ctl restart with an incorrect key passphrase used
the internal _update_pid method to set the pidfile after running pg_ctl
manually instead of using the supplied ->restart method. This refactors
the ->restart method to accept a fail_ok parameter like how ->start and
->stop does, and changes the SSL tests to use this instead. This removes
the need to call internal test module functions.
Reviewed-by: Melih Mutlu <m.melihmutlu@gmail.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/
F81643C4-D7B8-4C6B-AF18-
B73839966279@yesql.se
Daniel Gustafsson [Fri, 22 Sep 2023 09:18:25 +0000 (11:18 +0200)]
Avoid potential pfree on NULL on OpenSSL errors
Guard against the pointer being NULL before pfreeing upon an error
returned from OpenSSL. Also handle errors from X509_NAME_print_ex
which can return -1 on memory allocation errors.
Backpatch down to v15 where the code was added.
Author: Sergey Shinderuk <s.shinderuk@postgrespro.ru>
Discussion: https://postgr.es/m/
8db5374d-32e0-6abb-d402-
40762511eff2@postgrespro.ru
Backpatch-through: v15
Peter Eisentraut [Fri, 22 Sep 2023 05:40:56 +0000 (07:40 +0200)]
Simplify information schema check constraint deparsing
The computation of the column
information_schema.check_constraints.check_clause used
pg_get_constraintdef() plus some string manipulation to get the check
clause back out. This ended up with an extra pair of parentheses,
which is only an aesthetic problem, but also with suffixes like "NOT
VALID", which don't belong into that column. We can fix both of these
problems and simplify the code by just using pg_get_expr() instead.
Discussion: https://www.postgresql.org/message-id/
799b59ef-3330-f0d2-ee23-
8cdfa1740987@eisentraut.org
Tom Lane [Fri, 22 Sep 2023 03:11:30 +0000 (23:11 -0400)]
Fix COMMIT/ROLLBACK AND CHAIN in the presence of subtransactions.
In older branches, COMMIT/ROLLBACK AND CHAIN failed to propagate
the current transaction's properties to the new transaction if
there was any open subtransaction (unreleased savepoint).
Instead, some previous transaction's properties would be restored.
This is because the "if (s->chain)" check in CommitTransactionCommand
examined the wrong instance of the "chain" flag and falsely
concluded that it didn't need to save transaction properties.
Our regression tests would have noticed this, except they used
identical transaction properties for multiple tests in a row,
so that the faulty behavior was not distinguishable from correct
behavior.
Commit
12d768e70 fixed the problem in v15 and later, but only rather
accidentally, because I removed the "if (s->chain)" test to avoid a
compiler warning, while not realizing that the warning was flagging a
real bug.
In v14 and before, remove the if-test and save transaction properties
unconditionally; just as in the newer branches, that's not expensive
enough to justify thinking harder.
Add the comment and extra regression test to v15 and later to
forestall any future recurrence, but there's no live bug in those
branches.
Patch by me, per bug #18118 from Liu Xiang. Back-patch to v12 where
the AND CHAIN feature was added.
Discussion: https://postgr.es/m/18118-
4b72fcbb903aace6@postgresql.org
Daniel Gustafsson [Thu, 21 Sep 2023 11:53:07 +0000 (13:53 +0200)]
Allow dbname in pg_basebackup/pg_receivewal connstring
As physical replication work at the cluster level and not database
level, any dbname in the connection string is ignored. Proxies and
middleware used in connecting to the cluster might however need to
know the dbname in order to make the correct routing decision for
the connection.
With this the startup packet will include the dbname parameter.
Author: Jelte Fennema-Nio <me@jeltef.nl>
Reviewed-by: Tristen Raab <tristen.raab@highgo.ca>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Discussion: https://postgr.es/m/CAGECzQTw-dZkVT_RELRzfWRzY714-VaTjoBATYfZq93R8C-auA@mail.gmail.com
Etsuro Fujita [Thu, 21 Sep 2023 10:45:00 +0000 (19:45 +0900)]
Update comment about set_join_pathlist_hook().
The comment introduced by commit
e7cb7ee14 was a bit too terse, which
could lead to extensions doing different things within the hook function
than we intend to allow. Extend the comment to explain what they can do
within the hook function.
Back-patch to all supported branches.
In passing, I rephrased a nearby comment that I recently added to the
back branches.
Reviewed by David Rowley and Andrei Lepikhov.
Discussion: https://postgr.es/m/CAPmGK15SBPA1nr3Aqsdm%2BYyS-ay0Ayo2BRYQ8_A2To9eLqwopQ%40mail.gmail.com
David Rowley [Thu, 21 Sep 2023 05:47:20 +0000 (17:47 +1200)]
Fix vacuumdb to pass buffer-usage-limit with analyze-only mode
ae78cae3b added the --buffer-usage-limit to vacuumdb to allow it to
include the BUFFER_USAGE_LIMIT option in the VACUUM command.
Unfortunately, that commit forgot to adjust the code so the option was
added to the ANALYZE command when the -Z command line argument was
specified.
There were no issues with the -z command as that option just adds
ANALYZE to the VACUUM command.
In passing adjust the code to escape the --buffer-usage-limit option
before passing it to the server. It seems nothing beyond a confusing
error message could become this lack of escaping as VACUUM cannot be
specified in a multi-command string.
Reported-by: Ryoga Yoshida
Author: Ryoga Yoshida, David Rowley
Discussion: https://postgr.es/m/
08930c0b541700a5264e5fbf3a685f5a%40oss.nttdata.com
Backpatch-through: 16, where
ae78cae3b was introduced.
Michael Paquier [Wed, 20 Sep 2023 04:36:54 +0000 (13:36 +0900)]
doc: Fix description of BUFFER_USAGE_LIMIT for VACUUM and ANALYZE
BUFFER_USAGE_LIMIT requires a parameter, and 'B' is a supported unit.
Author: Ryoga Yoshida
Reviewed-by: Shinya Kato
Discussion: https://postgr.es/m/
9374034cb91b647b55a774a8980b0228@oss.nttdata.com
Backpatch-through: 16
Michael Paquier [Wed, 20 Sep 2023 03:29:36 +0000 (12:29 +0900)]
unaccent: Add support for quoted translated characters
As reported in bug #18057, the extension unaccent removes in its rule
file whitespace characters that are intentionally specified when
building unaccent.rules from UnicodeData.txt, causing an incorrect
translation for some characters like numeric symbols. This is caused by
the fact that all whitespaces before and after the origin and target
characters are all discarded (this limitation is documented).
This commit makes possible the use of quotes around target characters,
so as whitespaces can be considered part of target characters. Some
target characters use a double quote, these require an extra double
quote.
The documentation is updated to show how to use quoted areas,
generate_unaccent_rules.py is updated to generate unaccent.rules and a
couple of tests are added for numeric symbols. While working on this
patch, I have implemented a fake rule file to test the parsing logic
implemented, which is not included here as it would just consume extra
cycles in the tests, and it requires the manipulation of an installation
tree to be able to work correctly.
As this requires a change of format in unaccent.rules, this cannot be
backpatched, unfortunately. The idea to use double quotes as escaped
characters comes from Tom Lane.
Reported-by: Martin Schlossarek
Author: Michael Paquier
Discussion: https://postgr.es/m/18057-
62712cad01bd202c@postgresql.org
Nathan Bossart [Wed, 20 Sep 2023 02:18:34 +0000 (19:18 -0700)]
Remove open-coded binary heap in pg_dump_sort.c.
Thanks to commit
5af0263afd, binaryheap is available to frontend
code. This commit replaces the open-coded heap implementation in
pg_dump_sort.c with a binaryheap, saving a few lines of code.
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/
3612876.
1689443232%40sss.pgh.pa.us
Michael Paquier [Wed, 20 Sep 2023 01:02:12 +0000 (10:02 +0900)]
Fix typos in pgoutput.c
RelationSyncCache was mentioned in two comments under a different name.
Issue noticed while reviewing a different patch touching the same area.
Introduced by
665d1fad99e7.
Discussion: https://postgr.es/m/ZQk1Ca_eFDTmBiZy@paquier.xyz
Michael Paquier [Wed, 20 Sep 2023 00:26:15 +0000 (09:26 +0900)]
psql: Reset query buffer of \e, \ef and \ev on error
If any of these commands fail during editing or pre-processing, the
command stored in the query buffer would remain around without being
executed immediately as PSQL_CMD_ERROR is returned as status. The next
command provided by the user would run it, likely causing failures as
this could include silently some of the contents generated automatically
for views or functions.
The problems would be different depending on the psql meta-command used:
- For \ev and \ef, some errors can happen in a predictable way while
doing an object lookup or while creating an object command. A failure
while editing is equally problematic, but the class of failures
happening in the code path of do_edit() are unlikely. The query reset
is kept in exec_command_ef_ev() as a query may be unchanged.
- For \e, error can happen while editing.
In both cases, the query buffer is reset on error for an incorrect file
number provided, whose value check is done before filling up the query
buffer.
This is a slight change of behavior compared to the past for some of the
predictable error patterns for \ev and \ef, so for now I have made the
choice to not backpatch this commit (argument particularly available for
v11 that's going to be EOL'd soon). Perhaps this could be revisited
later depending on the feedback of this new behavior.
Author: Ryoga Yoshida, Michael Paquier
Reviewed-by: Aleksander Alekseev, Kyotaro Horiguchi
Discussion: https://postgr.es/m/
01419622d84ef093fd4fe585520bf03c@oss.nttdata.com
Nathan Bossart [Tue, 19 Sep 2023 21:31:29 +0000 (14:31 -0700)]
Convert pg_restore's ready_list to a priority queue.
Presently, parallel restores spend a lot of time sorting this list
so that we pick the largest items first. With many tables, this
sorting can become a significant bottleneck. There are a couple of
reports from the field about this, and it is easy to reproduce.
This commit improves the performance of parallel pg_restore with
many tables by converting its ready_list to a priority queue, i.e.,
a binary heap. We will first try to run the highest priority item,
but if it cannot be chosen due to the lock heuristic, we'll do a
sequential scan through the heap nodes until we find one that is
runnable. This means that we might end up picking an item with a
much lower priority. However, we expect that we will typically be
able to pick one of the first few items, which should usually have
a relatively high priority.
Suggested-by: Tom Lane
Tested-by: Pierre Ducroquet
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/
3612876.
1689443232%40sss.pgh.pa.us
Heikki Linnakangas [Tue, 19 Sep 2023 16:26:29 +0000 (19:26 +0300)]
Fix psql tab-completion for identifiers containing dollars.
Dollar ($) is a legit character for identifiers, except as the first
character, since commit
1bd22f55cf in version 7.4. Update the
tab-completion code accordingly.
Author: Mikhail Gribkov
Reviewed-by: Vik Fearing
Discussion: https://www.postgresql.org/message-id/CAMEv5_sTAvPvhye%2Bu4jkWDe5UGDiQ1ZkQomnKCboM08zDzOe%3Dg%40mail.gmail.com
Peter Eisentraut [Tue, 19 Sep 2023 09:29:45 +0000 (11:29 +0200)]
Replace more MemSet calls with struct initialization
This fixes up
10ea0f924a2 to use the style introduced by
9fd45870c1.
Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAMbWs490gJf5A=ydqyjh+Z8mVQa_foTGtcmBtHGLra0aOwLWHQ@mail.gmail.com
Heikki Linnakangas [Tue, 19 Sep 2023 08:53:51 +0000 (11:53 +0300)]
Fix GiST README's explanation of the NSN cross-check.
The text got the condition backwards, it's "NSN > LSN", not "NSN < LSN".
While we're at it, expand it a little for clarity.
Reviewed-by: Daniel Gustafsson
Discussion: https://www.postgresql.org/message-id/
4cb46e18-e688-524a-0f73-
b1f03ed5d6ee@iki.fi
Peter Eisentraut [Tue, 19 Sep 2023 07:46:01 +0000 (09:46 +0200)]
Standardize type of extend_by counter
The counter of extend_by loops is mixed int and uint32. Fix by
standardizing from int to uint32, to match the extend_by variable.
Fixup for
31966b151e.
Author: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Gurjeet Singh <gurjeet@singh.im>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEudQAqHG-JP-YnG54ftL_b7v6-57rMKwET_MSvEoen0UHuPig@mail.gmail.com
Michael Paquier [Tue, 19 Sep 2023 01:19:50 +0000 (10:19 +0900)]
Improve error message for snapshot import in snapmgr.c, take two
When a snapshot file fails to be read in ImportSnapshot(), it would
issue an ERROR as "invalid snapshot identifier" when opening a stream
for it in read-only mode. The error handling is improved to be more
talkative in failure cases:
- If a snapshot identifier uses incorrect characters, complain with the
same error as before this commit.
- If the snapshot file cannot be found in pg_snapshots/, complain with a
"snapshot \"foo\" does not exist" instead. This maps to the case where
AllocateFile() fails on ENOENT. Based on a suggestion from Andres
Freund.
- If AllocateFile() throws something else than ENOENT as errno, report
it with more details in %m instead, as these failures are never
expected.
b29504eeb489 was the first improvement take. The older error message
exists since
bb446b689b66 that introduced snapshot imports. Two test
cases are added to cover the cases of an identifier with an incorrect
format and of a missing snapshot.
Author: Bharath Rupireddy
Reviewed-by: Andres Freund, Daniel Gustafsson, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACWmr=3KdxDkm8h7Zn1XxBoF6hdzq8WQyMn2y1OL5RYFrg@mail.gmail.com
Michael Paquier [Mon, 18 Sep 2023 23:31:06 +0000 (08:31 +0900)]
Fix assertion failure with PL/Python exceptions
PLy_elog() was not able to handle correctly cases where a SPI called
failed, which would fill in a DETAIL string able to trigger an
assertion. We may want to improve this infrastructure so as it is able
to provide any extra detail information provided by an error stack, but
this is left as a future improvement as it could impact existing error
stacks and any applications that depend on them. For now, the assertion
is removed and a regression test is added to cover the case of a failure
with a detail string.
This problem exists since
2bd78eb8d51c, so backpatch all the way down
with tweaks to the regression tests output added where required.
Author: Alexander Lakhin
Discussion: https://postgr.es/m/18070-
ab9c171cbf4ebb0f@postgresql.org
Backpatch-through: 11
Nathan Bossart [Mon, 18 Sep 2023 21:06:08 +0000 (14:06 -0700)]
Add function for removing arbitrary nodes in binaryheap.
This commit introduces binaryheap_remove_node(), which can be used
to remove any node from a binary heap. The implementation is
straightforward. The target node is replaced with the last node in
the heap, and then we sift as needed to preserve the heap property.
This new function is intended for use in a follow-up commit that
will improve the performance of pg_restore.
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/
3612876.
1689443232%40sss.pgh.pa.us
Nathan Bossart [Mon, 18 Sep 2023 19:46:57 +0000 (12:46 -0700)]
Fix MSVC build for changes to binaryheap.
After
5af0263afd, binaryheap.c needs to be listed in Mkvcbuild.pm.
Per buildfarm.
Nathan Bossart [Mon, 18 Sep 2023 19:18:33 +0000 (12:18 -0700)]
Make binaryheap available to frontend code.
There are a couple of places in frontend code that could make use
of this simple binary heap implementation. This commit makes
binaryheap usable in frontend code, much like commit
26aaf97b68 did
for StringInfo. Like StringInfo, the header file is left in lib/
to reduce the likelihood of unnecessary breakage.
The frontend version of binaryheap exposes a void *-based API since
frontend code does not have access to the Datum definitions. This
seemed like a better approach than switching all existing uses to
void * or making the Datum definitions available to frontend code.
Reviewed-by: Tom Lane, Alvaro Herrera
Discussion: https://postgr.es/m/
3612876.
1689443232%40sss.pgh.pa.us
Tom Lane [Mon, 18 Sep 2023 18:27:47 +0000 (14:27 -0400)]
Don't crash if cursor_to_xmlschema is used on a non-data-returning Portal.
cursor_to_xmlschema() assumed that any Portal must have a tupDesc,
which is not so. Add a defensive check.
It's plausible that this mistake occurred because of the rather
poorly chosen name of the lookup function SPI_cursor_find(),
which in such cases is returning something that isn't very much
like a cursor. Add some documentation to try to forestall future
errors of the same ilk.
Report and patch by Boyu Yang (docs changes by me). Back-patch
to all supported branches.
Discussion: https://postgr.es/m/
dd343010-c637-434c-a8cb-
418f53bda3b8.yangboyu.yby@alibaba-inc.com
Alvaro Herrera [Mon, 18 Sep 2023 14:19:25 +0000 (16:19 +0200)]
Fix psql's \? output for \watch
It was reported as misaligned by Kyotaro, but it also needed to be
turned into a single translatable phrase (like the one for \g is), as
reported by Yugo.
This is a new issue (commit
f347ec76e2a2), so no backpatch is needed.
Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Author: Yugo NAGATA <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/
20230907.142956.
2038600444404289870.horikyota.ntt@gmail.com
Daniel Gustafsson [Mon, 18 Sep 2023 12:59:16 +0000 (14:59 +0200)]
doc: Add example for how to set file_fdw column option
The documentation is pretty light on how to set column options
on foreign tables, and the file_fdw docs refer to COPY when
documenting force_null even though it's not used in the same
way. Add a small example to describe how to use it.
Reported-by: Boshomi Phenix <boshomi@gmail.com>
Discussion: https://postgr.es/m/CAJVkCUparn4_Oarernm=U6LWVsTkecKcALHtwGr5M3qJRj_czw@mail.gmail.com
Peter Eisentraut [Mon, 18 Sep 2023 06:10:51 +0000 (08:10 +0200)]
Fix information schema for catalogued not-null constraints
The column check_constraints.check_clause should be like
col IS NOT NULL
without a surrounding CHECK (...).
Discussion: https://www.postgresql.org/message-id/
09489196-0bc1-e796-c43e-
63425f7c5910@eisentraut.org
Peter Eisentraut [Mon, 18 Sep 2023 05:26:34 +0000 (07:26 +0200)]
Update Unicode data to Unicode 15.1.0
Peter Eisentraut [Mon, 18 Sep 2023 05:25:46 +0000 (07:25 +0200)]
Make Unicode script fit for future versions
Between Unicode 15.0.0 and 15.1.0, the whitespace in
EastAsianWidth.txt has changed a bit, such as from
0020;Na # Zs SPACE
to
0020 ; Na # Zs SPACE
with space around the semicolon. Adjust the script to be able to
parse that.
Tom Lane [Fri, 15 Sep 2023 21:01:26 +0000 (17:01 -0400)]
Track nesting depth correctly when drilling down into RECORD Vars.
expandRecordVariable() failed to adjust the parse nesting structure
correctly when recursing to inspect an outer-level Var. This could
result in assertion failures or core dumps in corner cases.
Likewise, get_name_for_var_field() failed to adjust the deparse
namespace stack correctly when recursing to inspect an outer-level
Var. In this case the likely result was a "bogus varno" error
while deparsing a view.
Per bug #18077 from Jingzhou Fu. Back-patch to all supported
branches.
Richard Guo, with some adjustments by me
Discussion: https://postgr.es/m/18077-
b9db97c6e0ab45d8@postgresql.org
Daniel Gustafsson [Fri, 15 Sep 2023 17:05:57 +0000 (19:05 +0200)]
Rename variable for code clarity
When tracking IO timing for WAL, the duration is what we calculate
based on the start and end timestamps, it's not what the variable
contains. Rename the timestamp variable to end to better communicate
what it contains. Original patch by Krishnakumar with additional
hacking to fix another occurrence by me.
Author: Krishnakumar R <kksrcv001@gmail.com>
Discussion: https://postgr.es/m/CAPMWgZ9f9o8awrQpjo8oxnNQ=bMDVPx00NE0QcDzvHD_ZrdLPw@mail.gmail.com
Heikki Linnakangas [Fri, 15 Sep 2023 14:29:37 +0000 (17:29 +0300)]
Remove unnecessary smgrimmedsync() when creating unlogged table.
This became safe after commit
4b4798e138. The smgrcreate() call will
now register the segment for syncing at the next checkpoint, so we
don't need to sync it here. If a checkpoint happens before the
creation is WAL-logged, the records will be replayed when starting
recovery from the checkpoint. If a checkpoint happens after the WAL
logging, the checkpoint will fsync() it.
In the passing, clarify a comment in smgrDoPendingSyncs().
Discussion: https://www.postgresql.org/message-id/
6e5bbc08-cdfc-b2b3-9e23-
1a914b9850a9%40iki.fi
Reviewed-by: Robert Haas
Daniel Gustafsson [Thu, 14 Sep 2023 09:17:33 +0000 (11:17 +0200)]
Quote filenames in error messages
The majority of all filenames are quoted in user facing error and
log messages, but a few were still printed without quotes. While
these filenames do not risk causing any ambiguity as their format
is strict, quote them anyways to be consistent across all logs.
Also concatenate a message to keep it one line to make it easier
to grep for in the code.
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/
080EEABE-6645-4A46-AB20-
6285ADAC44FE@yesql.se
Peter Eisentraut [Thu, 14 Sep 2023 07:42:43 +0000 (09:42 +0200)]
Fix indentation in SQL file
Michael Paquier [Thu, 14 Sep 2023 07:00:01 +0000 (16:00 +0900)]
Revert "Improve error message on snapshot import in snapmgr.c"
This reverts commit
a0d87bcd9b57, following a remark from Andres Frend
that the new error can be triggered with an incorrect SET TRANSACTION
SNAPSHOT command without being really helpful for the user as it uses
the internal file name.
Discussion: https://postgr.es/m/
20230914020724.hlks7vunitvtbbz4@awork3.anarazel.de
Backpatch-through: 11
Amit Kapila [Thu, 14 Sep 2023 03:26:13 +0000 (08:56 +0530)]
Flush logical slots to disk during a shutdown checkpoint if required.
It's entirely possible for a logical slot to have a confirmed_flush LSN
higher than the last value saved on disk while not being marked as dirty.
Currently, it is not a major problem but a later patch adding support for
the upgrade of slots relies on that value being properly flushed to disk.
It can also help avoid processing the same transactions again in some
boundary cases after the clean shutdown and restart. Say, we process
some transactions for which we didn't send anything downstream (the
changes got filtered) but the confirm_flush LSN is updated due to
keepalives. As we don't flush the latest value of confirm_flush LSN, it
may lead to processing the same changes again without this patch.
The approach taken by this patch has been suggested by Ashutosh Bapat.
Author: Vignesh C, Julien Rouhaud, Kuroda Hayato
Reviewed-by: Amit Kapila, Dilip Kumar, Michael Paquier, Ashutosh Bapat, Peter Smith, Hou Zhijie
Discussion: http://postgr.es/m/CAA4eK1JzJagMmb_E8D4au=GYQkxox0AfNBm1FbP7sy7t4YWXPQ@mail.gmail.com
Discussion: http://postgr.es/m/TYAPR01MB58664C81887B3AF2EB6B16E3F5939@TYAPR01MB5866.jpnprd01.prod.outlook.com
Amit Kapila [Thu, 14 Sep 2023 03:09:03 +0000 (08:39 +0530)]
Remove redundant result assignment in 004_sync.pl.
Author: Peter Smith
Discussion: http://postgr.es/m/CAHut+PuTNdxnpn24s6jfPDe+fKJoe3M-CoNv-DFsZmJN-ed0Xw@mail.gmail.com
Andres Freund [Thu, 14 Sep 2023 02:14:09 +0000 (19:14 -0700)]
Fix tracking of temp table relation extensions as writes
Karina figured out that I (Andres) confused BufferUsage.temp_blks_written with
BufferUsage.local_blks_written in
fcdda1e4b5.
Tests in core PG can't easily test this, as BufferUsage is just used for
EXPLAIN (ANALYZE, BUFFERS) and pg_stat_statements. Thus this commit adds tests
for this to pg_stat_statements.
Reported-by: Karina Litskevich <litskevichkarina@gmail.com>
Author: Karina Litskevich <litskevichkarina@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CACiT8ibxXA6+0amGikbeFhm8B84XdQVo6D0Qfd1pQ1s8zpsnxQ@mail.gmail.com
Backpatch: 16-, where
fcdda1e4b5 was merged
Michael Paquier [Thu, 14 Sep 2023 01:30:08 +0000 (10:30 +0900)]
Improve error message on snapshot import in snapmgr.c
When a snapshot file fails to be read in ImportSnapshot(), it would
issue an ERROR as "invalid snapshot identifier" when opening a stream
for it in read-only mode. This error message is reworded to be the same
as all the other messages used in this case on failure, which is useful
when debugging this area.
Thinko introduced by
bb446b689b66 where snapshot imports have been
added. A backpatch down to 11 is done as this can improve any work
related to snapshot imports in older branches.
Author: Bharath Rupireddy
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CALj2ACWmr=3KdxDkm8h7Zn1XxBoF6hdzq8WQyMn2y1OL5RYFrg@mail.gmail.com
Backpatch-through: 11
Michael Paquier [Wed, 13 Sep 2023 23:35:02 +0000 (08:35 +0900)]
Refactor error messages for unsupported providers in pg_locale.c
These code paths should not be reached normally, but if they are an
error with "(null)" as information for the collation provider would show
up if no locale is set, while we can assume that we are referring to
libc.
This refactors the code so as the provider is always reported even if no
locale is set. The name of the function where the error happens is
added, while on it, as it can be helpful for debugging.
Issue introduced by
d87d548cd030, so backpatch down to 16.
Author: Michael Paquier, Ranier Vilela
Reviewed-by: Jeff Davis, Kyotaro Horiguchi
Discussion: https://postgr.es/m/
7073610042fcf97e1bea2ce08b7e0214b5e11094.camel@j-davis.com
Backpatch-through: 16
David Rowley [Wed, 13 Sep 2023 23:27:29 +0000 (11:27 +1200)]
Fix incorrect logic in plan dependency recording
Both
50e17ad28 and
29f45e299 mistakenly tried to record a plan dependency
on a function but mistakenly inverted the OidIsValid test. This meant
that we'd record a dependency only when the function's Oid was
InvalidOid. Clearly this was meant to *not* record the dependency in
that case.
50e17ad28 made this mistake first, then in v15
29f45e299 copied the same
mistake.
Reported-by: Tom Lane
Backpatch-through: 14, where
50e17ad28 first made this mistake
Discussion: https://postgr.es/m/
2277537.
1694301772@sss.pgh.pa.us
Amit Kapila [Wed, 13 Sep 2023 04:04:30 +0000 (09:34 +0530)]
Fix the ALTER SUBSCRIPTION to reflect the change in run_as_owner option.
Reported-by: Jeff Davis
Author: Hou Zhijie
Reviewed-by: Amit Kapila
Backpatch-through: 16
Discussion: http://postgr.es/m/
17b62714fd115bd1899afd922954540a5c6a0467.camel@j-davis.com
Thomas Munro [Wed, 13 Sep 2023 02:32:24 +0000 (14:32 +1200)]
Fix exception safety bug in typcache.c.
If an out-of-memory error was thrown at an unfortunate time,
ensure_record_cache_typmod_slot_exists() could leak memory and leave
behind a global state that produced an infinite loop on the next call.
Fix by merging RecordCacheArray and RecordIdentifierArray into a single
array. With only one allocation or re-allocation, there is no
intermediate state.
Back-patch to all supported releases.
Reported-by: "James Pang (chaolpan)" <chaolpan@cisco.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/PH0PR11MB519113E738814BDDA702EDADD6EFA%40PH0PR11MB5191.namprd11.prod.outlook.com
Michael Paquier [Wed, 13 Sep 2023 01:10:04 +0000 (10:10 +0900)]
Switch psql's TAP test for query cancellation to use IPC::Run::signal()
Previously, the test relied on a trick with a shell to retrieve the PID
of the psql session to be stopped with SIGINT, that was skipped on
Windows. This commit changes the test to use IPC::Run::signal()
instead, which still does not work on Windows, but for a different
reason: SIGINT would stop the test before finishing.
This should allow the test to run on non-Windows platforms where PPID is
not supported (like NetBSD), spreading it a bit more across the
buildfarm. And the logic of the test is simpler.
It is the first time in the tree that IPC::Run::signal() is used, so, as
a matter of safety (or just call that as me having cold feet), no
backpatch is done, at least for now.
Author: Yugo NAGATA
Reviewed-by: Fabien Coelho
Discussion: https://postgr.es/m/
20230810125935.
22c2922ea5250ba79358965b@sraoss.co.jp
Michael Paquier [Wed, 13 Sep 2023 00:53:48 +0000 (09:53 +0900)]
Skip psql's TAP test for query cancellation entirely on Windows
This changes 020_cancel.pl so as the test is entirely skipped on
Windows. This test was already doing nothing under WIN32, except
initializing and starting a node without using it so this shaves a few
test cycles.
Author: Yugo NAGATA
Reviewed-by: Fabien Coelho
Discussion: https://postgr.es/m/
20230810125935.
22c2922ea5250ba79358965b@sraoss.co.jp
Backpatch-through: 15
Michael Paquier [Sat, 9 Sep 2023 12:12:41 +0000 (21:12 +0900)]
Remove redundant assignments in copyfrom.c
The tuple descriptor and the number of attributes are assigned twice to
the same values in BeginCopyFrom(), for what looks like a small thinko
coming from the refactoring done in
c532d15dddff1.
Author: Jingtang Zhang
Discussion: https://postgr.es/m/CAPsk3_CrYeXUVHEiaWAYxY9BKiGvGT3AoXo_+Jm0xP_s_VmXCA@mail.gmail.com
Bruce Momjian [Fri, 8 Sep 2023 21:25:15 +0000 (17:25 -0400)]
doc: remove mention of backslash doubling in strings
Reported-by: Laurenz Albe
Discussion: https://postgr.es/m/
0b03f91a875fb44182f5bed9e1d404ed6d138066.camel@cybertec.at
Author: Laurenz Albe
Backpatch-through: 11
Masahiko Sawada [Fri, 8 Sep 2023 13:50:59 +0000 (22:50 +0900)]
Stabilize subscription stats test.
The new test added by commit
68a59f9e9 disables the subscription and
manually drops the associated replication slot. However, since
disabling the subsubscription doesn't wait for a walsender to release
the replication slot and exit, pg_drop_replication_slot() could
fail. Avoid failure by adding a wait for the replication slot to
become inactive.
Reported-by: Hou Zhijie, as per buildfarm
Reviewed-by: Hou Zhijie
Discussion: https://postgr.es/m/OS0PR01MB571682316378379AA34854F694E9A%40OS0PR01MB5716.jpnprd01.prod.outlook.com
Backpatch-through: 15
Daniel Gustafsson [Fri, 8 Sep 2023 13:05:12 +0000 (15:05 +0200)]
Add JIT deform_counter
generation_counter includes time spent on both JIT:ing expressions
and tuple deforming which are configured independently via options
jit_expressions and jit_tuple_deforming. As they are combined in
the same counter it's not apparent what fraction of time the tuple
deforming takes.
This adds deform_counter dedicated to tuple deforming, which allows
seeing more directly the influence jit_tuple_deforming is having on
the query. The counter is exposed in EXPLAIN and pg_stat_statements
bumpin pg_stat_statements to 1.11.
Author: Dmitry Dolgov <9erthalion6@gmail.com>
Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/
20220612091253.eegstkufdsu4kfls@erthalion.local
Daniel Gustafsson [Fri, 8 Sep 2023 09:34:43 +0000 (11:34 +0200)]
doc: Extend documentation of PG_TEST_EXTRA
Extend the PG_TEST_EXTRA documentation to mention resource intensive
tests as well. The previous wording only mentioned special software
and security in the main paragraph, with resource usage listed on one
of the tests in the list.
Backpatch to v15 where
f47ed79cc8 added wal_consistenct_checking as
a PG_TEST_EXTRA target.
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/CAN55FZ0OthTuBdiNkaX2BvxuHdK4Y1MVEb8_uEuD1yHMPmT9Og@mail.gmail.com
Backpatch-through: 15
Thomas Munro [Fri, 8 Sep 2023 05:38:48 +0000 (17:38 +1200)]
Teach WaitEventSetWait() to report multiple events on Windows.
The WAIT_USE_WIN32 implementation of WaitEventSetWait() previously
reported at most one event per call, because that's what the underlying
WaitForMultipleObjects() call does.
We can make the behavior match the three Unix implementations by looping
until our output buffer is full, or there are no more events available
now. This makes no difference to most callers including the regular
FEBE socket code, since they ask for at most one event anyway. A
difference in socket accept priority might be perceived by end users
after commit
7389aad6 started using WaitEventSet in the postmaster.
With this commit, the accept order now matches Unix systems, servicing
listening sockets in round-robin order.
We decided it wasn't really a bug or worth back-patching, but it seems
good to align the behavior across platforms.
Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version)
Tested-by: "Wei Wang (Fujitsu)" <wangw.fnst@fujitsu.com>
Discussion: https://postgr.es/m/CA%2BhUKG%2BA2dk29hr5zRP3HVJQ-_PncNJM6HVQ7aaYLXLRBZU-xw%40mail.gmail.com
Thomas Munro [Fri, 8 Sep 2023 05:12:12 +0000 (17:12 +1200)]
Remove some more "snapshot too old" vestiges.
Commit
f691f5b8 removed the logic, but left behind some now-useless
Snapshot arguments to various AM-internal functions, and missed a couple
of comments.
Reported-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-Wznj9qSNXZ1P1uWTUD_FeaTezbUazb416EPwi4Qr_jR_6A%40mail.gmail.com
Michael Paquier [Fri, 8 Sep 2023 01:00:29 +0000 (10:00 +0900)]
Improve BackendXidGetPid() to only access allProcs on matching XID
Compilers are able to optimize that, but it makes the code slightly more
readable this way.
Author: Zhao Junwang
Reviewed-by: Ashutosh Bapat
Discussion: https://postgr.es/m/CAEG8a3+i9gtqF65B+g_puVaCQuf0rZC-EMqMyEjGFJYOqUUWfA@mail.gmail.com
Bruce Momjian [Thu, 7 Sep 2023 19:47:53 +0000 (15:47 -0400)]
doc: change "cross product" to "Cartesian product"
Reported-by: Erik Wienhold
Discussion: https://postgr.es/m/
2053109544.160895.
1684955437950@office.mailbox.org
Author: Erik Wienhold
Backpatch-through: master
Robert Haas [Thu, 7 Sep 2023 17:51:35 +0000 (13:51 -0400)]
Reorder tests in get_cheapest_path_for_pathkeys().
Checking parallel safety should be even cheaper than cost comparison, so
do that first.
Also make some minor, related comment improvements.
Richard Guo, reviewed by Aleksander Alekseev, Andy Fan, and me.
Discussion: http://postgr.es/m/CAMbWs4-KE2wf4QPj_Sr5mX4QFtBNNKGmxK=+e=KZEGUjdG33=g@mail.gmail.com
Alvaro Herrera [Thu, 7 Sep 2023 10:15:18 +0000 (12:15 +0200)]
Move privilege check to the right place
Now that ATExecDropConstraint doesn't recurse anymore, so it's wrong to
test privileges "during recursion" there. Move the check to
dropconstraint_internal, which is the place where recursion occurs.
In passing, remove now-useless 'recursing' argument to
ATExecDropConstraint.
Discussion: https://postgr.es/m/
202309051744.y4mndw5gwzhh@alvherre.pgsql
Alvaro Herrera [Thu, 7 Sep 2023 09:33:01 +0000 (11:33 +0200)]
Update information_schema definition for not-null constraints
Now that we have catalogued not-null constraints, our information_schema
definition can be updated to grab those rather than fabricate synthetic
definitions.
Note that we still don't have catalog rows for not-null constraints on
domains, but we've never had not-null constraints listed in
information_schema, so that's a problem to be solved separately.
Co-authored-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/
81b461c4-edab-5d8c-2f88-
203108425340@enterprisedb.com
Discussion: https://postgr.es/m/
202309041710.psytrxlsiqex@alvherre.pgsql
Michael Paquier [Thu, 7 Sep 2023 05:12:18 +0000 (14:12 +0900)]
pg_basebackup: Generate valid temporary slot names under PQbackendPID()
pgbouncer can cause PQbackendPID() to return negative values due to it
filling be_pid with random bytes (even these days pid_max can only be
set up to 2^22 on 64b machines on Linux, for example, so this cannot
happen with normal PID numbers). When this happens, pg_basebackup may
generate a temporary slot name that may not be accepted by the parser,
leading to spurious failures, like:
pg_basebackup: error: could not send replication command
ERROR: replication slot name "pg_basebackup_-
1201966863" contains
invalid character
This commit fixes that problem by formatting the result from
PQbackendPID() as an unsigned integer when creating the temporary
replication slot name, so as the invalid character is gone and the
command can be parsed.
Author: Jelte Fennema
Reviewed-by: Daniel Gustafsson, Nishant Sharma
Discussion: https://postgr.es/m/CAGECzQQOGvYfp8ziF4fWQ_o8s2K7ppaoWBQnTmdakn3s-4Z=5g@mail.gmail.com
Backpatch-through: 11
Thomas Munro [Thu, 7 Sep 2023 02:38:15 +0000 (14:38 +1200)]
Fix instability in 031_recovery_conflict.pl.
Where the test wants a VACUUM command to generate WAL that would
conflict with a session on the standby, it could transiently fail to do
so if it couldn't acquire a cleanup lock conditionally at that moment on
the primary. VACUUM FREEZE will wait, so use that instead.
No back-patch for now, but that will be needed if/when the test is
re-enabled in back-branches.
Suggested-by: Andres Freund <andres@anarazel.de>
Reported-by: Christoph Berg <myon@debian.org>
Discussion: https://postgr.es/m/
20230812210006.ei7tutzwcr5svyt6%40awork3.anarazel.de
Thomas Munro [Thu, 7 Sep 2023 00:38:23 +0000 (12:38 +1200)]
Fix recovery conflict SIGUSR1 handling.
We shouldn't be doing non-trivial work in signal handlers in general,
and in this case the handler could reach unsafe code and corrupt state.
It also clobbered its own "reason" code.
Move all recovery conflict decision logic into the next
CHECK_FOR_INTERRUPTS(), and have the signal handler just set flags and
the latch, following the standard pattern. Since there are several
different "reasons", use a separate flag for each.
With this refactoring, the recovery conflict system no longer
piggy-backs on top of the regular query cancelation mechanism, but
instead raises an error directly if it decides that is necessary. It
still needs to respect QueryCancelHoldoffCount, because otherwise the
FEBE protocol might get out of sync (see commit
2b3a8b20c2d).
This fixes one class of intermittent failure in the new
031_recovery_conflict.pl test added by commit
9f8a050f, though the buggy
coding is much older. Failures outside contrived testing seem to be
very rare (or perhaps incorrectly attributed) in the field, based on
lack of reports.
No back-patch for now due to complexity and release schedule. We have
the option to back-patch into 16 later, as 16 has prerequisite commit
bea3d7e.
Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version)
Reviewed-by: Michael Paquier <michael@paquier.xyz> (earlier version)
Reviewed-by: Robert Haas <robertmhaas@gmail.com> (earlier version)
Tested-by: Christoph Berg <myon@debian.org>
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com
Discussion: https://postgr.es/m/CALj2ACVr8au2J_9D88UfRCi0JdWhyQDDxAcSVav0B0irx9nXEg%40mail.gmail.com
Nathan Bossart [Wed, 6 Sep 2023 23:27:16 +0000 (16:27 -0700)]
Allow using syncfs() in frontend utilities.
This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file. In
many cases, using syncfs() is much faster.
As with recovery_init_sync_method, this new option comes with some
caveats. The descriptions of these caveats have been moved to a
new appendix section in the documentation.
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/
20210930004340.GM831%40telsasoft.com
Nathan Bossart [Wed, 6 Sep 2023 23:27:00 +0000 (16:27 -0700)]
Add support for syncfs() in frontend support functions.
This commit adds support for using syncfs() in fsync_pgdata() and
fsync_dir_recurse() (which have been renamed to sync_pgdata() and
sync_dir_recurse()). Like recovery_init_sync_method,
sync_pgdata() calls syncfs() for the data directory, each
tablespace, and pg_wal (if it is a symlink). For now, all of the
frontend utilities that use these support functions are hard-coded
to use fsync(), but a follow-up commit will allow specifying
syncfs().
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/
20210930004340.GM831%40telsasoft.com
Nathan Bossart [Wed, 6 Sep 2023 23:26:39 +0000 (16:26 -0700)]
Make enum for sync methods available to frontend code.
This commit renames RecoveryInitSyncMethod to DataDirSyncMethod and
moves it to common/file_utils.h. This is preparatory work for a
follow-up commit that will allow specifying the synchronization
method in frontend utilities such as pg_upgrade and pg_basebackup.
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/ZN2ZB4afQ2JbR9TA%40paquier.xyz
Bruce Momjian [Wed, 6 Sep 2023 20:52:24 +0000 (16:52 -0400)]
doc: mention that to_char() values are rounded
Reported-by: barsikdacat@gmail.com
Diagnosed-by: Laurenz Albe
Discussion: https://postgr.es/m/
168991536429.626.
9957835774751337210@wrigleys.postgresql.org
Author: Laurenz Albe
Backpatch-through: 11
Daniel Gustafsson [Wed, 6 Sep 2023 08:18:30 +0000 (10:18 +0200)]
Update comments to match location of definition
Commit
cc50080a82 rearranged testsuites to reduce dependencies, but
missed to update a comment when moving an operator class definition.
Also fix a typo in that same comment while here.
Author: Suraj Kharage <suraj.kharage@enterprisedb.com>
Discussion: https://postgr.es/m/CAF1DzPWXd2yq9_=P905cEypMVKw3ho+Fpj4HwJ4ta8T-eh+Yig@mail.gmail.com
Michael Paquier [Wed, 6 Sep 2023 01:27:02 +0000 (10:27 +0900)]
Remove column for wait event names in wait_event_names.txt
This file is now made of two columns, removing the column listing the
user-visible strings used in the system views and the documentation:
- Enum definitions for each class without the prefix "WAIT_EVENT_", so
as this information can be grepped in the code and wait_event_names.txt
at the same time.
- Description in the documentation.
The wait event names are now generated from the enum objects in
CamelCase, with the underscores removed. The data generated for wait
events is consistent with what was produced by
414f6c0fb79a.
This has the advantage to remove WAIT_EVENT_DOCONLY, which was a
placeholder for the wait event types Lock and LWLock as these two only
require the generation of the documentation.
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/ZOxVHQwEC/9X/p/z@paquier.xyz
Michael Paquier [Wed, 6 Sep 2023 01:04:43 +0000 (10:04 +0900)]
Use more consistent names for wait event objects and types
The event names use the same case-insensitive characters, hence applying
lower() or upper() to the monitoring queries allows the detection of the
same events as before this change. It is possible to cross-check the
data with the system view pg_wait_events, for instance, with a query
like that showing no differences:
SELECT lower(type), lower(name), description
FROM pg_wait_events ORDER BY 1, 2;
This will help in the introduction of more simplifications in the format
of wait_event_names. Some of the enum values in the code had to be
renamed a bit to follow the same convention naming across the board.
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/ZOxVHQwEC/9X/p/z@paquier.xyz
Nathan Bossart [Wed, 6 Sep 2023 00:02:06 +0000 (17:02 -0700)]
Move PG_TEMP_FILE* macros to file_utils.h.
Presently, frontend code that needs to use these macros must either
include storage/fd.h, which declares several frontend-unsafe
functions, or duplicate the macros. This commit moves these macros
to common/file_utils.h, which is safe for both frontend and backend
code. Consequently, we can also remove the duplicated macros in
pg_checksums and stop including storage/fd.h in pg_rewind.
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/ZOP5qoUualu5xl2Z%40paquier.xyz
Nathan Bossart [Tue, 5 Sep 2023 20:59:06 +0000 (13:59 -0700)]
Replace known_assigned_xids_lck with memory barriers.
This lock was introduced before memory barrier support was added,
and it is only used to guarantee proper memory ordering when
KnownAssignedXidsAdd() appends to the array without a lock. Now
that such memory barrier support exists, we can remove the lock and
use barriers instead.
Suggested-by: Tom Lane
Author: Michail Nikolaev
Reviewed-by: Robert Haas
Discussion: https://postgr.es/m/CANtu0oh0si%3DjG5z_fLeFtmYcETssQ08kLEa8b6TQqDm_cinroA%40mail.gmail.com
Bruce Momjian [Tue, 5 Sep 2023 17:05:28 +0000 (13:05 -0400)]
doc: mention libpq regression tests
Reported-by: Ryo Matsumura
Discussion: https://postgr.es/m/TYCPR01MB11316B3FB56EE54D70BF0CEF6E8E4A@TYCPR01MB11316.jpnprd01.prod.outlook.com
Backpatch-through: 11
Peter Eisentraut [Tue, 5 Sep 2023 09:36:55 +0000 (11:36 +0200)]
Unify gratuitously different error messages
Fixup for commit
37188cea0c.
Thomas Munro [Tue, 5 Sep 2023 06:26:12 +0000 (18:26 +1200)]
Remove the "snapshot too old" feature.
Remove the old_snapshot_threshold setting and mechanism for producing
the error "snapshot too old", originally added by commit
848ef42b.
Unfortunately it had a number of known problems in terms of correctness
and performance, mostly reported by Andres in the course of his work on
snapshot scalability. We agreed to remove it, after a long period
without an active plan to fix it.
This is certainly a desirable feature, and someone might propose a new
or improved implementation in the future.
Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CACG%3DezYV%2BEvO135fLRdVn-ZusfVsTY6cH1OZqWtezuEYH6ciQA%40mail.gmail.com
Discussion: https://postgr.es/m/
20200401064008.qob7bfnnbu4w5cw4%40alap3.anarazel.de
Discussion: https://postgr.es/m/CA%2BTgmoY%3Daqf0zjTD%2B3dUWYkgMiNDegDLFjo%2B6ze%3DWtpik%2B3XqA%40mail.gmail.com
Michael Paquier [Tue, 5 Sep 2023 04:57:44 +0000 (13:57 +0900)]
Improve description of keys in tsvector
If all the bits of a key in a tsvector are true (marked with ALLISTRUE),
gtsvectorout() would show the following description:
"0 true bits, 0 false bits"
This is confusing, as all the bits are true, but this would be
equivalent to the information if siglen is 0.
This commit improves the output so as "all true bits" show instead in
this case. Alexander has proposed a regression test for pageinspect,
not included here as it is rather expensive compared to its coverage
value.
Author: Alexander Lakhin
Discussion: https://postgr.es/m/17950-
6c80a8d2b94ec695@postgresql.org
Michael Paquier [Mon, 4 Sep 2023 05:55:37 +0000 (14:55 +0900)]
Fix out-of-bound read in gtsvector_picksplit()
This could lead to an imprecise choice when splitting an index page of a
GiST index on a tsvector, deciding which entries should remain on the
old page and which entries should move to a new page.
This is wrong since tsearch2 has been moved into core with commit
140d4ebcb46e, so backpatch all the way down. This error has been
spotted by valgrind.
Author: Alexander Lakhin
Discussion: https://postgr.es/m/17950-
6c80a8d2b94ec695@postgresql.org
Backpatch-through: 11
Amit Kapila [Mon, 4 Sep 2023 03:36:15 +0000 (09:06 +0530)]
Fix typo in decode.c.
Author: Hou Zhijie
Discussion: http://postgr.es/m/OS0PR01MB57162DFFFCFCDA2E4B95899394E4A@OS0PR01MB5716.jpnprd01.prod.outlook.com
Michael Paquier [Sun, 3 Sep 2023 23:04:22 +0000 (08:04 +0900)]
Fix handling of shared statistics with dropped databases
Dropping a database while a connection is attempted on it was able to
lead to the presence of valid database entries in shared statistics.
The issue is that MyDatabaseId was getting set too early than it should,
as, if the connection attempted on the dropped database fails when
renamed or dropped, the shutdown callback of the shared statistics would
finish by re-inserting a correct entry related to the database already
dropped.
As analyzed by the bug reporters, this issue could lead to phantom
entries in the database list maintained by the autovacuum launcher
(in rebuild_database_list()) if the database dropped was part of the
database list when it was still valid. After the database was dropped,
it would remain the highest on the list of databases to considered by
the autovacuum worker as things to process. This would prevent
autovacuum jobs to happen on all the other databases still present.
The commit fixes this issue by delaying setting MyDatabaseId until the
database existence has been re-checked with the second scan on
pg_database after getting a shared lock on it, and by switching
pgstat_update_dbstats() so as nothing happens if MyDatabaseId is not
valid.
Issue introduced by
5891c7a8ed8f, so backpatch down to 15.
Reported-by: Will Mortensen, Jacob Speidel
Analyzed-by: Will Mortensen, Jacob Speidel
Author: Andres Freund
Discussion: https://postgr.es/m/17973-
bca1f7d5c14f601e@postgresql.org
Backpatch-through: 15
Alvaro Herrera [Fri, 1 Sep 2023 17:49:20 +0000 (19:49 +0200)]
Fix not-null constraint test
When a partitioned table has a primary key, trying to find the
corresponding not-null constraint for that column would come up empty,
causing code that's trying to check said not-null constraint to crash.
Fix by only running the check when the not-null constraint exists.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/
d57b4a69-7394-3146-5976-
9a1ef27e7972@gmail.com
Alvaro Herrera [Fri, 1 Sep 2023 12:21:27 +0000 (14:21 +0200)]
ATPrepAddPrimaryKey: ignore non-PK constraints
Because of lack of test coverage, this function added by
b0e96f311985
wasn't ignoring constraint types other than primary keys, which it
should have. Add some lines to a test for it.
Reported-by: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48bc-k_-1fh0dZpAhp_LiR5MfEX9haystmoBboR_4czCQ@mail.gmail.com