Michael Paquier [Thu, 7 Dec 2023 05:27:54 +0000 (14:27 +0900)]
Improve some error messages with invalid indexes for REINDEX CONCURRENTLY
An invalid index is skipped when doing REINDEX CONCURRENTLY at table
level, with INDEX_CORRUPTED used as errcode. This is confusing,
because an invalid index could exist after an interruption. The errcode
is switched to OBJECT_NOT_IN_PREREQUISITE_STATE instead, as per a
suggestion from Andres Freund.
While on it, the error messages are reworded, and a hint is added,
telling how to rebuild an invalid index in this case. This has been
suggested by Noah Misch.
Discussion: https://postgr.es/m/
20231118230958.4fm3fhk4ypshxopa@awork3.anarazel.de
Amit Kapila [Thu, 7 Dec 2023 03:12:48 +0000 (08:42 +0530)]
Fix issues in binary_upgrade_logical_slot_has_caught_up().
The commit
29d0a77fa6 labelled binary_upgrade_logical_slot_has_caught_up()
as a non-strict function to allow providing a better error message to callers
in case the passed slot_name is NULL. On further discussion, it seems that
it is not helpful to have a different error message for NULL input in this
function, so this patch marks the function as strict.
This patch also removes the explicit permission check to use replication
slots as this function is invoked only by superusers and instead adds an
Assert.
Reported-by: Masahiko Sawada
Author: Hayato Kuroda
Reviewed-by: Vignesh C
Discussion: https://postgr.es/m/CAD21AoDSyiBKkMXBxN_gUayZZUCOgyHnG8Ge8rcPXNP3Tf6B4g@mail.gmail.com
Michael Paquier [Wed, 6 Dec 2023 23:31:02 +0000 (08:31 +0900)]
Fix assertion failure with REINDEX and event triggers
A REINDEX CONCURRENTLY run on a table with no indexes would always pop
the topmost snapshot from the active snapshot stack, making the snapshot
handling inconsistent between the multiple-relation and single-relation
cases. This commit slightly changes the snapshot stack handling so as a
snapshot is popped only ReindexMultipleInternal() in this case after a
relation has been reindexed, fixing a problem where an event trigger
function may need a snapshot but does not have one. This also keeps the
places where PopActiveSnapshot() is called closer to each other.
While on it, this expands the existing tests to cover all the cases that
could be faced with REINDEX commands and such event triggers, for one or
more relations, with or without indexes.
This behavior is inconsistent since
5dc92b844e68, but we've never had a
need for an active snapshot at the end of a REINDEX until now.
Thanks also to Jian He for the input.
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/
cb538743-484c-eb6a-a8c5-
359980cd3a17@gmail.com
Nathan Bossart [Wed, 6 Dec 2023 23:16:57 +0000 (17:16 -0600)]
Suppress -Wunused-result warning about write().
pg_test_fsync's signal_cleanup() intentionally ignores the write()
result since there's not much we could do about it, but certain
compilers make that harder than it ought to be.
This was missed in commit
52e98d4502.
Reviewed-by: Tristan Partin, Peter Eisentraut
Discussion: https://postgr.es/m/
20231206161839.GA2828158%40nathanxps13
Peter Eisentraut [Wed, 6 Dec 2023 09:11:36 +0000 (10:11 +0100)]
Use signal-safe functions in signal handler
According to signal-safety(7), exit(3) and puts(3) are not safe to call
in a signal handler.
Author: Tristan Partin <tristan@neon.tech>
Discussion: https://www.postgresql.org/message-id/flat/CTVDKVZCCVSY.1XQ87UL50KQRD%40gonk
Michael Paquier [Wed, 6 Dec 2023 05:10:39 +0000 (14:10 +0900)]
Fix compilation on Windows with WAL_DEBUG
This has been broken since
b060dbe0001a that has reworked the callback
mechanism of XLogReader, most likely unnoticed because any form of
development involving WAL happens on platforms where this compiles fine.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACVF14WKQMFwcJ=3okVDhiXpuK5f7YdT+BdYXbbypMHqWA@mail.gmail.com
Backpatch-through: 13
Michael Paquier [Wed, 6 Dec 2023 00:54:47 +0000 (09:54 +0900)]
Apply filters to dump files all the time in 002_pg_upgrade.pl
This commit removes the restriction that would not apply filters to the
dumps used for comparison in the TAP test of pg_upgrade when using the
same base version for the old and new nodes.
The previous logic would fail on Windows if loading a dump while using
the same set of binaries for the old and new nodes, as the library
dependencies updated in the old dump would append CRLFs to the dump
file as it is treated as a text file. The dump filtering logic replaces
all CRLFs (\r\n) by LFs (\n), which is able to prevent this issue.
When the old and new versions of the binaries are the same,
AdjustUpgrade removes all blank lines, removes version-based comments
generated by pg_dump and replaces CRLFs by LFs.
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/
60d434b9-53d9-9ea1-819b-
efebdcf44e41@gmail.com
Backpatch-through: 15
Alexander Korotkov [Tue, 5 Dec 2023 20:53:12 +0000 (22:53 +0200)]
Add support for deparsing semi-joins to contrib/postgres_fdw
SEMI-JOIN is deparsed as the EXISTS subquery. It references outer and inner
relations, so it should be evaluated as the condition in the upper-level WHERE
clause. The signatures of deparseFromExprForRel() and deparseRangeTblRef() are
revised so that they can add conditions to the upper level.
PgFdwRelationInfo now has a hidden_subquery_rels field, referencing the relids
used in the inner parts of semi-join. They can't be referred to from upper
relations and should be used internally for equivalence member searches.
The planner can create semi-join, which refers to inner rel vars in its target
list. However, we deparse semi-join as an exists() subquery. So we skip the
case when the target list references to inner rel of semi-join.
Author: Alexander Pyhalov
Reviewed-by: Ashutosh Bapat, Ian Lawrence Barwick, Yuuki Fujii, Tomas Vondra
Discussion: https://postgr.es/m/
c9e2a757cf3ac2333714eaf83a9cc184@postgrespro.ru
Robert Haas [Tue, 5 Dec 2023 17:51:39 +0000 (12:51 -0500)]
Rename pg_verifybackup's JsonManifestParseContext callback functions.
The old names were too generic, and would have applied to any binary
that made use of JsonManifestParseContext. Rename to make the names
specific to pg_verifybackup, since there are plans afoot to reuse
this infrastructure.
Per suggestion from Álvaro Herrra.
Discussion: http://postgr.es/m/
202311131625.o7hzq3oukuyd@alvherre.pgsql
Robert Haas [Tue, 5 Dec 2023 17:17:49 +0000 (12:17 -0500)]
Rename JsonManifestParseContext callbacks.
There is no real reason to just run multiple words together when
we can instead punctuate them with marks intended for that purpose.
Per suggestion from Álvaro Herrera.
Discussion: http://postgr.es/m/
202311161021.nisg7imt7kyf@alvherre.pgsql
Daniel Gustafsson [Tue, 5 Dec 2023 14:54:59 +0000 (15:54 +0100)]
Fix indentation
When preparing commit
98e675ed7af I accidentally forgot to run
pgindent, which did produce a diff. Fix by adding the required
whitespace per the koel buildfarm failure.
Daniel Gustafsson [Tue, 5 Dec 2023 13:30:56 +0000 (14:30 +0100)]
Fix incorrect error message for IDENTIFY_SYSTEM
Commit
5a991ef8692e accidentally reversed the order of the tuples
and fields parameters, making the error message incorrectly refer
to 3 tuples with 1 field when IDENTIFY_SYSTEM returns 1 tuple and
3 or 4 fields. Fix by changing the order of the parameters. This
also adds a comment describing why we check for < 3 when postgres
since 9.4 has been sending 4 fields.
Backpatch all the way since the bug is almost a decade old.
Author: Tomonari Katsumata <t.katsumata1122@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Bug: #18224
Backpatch-through: v12
Alvaro Herrera [Tue, 5 Dec 2023 11:43:24 +0000 (12:43 +0100)]
Fix handling of errors in libpq pipelines
The logic to keep the libpq command queue in sync with queries that have
been processed had a bug when errors were returned for reasons other
than problems in queries -- for example, when a connection is lost. We
incorrectly consumed an element from the command queue every time, but
this is wrong and can lead to the queue becoming empty ahead of time,
leading to later malfunction: PQgetResult would return nothing,
potentially causing the calling application to enter a busy loop.
Fix by making the SYNC queue element a barrier that can only be consumed
when a SYNC message is received.
Backpatch to 14.
Reported by: Иван Трофимов (Ivan Trofimov) <i.trofimow@yandex.ru>
Discussion: https://postgr.es/m/17948-
fcace7557e449957@postgresql.org
Amit Kapila [Tue, 5 Dec 2023 03:40:06 +0000 (09:10 +0530)]
Fix a random failure in 003_logical_slots.pl.
The failed test was trying to validate that the two_phase option for a
slot is retained after the upgrade. The problem was that it didn't get
enabled before the upgrade so expecting to be enabled after the upgrade
was not right in the first place. This is a timing issue because we enable
the two_phase once the initial sync for all the tables is finished.
Normally, we wait for the two_phase state to be enabled but this test
missed that step.
Per buildfarm.
Author: Hayato Kuroda
Discussion: https://postgr.es/m/TY3PR01MB98892396D1071FC4320D6B31F586A@TY3PR01MB9889.jpnprd01.prod.outlook.com
Jeff Davis [Tue, 5 Dec 2023 01:19:16 +0000 (17:19 -0800)]
Optimize SearchPathCache by saving the last entry.
Repeated lookups are common, so it's worth it to check the last entry
before doing another hash lookup.
Discussion: https://postgr.es/m/
04c8592dbd694e4114a3ed87139a7a04e4363030.camel%40j-davis.com
Nathan Bossart [Mon, 4 Dec 2023 17:55:18 +0000 (11:55 -0600)]
Teach convert() and friends to avoid copying when possible.
Presently, pg_convert() allocates a new bytea and copies the result
regardless of whether any conversion actually happened. This
commit adjusts this function to return the source pointer as-is if
no conversion occurred. This optimization isn't expected to make a
tremendous difference, but it still seems worthwhile to avoid
unnecessary memory allocations.
Author: Yurii Rashkovskii
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/CA%2BRLCQyknBPSWXRBQGOi6aYEcdQ9RpH9Kch4GjoeY8dQ3D%2Bvhw%40mail.gmail.com
Heikki Linnakangas [Mon, 4 Dec 2023 13:34:37 +0000 (15:34 +0200)]
Remove now-unnecessary Autovacuum[Launcher|Worker]IAm functions
After commit
fd5e8b440d, InitProcess() is called later in the
EXEC_BACKEND startup sequence, so it's enough to set the
am_autovacuum_[launcher|worker] variables at the same place as in the
!EXEC_BACKEND case.
Alvaro Herrera [Mon, 4 Dec 2023 13:00:51 +0000 (14:00 +0100)]
Don't use pgbench -j in tests
It draws an unnecessary error in builds compiled without thread support.
Added by commit
038f586d5f1d, which was backpatched to 14; though in
branch master we no longer support such builds, there's no reason to
have this there, so remove it in all branches since 14.
Reported-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/ZW2G9Ix4nBKLcSSO@paquier.xyz
Peter Eisentraut [Mon, 4 Dec 2023 05:34:27 +0000 (06:34 +0100)]
Remove unnecessary include of <math.h>
This was probably never necessary. (The header used to use random(),
but that shouldn't require <math.h> either. In any case, that's gone,
too.)
Reviewed-by: Shubham Khanna <Shubham.Khanna@fujitsu.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/
cff5475d-e0a9-4561-b094-
794aa36bd031%40eisentraut.org
Peter Eisentraut [Mon, 4 Dec 2023 05:34:27 +0000 (06:34 +0100)]
Remove unnecessary include of <sys/socket.h>
This was put here as part of a mechanical replacement of the old
"getaddrinfo.h" with <netdb.h> plus <sys/socket.h> (commit
5579388d2d). But here, we only need netdb.h (for NI_MAXHOST), not
sys/socket.h.
Reviewed-by: Shubham Khanna <Shubham.Khanna@fujitsu.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/
cff5475d-e0a9-4561-b094-
794aa36bd031%40eisentraut.org
Peter Eisentraut [Mon, 4 Dec 2023 05:34:27 +0000 (06:34 +0100)]
Remove unnecessary includes of <signal.h>
These were once needed for sig_atomic_t, but that no longer appears in
these headers, so the include is not needed.
Reviewed-by: Shubham Khanna <Shubham.Khanna@fujitsu.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/
cff5475d-e0a9-4561-b094-
794aa36bd031%40eisentraut.org
Michael Paquier [Mon, 4 Dec 2023 00:53:49 +0000 (09:53 +0900)]
Add support for REINDEX in event triggers
This commit adds support for REINDEX in event triggers, making this
command react for the events ddl_command_start and ddl_command_end. The
indexes rebuilt are collected with the ReindexStmt emitted by the
caller, for the concurrent and non-concurrent paths.
Thanks to that, it is possible to know a full list of the indexes that a
single REINDEX command has worked on.
Author: Garrett Thornburg, Jian He
Reviewed-by: Jim Jones, Michael Paquier
Discussion: https://postgr.es/m/CAEEqfk5bm32G7sbhzHbES9WejD8O8DCEOaLkxoBP7HNWxjPpvg@mail.gmail.com
Michael Paquier [Sun, 3 Dec 2023 23:09:51 +0000 (08:09 +0900)]
doc: Remove reference to trigger file regarding promotion
The wording changed here comes from
991bfe11d28a, when the only way to
trigger a promotion was with a trigger file. There are more options to
achieve this operation these days, like the SQL function pg_promote() or
the command `pg_ctl promote`, so it is confusing to assume that only a
trigger file is able to do the work.
Note also that promote_trigger_file has been removed as of
cd4329d9393f
in 16~.
Author: Shinya Kato
Discussion: https://postgr.es/m/
201b08ea29aa61f96162080e75be503c@oss.nttdata.com
Backpatch-through: 12
Heikki Linnakangas [Sun, 3 Dec 2023 14:39:18 +0000 (16:39 +0200)]
Refactor how InitProcess is called
The order of process initialization steps is now more consistent
between !EXEC_BACKEND and EXEC_BACKEND modes. InitProcess() is called
at the same place in either mode. We can now also move the
AttachSharedMemoryStructs() call into InitProcess() itself. This
reduces the number of "#ifdef EXEC_BACKEND" blocks.
Reviewed-by: Tristan Partin, Andres Freund, Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/
7a59b073-5b5b-151e-7ed3-
8b01ff7ce9ef@iki.fi
Heikki Linnakangas [Sun, 3 Dec 2023 14:38:54 +0000 (16:38 +0200)]
Pass BackgroundWorker entry in the parameter file in EXEC_BACKEND mode
The BackgroundWorker struct is now passed the same way as the Port
struct. Seems more consistent.
This makes it possible to move InitProcess later in SubPostmasterMain
(in next commit), as we no longer need to access shared memory to read
background worker entry.
Reviewed-by: Tristan Partin, Andres Freund, Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/
7a59b073-5b5b-151e-7ed3-
8b01ff7ce9ef@iki.fi
Heikki Linnakangas [Sun, 3 Dec 2023 14:09:42 +0000 (16:09 +0200)]
Refactor CreateSharedMemoryAndSemaphores
For clarity, have separate functions for *creating* the shared memory
and semaphores at postmaster or single-user backend startup, and
for *attaching* to existing shared memory structures in EXEC_BACKEND
case. CreateSharedMemoryAndSemaphores() is now called only at
postmaster startup, and a new AttachSharedMemoryStructs() function is
called at backend startup in EXEC_BACKEND mode.
Reviewed-by: Tristan Partin, Andres Freund
Discussion: https://www.postgresql.org/message-id/
7a59b073-5b5b-151e-7ed3-
8b01ff7ce9ef@iki.fi
Heikki Linnakangas [Fri, 1 Dec 2023 20:30:08 +0000 (22:30 +0200)]
Silence Valgrind complaint with EXEC_BACKEND
The padding bytes written to the backend params file were
uninitialized. That's harmless because we don't access the padding
bytes when we read the file back in, but Valgrind doesn't know
that. In any case, clear the padding bytes to make Valgrind happy.
Reported-by: Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/
014768ed-8b39-c44f-b07c-
098c87b1644c@gmail.com
Peter Eisentraut [Fri, 1 Dec 2023 16:58:18 +0000 (17:58 +0100)]
pgindent fix
for commit
a11c9c42ea
Peter Eisentraut [Fri, 1 Dec 2023 14:48:06 +0000 (15:48 +0100)]
Check collation when creating partitioned index
When creating a partitioned index, the partition key must be a subset
of the index's columns. But this currently doesn't check that the
collations between the partition key and the index definition match.
So you can construct a unique index that fails to enforce uniqueness.
(This would most likely involve a nondeterministic collation, so it
would have to be crafted explicitly and is not something that would
just happen by accident.)
This patch adds the required collation check. As a result, any
previously allowed unique index that has a collation mismatch would no
longer be allowed to be created.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/
3327cb54-f7f1-413b-8fdb-
7a9dceebb938%40eisentraut.org
Peter Eisentraut [Fri, 1 Dec 2023 07:40:45 +0000 (08:40 +0100)]
doc: Update info on information schema usage tables
Commit
f40c6969d0 added the information schema usage tables but added
documentation that they did not fully work yet. Commit
e717a9a18b
then added SQL-standard function bodies, which made the information
schema views fully functional, but it neglected to update the
documentation. This is now done here.
Reported-by: Erki Eessaar <erki.eessaar@taltech.ee>
Reviewed-by: Erki Eessaar <erki.eessaar@taltech.ee>
Discussion: https://www.postgresql.org/message-id/flat/AM9PR01MB8268EC7B696F9FE346CA5B93FEB8A%40AM9PR01MB8268.eurprd01.prod.exchangelabs.com
Amit Kapila [Fri, 1 Dec 2023 04:44:36 +0000 (10:14 +0530)]
Fix an uninitialized access in hash_xlog_squeeze_page().
Commit
861f86beea changed hash_xlog_squeeze_page() to start reading
the write buffer conditionally but forgot to initialize it leading to an
uninitialized access.
Reported-by: Alexander Lakhin
Author: Hayato Kuroda
Reviewed-by: Alexander Lakhin, Amit Kapila
Discussion: http://postgr.es/m/
62ed1a9f-746a-8e86-904b-
51b9b806a1d9@gmail.com
Andres Freund [Fri, 1 Dec 2023 01:43:39 +0000 (17:43 -0800)]
meson: Stop using deprecated way getting path of files
The just released meson 1.3 strongly deprecated a hack we were using, emitting
a noisy warning (the hack basically depended on an implementation detail to
work). Turns out there has been a better way available for a while, I just
hadn't found it. 1.4 added a more convenient approach, but we can't rely on
that.
Reviewed-by: Tristan Partin <tristan@neon.tech>
Discussion: https://postgr.es/m/
20231129185053.s6c7f73eg7b4ztfi@awork3.anarazel.de
Backpatch: 16-, where the meson build was added.
Thomas Munro [Fri, 1 Dec 2023 01:58:40 +0000 (14:58 +1300)]
Adjust obsolete comment explaining set_stack_base().
Commit
7389aad6 removed the notion of backends started from inside a
signal handler. A stray comment still referred to them, while
explaining the need for a call to set_stack_base(). That leads to the
question of whether we still need the call in !EXEC_BACKEND builds.
There doesn't seem to be much point in suppressing it now, as it doesn't
hurt and probably helps to measure the stack base from the exact same
place in EXEC_BACKEND and !EXEC_BACKEND builds.
Back-patch to 16.
Reported-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reported-by: Tristan Partin <tristan@neon.tech>
Reported-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA%2BhUKG%2BEJHcevNGNOxVWxTNFbuB%3Dvjf4U68%2B85rAC_Sxvy2zEQ%40mail.gmail.com
Heikki Linnakangas [Thu, 30 Nov 2023 23:00:03 +0000 (01:00 +0200)]
Print lwlock stats also for aux processes, when built with LWLOCK_STATS
InitAuxiliaryProcess() closely resembles InitProcess(), but it didn't
call InitLWLockAccess(). But because InitLWLockAccess() is a no-op
unless compiled with LWLOCK_STATS, and everything works even if it's
not called, the only consequence was that the stats were not printed
for aux processes.
This was an oversight in commit
1c6821be31f, in version 9.5, so it is
missing in all supported branches. But since it only affects
developers using LWLOCK_STATS and no one has complained, no
backpatching.
Discussion: https://www.postgresql.org/message-id/
20231130202648.7k6agmuizdilufnv@awork3.anarazel.de
Alexander Korotkov [Thu, 30 Nov 2023 11:45:28 +0000 (13:45 +0200)]
Fix typo in
5a1dfde8334b
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/
55d8800f-4a80-5256-1e84-
246fbe79acd0@gmail.com
Daniel Gustafsson [Thu, 30 Nov 2023 09:56:53 +0000 (10:56 +0100)]
Fix spelling and punctuation
Remove trailing periods from pg_log_error emitted strings as only
hint and detail level error messages should be punctuated. Also
reword the usage screen which was missing a word.
Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/
20231130.105223.
554982964895179414.horikyota.ntt@gmail.com
Discussion: https://postgr.es/m/
20231130.103900.
2069212175914114279.horikyota.ntt@gmail.com
Daniel Gustafsson [Thu, 30 Nov 2023 09:56:51 +0000 (10:56 +0100)]
Add missing file to nls Makefile
Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/
20231130.120009.
1370713511317755874.horikyota.ntt@gmail.com
Daniel Gustafsson [Thu, 30 Nov 2023 09:56:48 +0000 (10:56 +0100)]
Fix array subscript warnings
Commit
a5cf808be55 accidentally passed signed chars to isalpha and
isspace in the parser code which leads to undefined behavior. Fix
by casting the parameters to unsigned chars.
Author: Pavel Stehule <pavel.stehule@gmail.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/388186.
1701315586@sss.pgh.pa.us
Discussion: https://postgr.es/m/ZWgg5xim2CXQcfmh@paquier.xyz
Alexander Korotkov [Thu, 30 Nov 2023 09:34:45 +0000 (11:34 +0200)]
Fix warning due non-standard inline declaration in
4ed8f0913bfdb5f355
Reported-by: Alexander Lakhin, Tom Lane
Author: Pavel Borisov
Discussion: https://postgr.es/m/
55d8800f-4a80-5256-1e84-
246fbe79acd0@gmail.com
John Naylor [Thu, 30 Nov 2023 08:25:57 +0000 (15:25 +0700)]
Remove redundant setting of hashkey after insertion
It's not necessary to fill the key field in most cases, since
hash_search has already done that. Some existing call sites have an
assert or comment that this contract has been fulfilled, but those
are quite old and that practice seems unnecessary here.
While at it, remove a nearby redundant assignment that a smart compiler
will elide anyway.
Zhao Junwang, with some adjustments by me
Reviewed by Nathan Bossart, with additional feedback from Tom Lane
Discussion: http://postgr.es/m/CAEG8a3%2BUPF%3DR2QGPgJMF2mKh8xPd1H2TmfH77zPuVUFdBpiGUA%40mail.gmail.com
Peter Eisentraut [Thu, 30 Nov 2023 06:22:51 +0000 (07:22 +0100)]
meson: Improve/fix Python version selection
When we look for the Python installation using the meson python
module, we should make it use the python program previously determined
by the 'PYTHON' option. Otherwise, it will just use its own search
and the 'PYTHON' option won't affect it. We need this to be able to
select the Python installation to build PL/Python against.
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/
3f5427e8-cef6-474d-ae88-
13db1bfdc1a7%40eisentraut.org
Masahiko Sawada [Thu, 30 Nov 2023 05:29:48 +0000 (14:29 +0900)]
Add tests for XID wraparound.
The test module includes helper functions to quickly burn through lots
of XIDs. They are used in the tests, and are also handy for manually
testing XID wraparound.
Since these tests are very expensive the entire suite is disabled by
default. It requires to set PG_TEST_EXTRA to run it.
Reviewed-by: Daniel Gustafsson, John Naylor, Michael Paquier
Reviewed-by: vignesh C
Author: Heikki Linnakangas, Masahiko Sawada, Andres Freund
Discussion: https://www.postgresql.org/message-id/CAD21AoDVhkXp8HjpFO-gp3TgL6tCKcZQNxn04m01VAtcSi-5sA%40mail.gmail.com
Michael Paquier [Thu, 30 Nov 2023 05:19:29 +0000 (14:19 +0900)]
doc: Mention how to use quotes with GUC names in error messages
Quotes should not be used except if a GUC name is a natural English
word.
Author: Álvaro Herrera
Discussion: https://postgr.es/m/CAHut+Pv-kSN8SkxSdoHano_wPubqcg5789ejhCDZAcLFceBR-w@mail.gmail.com
Michael Paquier [Thu, 30 Nov 2023 05:11:45 +0000 (14:11 +0900)]
Apply quotes more consistently to GUC names in logs
Quotes are applied to GUCs in a very inconsistent way across the code
base, with a mix of double quotes or no quotes used. This commit
removes double quotes around all the GUC names that are obviously
referred to as parameters with non-English words (use of underscore,
mixed case, etc).
This is the result of a discussion with Álvaro Herrera, Nathan Bossart,
Laurenz Albe, Peter Eisentraut, Tom Lane and Daniel Gustafsson.
Author: Peter Smith
Discussion: https://postgr.es/m/CAHut+Pv-kSN8SkxSdoHano_wPubqcg5789ejhCDZAcLFceBR-w@mail.gmail.com
Masahiko Sawada [Thu, 30 Nov 2023 05:08:34 +0000 (14:08 +0900)]
Add option to specify timeout seconds to BackgroundPsql.pm.
Previously, a background psql session uses the default timeout and it
cannot be overridden. This change adds a new option to set the timeout
during start.
There are no users of this new option. It is needed for an upcoming
patch adding tests for XID wraparound.
Reviewed-by: Daniel Gustafsson, Noah Misch
Discussion: https://postgr.es/m/
C9CF2F76-0D81-4C9D-9832-
202BE8517056%40yesql.se
Peter Eisentraut [Thu, 30 Nov 2023 05:00:44 +0000 (06:00 +0100)]
Remove unused macro
Usage was removed in
a33e17f210 but the definition was not removed.
Peter Eisentraut [Thu, 30 Nov 2023 04:33:55 +0000 (05:33 +0100)]
Improve "user mapping not found" error message
Display the name of the foreign server for which the user mapping was
not found.
Author: Ian Lawrence Barwick <barwick@gmail.com>
Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/flat/CAB8KJ=jFzNaeyFtLcTZNOc6fd1+F93pGVLFa-wyt31wn7VNxqQ@mail.gmail.com
Amit Kapila [Thu, 30 Nov 2023 04:01:21 +0000 (09:31 +0530)]
Fix a test in 003_logical_slots.
We allow to upgrade the slot iff there is no pending WAL to be processed.
The test first disables the subscription to avoid unnecessary LOGs on the
subscriber and then stops the publisher node. It is quite possible that
just before the shutdown of the publisher, autovacuum generates some WAL
record that needs to be processed, so just disable the autovacuum for this
test.
Per buildfarm.
Author: Hayato Kuroda
Reviewed-by: Amit Kapila
Discussion: http://postgr.es/m/OS3PR01MB9882FED1F0060468FB01B9DAF583A@OS3PR01MB9882.jpnprd01.prod.outlook.com
Masahiko Sawada [Thu, 30 Nov 2023 02:23:00 +0000 (11:23 +0900)]
Fix wrong description of BackgroundPsql's timeout.
Backpatch through 16 where this was introduced by
664d757531e1.
Reviewed-by: Daniel Gustafsson
Backpatch-through: 16
Discussion: http://postgr.es/m/CAD21AoBXMEqDBLoDuAWVWoTLYB4aNsxx4oYNmyJJbhfq_vGQBQ@mail.gmail.com
Masahiko Sawada [Thu, 30 Nov 2023 01:14:17 +0000 (10:14 +0900)]
Fix BackgroundPsql's set_query_timer_restart() issue without argument.
The set_query_timer_restart() required an argument to define a value
to query_timer_restart, but none of the existing callers passes an
argument to this function.
This changes the function to set a value without an argument.
Backpatch through 16 where the background psql TAP functions were
refactored by
664d757531e1.
Reviewed-by: Bharath Rupireddy, Tom Lane
Discussion: https://postgr.es/m/CAD21AoA0B6VKe_5A9nZi8i5umwSN-zJJuPVNht9DaOZ9SJumMA@mail.gmail.com
Backpatch-through: 16
Daniel Gustafsson [Wed, 29 Nov 2023 13:56:26 +0000 (14:56 +0100)]
Fix typo in comment
Spotted while looking over changes for another patch.
Daniel Gustafsson [Wed, 29 Nov 2023 13:56:24 +0000 (14:56 +0100)]
Read include/exclude commands for dump/restore from file
When there is a need to filter multiple tables with include and/or exclude
options it's quite possible to run into the limitations of the commandline.
This adds a --filter=FILENAME feature to pg_dump, pg_dumpall and pg_restore
which is used to supply a file containing object exclude/include commands
which work just like their commandline counterparts. The format of the file
is one command per row like:
<command> <object> <objectpattern>
<command> can be "include" or "exclude", <object> can be table_data, index
table_data_and_children, database, extension, foreign_data, function, table
schema, table_and_children or trigger.
This patch has gone through many revisions and design changes over a long
period of time, the list of reviewers reflect reviewers of some version of
the patch, not necessarily the final version.
Patch by Pavel Stehule with some additional hacking by me.
Author: Pavel Stehule <pavel.stehule@gmail.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Reviewed-by: Erik Rijkers <er@xs4all.nl>
Discussion: https://postgr.es/m/CAFj8pRB10wvW0CC9Xq=1XDs=zCQxer3cbLcNZa+qiX4cUH-G_A@mail.gmail.com
Thomas Munro [Wed, 29 Nov 2023 03:44:19 +0000 (16:44 +1300)]
Optimize pg_readv/pg_pwritev single vector case.
For the trivial case of iovcnt == 1, kernels are measurably slower at
dealing with the more complex arguments of preadv/pwritev than the
equivalent plain old pread/pwrite. The overheads are worth it for
iovcnt > 1, but for 1 let's just redirect to the cheaper calls. While
we could leave it to callers to worry about that, we already have to
have our own pg_ wrappers for portability reasons so it seems
reasonable to centralize this knowledge there (thanks to Heikki for this
suggestion). Try to avoid function call overheads by making them
inlinable, which might also allow the compiler to avoid the branch in
some cases. For systems that don't have preadv and pwritev (currently:
Windows and [closed] Solaris), we might as well pull the replacement
functions up into the static inline functions too.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/CA+hUKGJkOiOCa+mag4BF+zHo7qo=o9CFheB8=g6uT5TUm2gkvA@mail.gmail.com
Alexander Korotkov [Tue, 28 Nov 2023 23:44:01 +0000 (01:44 +0200)]
Add SLRU tests for 64-bit page case
4ed8f0913b added 64-bit page numbering for SLRU. This commit adds tests for
page numbers higher than 2^32.
Author: Maxim Orlov
Reviewed-by: Aleksander Alekseev, Alexander Korotkov
Discussion: https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.com
Discussion: https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
Alexander Korotkov [Tue, 28 Nov 2023 23:43:13 +0000 (01:43 +0200)]
Make use FullTransactionId in 2PC filenames
Switch from using TransactionId to FullTransactionId in naming of 2PC files.
Transaction state file in the pg_twophase directory now have extra 8 bytes in
the name to address an epoch of a given xid.
Author: Maxim Orlov, Aleksander Alekseev, Alexander Korotkov, Teodor Sigaev
Author: Nikita Glukhov, Pavel Borisov, Yura Sokolov
Reviewed-by: Jacob Champion, Heikki Linnakangas, Alexander Korotkov
Reviewed-by: Japin Li, Pavel Borisov, Tom Lane, Peter Eisentraut, Andres Freund
Reviewed-by: Andrey Borodin, Dilip Kumar, Aleksander Alekseev
Discussion: https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.com
Discussion: https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
Alexander Korotkov [Tue, 28 Nov 2023 23:41:48 +0000 (01:41 +0200)]
Use larger segment file names for pg_notify
This avoids the wraparound in async.c and removes the corresponding code
complexity. The maximum amount of allocated SLRU pages for NOTIFY / LISTEN
queue is now determined by the max_notify_queue_pages GUC. The default
value is
1048576. It allows to consume up to 8 GB of disk space which is
exactly the limit we had previously.
Author: Maxim Orlov, Aleksander Alekseev, Alexander Korotkov, Teodor Sigaev
Author: Nikita Glukhov, Pavel Borisov, Yura Sokolov
Reviewed-by: Jacob Champion, Heikki Linnakangas, Alexander Korotkov
Reviewed-by: Japin Li, Pavel Borisov, Tom Lane, Peter Eisentraut, Andres Freund
Reviewed-by: Andrey Borodin, Dilip Kumar, Aleksander Alekseev
Discussion: https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.com
Discussion: https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
Alexander Korotkov [Tue, 28 Nov 2023 23:39:55 +0000 (01:39 +0200)]
Index SLRUs by 64-bit integers rather than by 32-bit integers
We've had repeated bugs in the area of handling SLRU wraparound in the past,
some of which have caused data loss. Switching to an indexing system for SLRUs
that does not wrap around should allow us to get rid of a whole bunch
of problems and improve the overall reliability of the system.
This particular patch however only changes the indexing and doesn't address
the wraparound per se. This is going to be done in the following patches.
Author: Maxim Orlov, Aleksander Alekseev, Alexander Korotkov, Teodor Sigaev
Author: Nikita Glukhov, Pavel Borisov, Yura Sokolov
Reviewed-by: Jacob Champion, Heikki Linnakangas, Alexander Korotkov
Reviewed-by: Japin Li, Pavel Borisov, Tom Lane, Peter Eisentraut, Andres Freund
Reviewed-by: Andrey Borodin, Dilip Kumar, Aleksander Alekseev
Discussion: https://postgr.es/m/CACG%3DezZe1NQSCnfHOr78AtAZxJZeCvxrts0ygrxYwe%3DpyyjVWA%40mail.gmail.com
Discussion: https://postgr.es/m/CAJ7c6TPDOYBYrnCAeyndkBktO0WG2xSdYduTF0nxq%2BvfkmTF5Q%40mail.gmail.com
Tom Lane [Tue, 28 Nov 2023 18:32:15 +0000 (13:32 -0500)]
Clean up usage of bison precedence for non-operator keywords.
Assigning a precedence to a keyword that isn't a kind of expression
operator is rather dangerous, because it might mask grammar
ambiguities that we'd rather know about. It's much safer to attach
explicit precedences to individual rules, which will affect the
behavior of only that one rule. Moreover, when we do have to give
a precedence to a non-operator keyword, we should try to give it the
same precedence as IDENT, thereby reducing the risk of surprising
side-effects.
Apply this hard-won knowledge to SET (which I misassigned ages ago
in commit
2647ad658) and some SQL/JSON-related productions
(from commits
6ee30209a,
71bfd1543).
Patch HEAD only, since there's no evidence of actual bugs here.
Discussion: https://postgr.es/m/CADT4RqBPdbsZW7HS1jJP319TMRHs1hzUiP=iRJYR6UqgHCrgNQ@mail.gmail.com
Tom Lane [Tue, 28 Nov 2023 17:34:03 +0000 (12:34 -0500)]
Use BIO_{get,set}_app_data instead of BIO_{get,set}_data.
We should have done it this way all along, but we accidentally got
away with using the wrong BIO field up until OpenSSL 3.2. There,
the library's BIO routines that we rely on use the "data" field
for their own purposes, and our conflicting use causes assorted
weird behaviors up to and including core dumps when SSL connections
are attempted. Switch to using the approved field for the purpose,
i.e. app_data.
While at it, remove our configure probes for BIO_get_data as well
as the fallback implementation. BIO_{get,set}_app_data have been
there since long before any OpenSSL version that we still support,
even in the back branches.
Also, update src/test/ssl/t/001_ssltests.pl to allow for a minor
change in an error message spelling that evidently came in with 3.2.
Tristan Partin and Bo Andreson. Back-patch to all supported branches.
Discussion: https://postgr.es/m/CAN55FZ1eDDYsYaL7mv+oSLUij2h_u6hvD4Qmv-7PK7jkji0uyQ@mail.gmail.com
Heikki Linnakangas [Tue, 28 Nov 2023 12:08:43 +0000 (14:08 +0200)]
Fix comment about ressortgrouprefs being unique in setop plans.
Author: Richard Guo, Tom Lane
Discussion: https://www.postgresql.org/message-id/CAMbWs49rAfFS-yd7=QxtDUrZDFfRBGy4rGBJNyGDH7=CLipFPg@mail.gmail.com
Michael Paquier [Tue, 28 Nov 2023 10:44:13 +0000 (19:44 +0900)]
Remove more statements from stats.sql
Some of the statements capturing stats reset timestamps have become
unnecessary after
a9a8108411e4, so let's remove them.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACUnvB_Yo=O1xApBa4CDqQpW-x=QM35GBN1MqVRAxAGXEg@mail.gmail.com
Heikki Linnakangas [Tue, 28 Nov 2023 09:59:09 +0000 (11:59 +0200)]
Fix assertions with RI triggers in heap_update and heap_delete.
If the tuple being updated is not visible to the crosscheck snapshot,
we return TM_Updated but the assertions would not hold in that case.
Move them to before the cross-check.
Fixes bug #17893. Backpatch to all supported versions.
Author: Alexander Lakhin
Backpatch-through: 12
Discussion: https://www.postgresql.org/message-id/17893-
35847009eec517b5%40postgresql.org
Dean Rasheed [Tue, 28 Nov 2023 09:50:17 +0000 (09:50 +0000)]
psql: Add tab completion for view options.
Add support for tab completion of WITH (...) options to CREATE VIEW,
and for the corresponding SET/RESET (...) options in ALTER VIEW.
Christoph Heiss, reviewed by Melih Mutlu, Vignesh C, Jim Jones,
Mikhail Gribkov, David Zhang, Shubham Khanna, and me.
Discussion: https://postgr.es/m/
a2075c5a-66f9-a564-f038-
9ac044b03117@c8h4.io
Michael Paquier [Tue, 28 Nov 2023 04:18:59 +0000 (13:18 +0900)]
Remove test for pg_stat_reset_shared() in stats.sql
Some buildfarm members have been failing a test related to pg_stat_io,
as an effect of
23c8c0c8f472 that has switched pg_stat_reset_shared()
from being a no-op to reset all shared stats types.
This extra reset has the effect to make pg_stat_io's counters low enough
that little concurrent activity is enough to cause a failure. Another
thing I have considered is to move this sequence at the end of
stats.sql, but there are other instabilities, one being pg_stat_wal.
Knowing that there are already tests for the reset of each individual
shared stats target, this test has limited value, so let's remove it to
minimize the number of resets done for each shared stats type. This
should hopefully improve the stability of the whole.
Discussion: https://postgr.es/m/
3500949.
1700935734@sss.pgh.pa.us
Michael Paquier [Mon, 27 Nov 2023 23:40:08 +0000 (08:40 +0900)]
Fix comment in tableam.h about GetHeapamTableAmRoutine()
This routine is located in heapam_handler.c, not tableamapi.c. Issue
noted while hacking the area for a different patch.
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/ZWQuHltp2KS_0Cct@paquier.xyz
Michael Paquier [Mon, 27 Nov 2023 23:35:50 +0000 (08:35 +0900)]
Add CHECK_FOR_INTERRUPTS() in scram_SaltedPassword() for the backend
scram_SaltedPassword() could take a long time to compute when the number
of iterations used is large enough, and this code uses a tight loop to
compute a salted password.
Note that the same issue exists in libpq when using \password and a
large iteration number, but this cannot be interrupted. A CFI in the
backend is useful for server-side computations, at least.
Backpatch down to 16, where the user-settable GUC scram_iterations has
been added.
Author: Bowen Shi
Reviewed-by: Aleksander Alekseev, Daniel Gustafsson
Discussion: https://postgr.es/m/CAM_vCueV6xfr08KczfaCEk5J_qeTZtgqN7+orkNLx=g+phE82Q@mail.gmail.com
Backpatch-through: 16
David Rowley [Mon, 27 Nov 2023 21:41:12 +0000 (10:41 +1300)]
Don't use bms_membership() in cases where we don't need to
00b41463c adjusted Bitmapset so that an empty set is always represented
as NULL. This makes checking for empty sets far cheaper than it used
to be.
There were various places in the code where we'd call bms_membership()
to handle the 3 possible BMS_Membership values. For the BMS_SINGLETON
case, we'd also call bms_singleton_member() to find the single set member.
This can now be done in a more optimal way by first checking if the set is
NULL and then not bothering with bms_membership() and simply call
bms_get_singleton_member() instead to find the single member. This
function will return false if there are multiple members in the set.
Here we also tidy up some logic in examine_variable() for the single
member case. There's now no need to call bms_is_member() as we've
already established that we're working with a singleton Bitmapset, so we
can just check if varRelid matches the singleton member.
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/CAApHDvqW+CxNPcY245GaWiuqkkqgTudtG2ncGvvSjGn2wdTZLA@mail.gmail.com
Nathan Bossart [Mon, 27 Nov 2023 19:10:09 +0000 (13:10 -0600)]
Retire a few backwards compatibility macros.
As of commits
dd04e958c8 and
1833f1a1c3, tuplestore_donestoring(),
SPI_push(), SPI_pop(), SPI_push_conditional(),
SPI_pop_conditional(), and SPI_restore_connection() are no-op
macros provided for backwards compatibility. This commit removes
these macros, so any uses in third-party code will need to be
removed, too. Since these macros have been no-ops for a while,
such adjustments won't produce any behavior changes for all
currently-supported versions of PostgreSQL.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACVeO58JM5tK2Qa8QC-%3DkC8sdkJOTd4BFU%3DK8zs4gGYpjQ%40mail.gmail.com
Alvaro Herrera [Mon, 27 Nov 2023 18:18:03 +0000 (19:18 +0100)]
Fix CREATE INDEX CONCURRENTLY example
It fails to use the CONCURRENTLY keyword where it was necessary, so add
it. This text was added to pg11 in commit
5efd604ec0a3; backpatch to pg12.
Author: Nikolay Samokhvalov <nik@postgres.ai>
Discussion: https://postgr.es/m/CAM527d9iz6+=_c7EqSKaGzjqWvSeCeRVVvHZ1v3gDgjTtvgsbw@mail.gmail.com
Tomas Vondra [Mon, 27 Nov 2023 15:52:59 +0000 (16:52 +0100)]
Check if ii_AmCache is NULL in aminsertcleanup
Fix a bug introduced by
c1ec02be1d79. It may happen that the executor
opens indexes on the result relation, but no rows end up being inserted.
Then the index_insert_cleanup still gets executed, but passes down NULL
to the AM callback. The AM callback may not expect this, as is the case
of brininsertcleanup, leading to a crash.
Fixed by only calling the cleanup callback if (ii_AmCache != NULL). This
way the AM can simply assume to only see a valid cache.
Reported-by: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-w9qC-o9hQox9UHvdVZAYTp8OrPQOKtwbvzWaRejTT=Q@mail.gmail.com
Heikki Linnakangas [Mon, 27 Nov 2023 15:42:39 +0000 (17:42 +0200)]
Reduce rate of walwriter wakeups due to async commits.
XLogSetAsyncXactLSN(), called at asynchronous commit, would wake up
walwriter every time the LSN advances, but walwriter doesn't actually
do anything unless it has at least 'wal_writer_flush_after' full
blocks of WAL to write. Repeatedly waking up walwriter to do nothing
is a waste of CPU cycles in both walwriter and the backends doing the
wakeups. To fix, apply the same logic in XLogSetAsyncXactLSN() to
decide whether to wake up walwriter, as walwriter uses to determine if
it has any work to do.
In the passing, rename misleadingly named 'flushbytes' local variable
to 'flushblocks'.
Author: Andres Freund, Heikki Linnakangas
Discussion: https://www.postgresql.org/message-id/
20231024230929.vsc342baqs7kmbte@awork3.anarazel.de
Amit Kapila [Mon, 27 Nov 2023 03:19:55 +0000 (08:49 +0530)]
Avoid unconditionally filling in missing values with NULL in pgoutput.
52e4f0cd4 introduced a bug in pgoutput in which missing values in tuples
were incorrectly filled in with NULL. The problem was the use of
CreateTupleDescCopy where CreateTupleDescCopyConstr was required, as the
former drops the constraints in the tuple description (specifically, the
default value constraint) on the floor.
The bug could result in incorrectness when a table replicated via
`REPLICA IDENTITY FULL` underwent a schema change that added a column
with a default value. The problem is that in such cases updates fill NULL
values in old tuples for missing columns for default values. Then on the
subscriber, we failed to find a matching tuple and missed updating the
required row.
Author: Nikhil Benesch
Reviewed-by: Hou Zhijie, Amit Kapila
Backpatch-through: 15
Discussion: http://postgr.es/m/CAPWqQZTEpZQamYsGMn6ZDRvVywwpVPiKH6OY4KSgA+NmeqFNzA@mail.gmail.com
Alexander Korotkov [Mon, 27 Nov 2023 00:51:18 +0000 (02:51 +0200)]
Track statement entry timestamp in contrib/pg_stat_statements
This patch adds 'stats_since' and 'minmax_stats_since' columns to the
pg_stat_statements view and pg_stat_statements() function. The new min/max
reset mode for the pg_stat_stetments_reset() function is controlled by the
parameter minmax_only.
'stat_since' column is populated with the current timestamp when a new
statement is added to the pg_stat_statements hashtable. It provides clean
information about statistics collection time intervals for each statement.
Besides it can be used by sampling solutions to detect situations when a
statement was evicted and stored again between samples.
Such a sampling solution could derive any pg_stat_statements statistic values
for an interval between two samples with the exception of all min/max
statistics. To address this issue this patch adds the ability to reset
min/max statistics independently of the statement reset using the new
minmax_only parameter of the pg_stat_statements_reset(userid oid, dbid oid,
queryid bigint, minmax_only boolean) function. The timestamp of such reset
is stored in the minmax_stats_since field for each statement.
pg_stat_statements_reset() function now returns the timestamp of a reset as the
result.
Discussion: https://postgr.es/m/flat/
72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
Alexander Korotkov [Mon, 27 Nov 2023 00:50:59 +0000 (02:50 +0200)]
Add NOT NULL checking of pg_stat_statements_reset() in tests
This is preliminary patch. It adds NOT NULL checking for the result of
pg_stat_statements_reset() function. It is needed for upcoming patch
"Track statement entry timestamp" that will change the result type of
this function to the timestamp of a reset performed.
Discussion: https://postgr.es/m/flat/
72e80e7b160a6eb189df9ef6f068cce3765d37f8.camel%40moonset.ru
Author: Andrei Zubkov
Reviewed-by: Julien Rouhaud, Hayato Kuroda, Yuki Seino, Chengxi Sun
Reviewed-by: Anton Melnikov, Darren Rush, Michael Paquier, Sergei Kornilov
Reviewed-by: Alena Rybakina, Andrei Lepikhov
Michael Paquier [Mon, 27 Nov 2023 00:40:44 +0000 (09:40 +0900)]
Fix race condition with BIO methods initialization in libpq with threads
The libpq code in charge of creating per-connection SSL objects was
prone to a race condition when loading the custom BIO methods needed by
my_SSL_set_fd(). As BIO methods are stored as a static variable, the
initialization of a connection could fail because it could be possible
to have one thread refer to my_bio_methods while it is being manipulated
by a second concurrent thread.
This error has been introduced by
8bb14cdd33de, that has removed
ssl_config_mutex around the call of my_SSL_set_fd(), that itself sets
the custom BIO methods used in libpq. Like previously, the BIO method
initialization is now protected by the existing ssl_config_mutex, itself
initialized earlier for WIN32.
While on it, document that my_bio_methods is protected by
ssl_config_mutex, as this can be easy to miss.
Reported-by: Willi Mann
Author: Willi Mann, Michael Paquier
Discussion: https://postgr.es/m/
e77abc4c-4d03-4058-a9d7-
ef0035657e04@celonis.com
Backpatch-through: 12
Alexander Korotkov [Sun, 26 Nov 2023 23:30:39 +0000 (01:30 +0200)]
Display length and bounds histograms in pg_stats
Values corresponding to STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM and
STATISTIC_KIND_BOUNDS_HISTOGRAM were not exposed to pg_stats when these
slot kinds were introduced in
918eee0c49.
This commit adds the missing fields to pg_stats.
Catversion is bumped.
Discussion: https://postgr.es/m/flat/
b67d8b57-9357-7e82-a2e7-
f6ce6eaeec67@postgrespro.ru
Author: Egor Rogov, Soumyadeep Chakraborty
Reviewed-by: Tomas Vondra, Justin Pryzby, Jian He
Alexander Korotkov [Sun, 26 Nov 2023 23:29:56 +0000 (01:29 +0200)]
Update comments for pg_statistic catalog table
Make a reminder that pg_stats view needs to be modified whenever a new slot
kind is added. To prevent situations like
918eee0c49 when pg_stats was
forgotten to be updated.
Also, revise the comment that only non-null, non-empty rows are considered
for the range length histogram.
Discussion: https://postgr.es/m/flat/
b67d8b57-9357-7e82-a2e7-
f6ce6eaeec67@postgrespro.ru
Author: Egor Rogov, Soumyadeep Chakraborty
Reviewed-by: Tomas Vondra, Justin Pryzby, Jian He
Tom Lane [Sun, 26 Nov 2023 21:40:22 +0000 (16:40 -0500)]
Doc: list AT TIME ZONE and COLLATE in operator precedence table.
These constructs have precedence, but we forgot to list them.
In HEAD, mention AT LOCAL as well as AT TIME ZONE.
Per gripe from Shay Rojansky.
Discussion: https://postgr.es/m/CADT4RqBPdbsZW7HS1jJP319TMRHs1hzUiP=iRJYR6UqgHCrgNQ@mail.gmail.com
Tomas Vondra [Sun, 26 Nov 2023 20:35:32 +0000 (21:35 +0100)]
Fix brin.c indentation issues introduced by
c1ec02be1d
Per buildfarm member koel.
Peter Eisentraut [Sat, 25 Nov 2023 21:18:53 +0000 (22:18 +0100)]
Use fipshash in brin_multi test
This fixes some md5() calls that snuck in in
0457109344 after we had
removed them all in
208bf364a9.
Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/
a35eaf0f-b19c-7797-e296-
7b7e2adc473e@eisentraut.org
Tomas Vondra [Sat, 25 Nov 2023 19:27:04 +0000 (20:27 +0100)]
Reuse BrinDesc and BrinRevmap in brininsert
The brininsert code used to initialize (and destroy) BrinDesc and
BrinRevmap for each tuple, which is not free. This patch initializes
these structures only once, and reuses them for all inserts in the same
command. The data is passed through indexInfo->ii_AmCache.
This also introduces an optional AM callback "aminsertcleanup" that
allows performing custom cleanup in case simply pfree-ing ii_AmCache is
not sufficient (which is the case when the cache contains TupleDesc,
Buffers, and so on).
Author: Soumyadeep Chakraborty
Reviewed-by: Alvaro Herrera, Matthias van de Meent, Tomas Vondra
Discussion: https://postgr.es/m/CAE-ML%2B9r2%3DaO1wwji1sBN9gvPz2xRAtFUGfnffpd0ZqyuzjamA%40mail.gmail.com
Bruce Momjian [Sat, 25 Nov 2023 16:04:46 +0000 (11:04 -0500)]
C comment: add header to pg_test_fsync.c
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/CAB7nPqT1c9WrUw4+eSGF_-ru7ERBOC50a4r3tS1s-yT4OaYsLg@mail.gmail.com
Author: Michael Paquier
Backpatch-through: master
Bruce Momjian [Sat, 25 Nov 2023 15:48:18 +0000 (10:48 -0500)]
C comment: clarify that WAL files can be _recycled_ or removed
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/CAB7nPqSDdF0heotQU3gsepgqx+9c+6KjLd3R6aNYH7KKfDd2ig@mail.gmail.com
Author: Michael Paquier
Backpatch-through: master
Bruce Momjian [Sat, 25 Nov 2023 03:36:23 +0000 (22:36 -0500)]
Use SECS_PER_HOUR macro in tzparser.c, instead of constants
Reported-by: CharSyam
Discussion: https://postgr.es/m/CAMrLSE5j_aWfoBDMrSvk14oBKSy+-2cjzNNH_FciirA7Kwo9TA@mail.gmail.com
Author: CharSyam
Backpatch-through: master
Bruce Momjian [Sat, 25 Nov 2023 03:02:07 +0000 (22:02 -0500)]
doc: gin_page_opaque_info() must be a _compressed_ GIN page
Reported-by: Jeff Janes
Discussion: https://postgr.es/m/CAMkU=1xvzQxTAiYNM2PWJ6snMTPh3u3Ammbwss7mvAShS2Ohww@mail.gmail.com
Author: Jeff Janes
Backpatch-through: master
Bruce Momjian [Sat, 25 Nov 2023 01:07:14 +0000 (20:07 -0500)]
doc: improve ALTER TABLE "offical constraint" wording
Reported-by: Josh Kupershmidt
Discussion: https://postgr.es/m/CAK3UJRF=KY_nx_TRQq+t6jOrtS2rry79ktkzPiMDhFx_K=dZAg@mail.gmail.com
Author: Josh Kupershmidt
Backpatch-through: master
Tom Lane [Sat, 25 Nov 2023 01:02:53 +0000 (20:02 -0500)]
Doc: un-break PDF build.
Oversight in
5c4c7efad: gotta adjust the cell height for removal of
an entry. Per buildfarm.
Tom Lane [Sat, 25 Nov 2023 00:51:03 +0000 (19:51 -0500)]
gitignore generated file targets-meson.sgml.
Oversight in
07cb29737.
Bruce Momjian [Sat, 25 Nov 2023 00:44:09 +0000 (19:44 -0500)]
modify segno. for pg_walfile_name() and pg_walfile_name_offset()
Previously these functions returned the previous segment number if the
LSN was on a segment boundary. We now always return the current segment
number for an LSN.
Docs updated to reflect this change. Regression tests added, author
Andres Freund.
Also mentioned in thread https://postgr.es/m/flat/
20220204225057.GA1535307%40nathanxps13#
d964275c9540d8395e138efc0a75f7e8
BACKWARD INCOMPATIBILITY
Reported-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/
20190726.172120.
101752680.horikyota.ntt@gmail.com
Co-authored-by: Kyotaro Horiguchi
Backpatch-through: master
Bruce Momjian [Fri, 24 Nov 2023 23:01:56 +0000 (18:01 -0500)]
doc: remove documentation for deprecated @@@ operator
Reported-by: Kyotaro HORIGUCHI
Discussion: https://postgr.es/m/CAF4Au4wmUsZRVhR+ySpvabRfB_1D1fnrPY9TRAKO2DEbi4Cpgg@mail.gmail.com
Co-authored-by: Oleg Bartunov
Backpatch-through: master
Bruce Momjian [Fri, 24 Nov 2023 22:56:28 +0000 (17:56 -0500)]
doc: mention vacuum's removal of commit timestamp information
Reported-by: Kyotaro HORIGUCHI
Discussion: https://postgr.es/m/
20180622.172132.
230342845.horiguchi.kyotaro@lab.ntt.co.jp
Co-authored-by: Kyotaro HORIGUCHI
Backpatch-through: 16
Thomas Munro [Fri, 24 Nov 2023 21:39:32 +0000 (10:39 +1300)]
Fix whitespace.
Use tabs instead of spaces for new paragraph, like existing paragraphs.
Thomas Munro [Fri, 24 Nov 2023 20:41:33 +0000 (09:41 +1300)]
Improve comments about pqsignal().
Explain where pqsignal() came from, what problem it originally solved
without assuming the reader is familiar with historical Unixen, why we
still need it, what it does for us now, and the key differences in
frontend code on Windows.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/CA%2BhUKG%2BRst1h3uo%2BXRgdRVnWHBa4mmj5gFbmCzZr73s-Fh_5JA%40mail.gmail.com
Bruce Momjian [Fri, 24 Nov 2023 19:36:00 +0000 (14:36 -0500)]
doc: add docs for age(xid) and mxid_age(xid)
Reported-by: David Rowley
Discussion: https://postgr.es/m/CAKJS1f_OQpz7rpe-KJmskVxbU06buiXbfonxG3JLB+nGCJ5E=g@mail.gmail.com
Backpatch-through: 16
Tom Lane [Thu, 23 Nov 2023 18:30:18 +0000 (13:30 -0500)]
Fix timing-dependent failure in GSSAPI data transmission.
When using GSSAPI encryption in non-blocking mode, libpq sometimes
failed with "GSSAPI caller failed to retransmit all data needing
to be retried". The cause is that pqPutMsgEnd rounds its transmit
request down to an even multiple of 8K, and sometimes that can lead
to not requesting a write of data that was requested to be written
(but reported as not written) earlier. That can upset pg_GSS_write's
logic for dealing with not-yet-written data, since it's possible
the data in question had already been incorporated into an encrypted
packet that we weren't able to send during the previous call.
We could fix this with a one-or-two-line hack to disable pqPutMsgEnd's
round-down behavior, but that seems like making the caller work around
a behavior that pg_GSS_write shouldn't expose in this way. Instead,
adjust pg_GSS_write to never report a partial write: it either
reports a complete write, or reflects the failure of the lower-level
pqsecure_raw_write call. The requirement still exists for the caller
to present at least as much data as on the previous call, but with
the caller-visible write start point not moving there is no temptation
for it to present less. We lose some ability to reclaim buffer space
early, but I doubt that that will make much difference in practice.
This also gets rid of a rather dubious assumption that "any
interesting failure condition (from pqsecure_raw_write) will recur
on the next try". We've not seen failure reports traceable to that,
but I've never trusted it particularly and am glad to remove it.
Make the same adjustments to the equivalent backend routine
be_gssapi_write(). It is probable that there's no bug on the backend
side, since we don't have a notion of nonblock mode there; but we
should keep the logic the same to ease future maintenance.
Per bug #18210 from Lars Kanis. Back-patch to all supported branches.
Discussion: https://postgr.es/m/18210-
4c6d0b14627f2eb8@postgresql.org
Heikki Linnakangas [Thu, 23 Nov 2023 11:31:36 +0000 (13:31 +0200)]
Use ResourceOwner to track WaitEventSets.
A WaitEventSet holds file descriptors or event handles (on Windows).
If FreeWaitEventSet is not called, those fds or handles are leaked.
Use ResourceOwners to track WaitEventSets, to clean those up
automatically on error.
This was a live bug in async Append nodes, if a FDW's
ForeignAsyncRequest function failed. (In back branches, I will apply a
more localized fix for that based on PG_TRY-PG_FINALLY.)
The added test doesn't check for leaking resources, so it passed even
before this commit. But at least it covers the code path.
In the passing, fix misleading comment on what the 'nevents' argument
to WaitEventSetWait means.
Report by Alexander Lakhin, analysis and suggestion for the fix by
Tom Lane. Fixes bug #17828.
Reviewed-by: Alexander Lakhin, Thomas Munro
Discussion: https://www.postgresql.org/message-id/472235.
1678387869@sss.pgh.pa.us
Bruce Momjian [Thu, 23 Nov 2023 04:41:15 +0000 (23:41 -0500)]
C comment: fix typos with unnecessary apostrophes
Reported-by: Vinayak Pokale
Discussion: https://postgr.es/m/CAEySZvh7gPTOqMhuKOBXEt=qF_1BCvFQB4MAJ4yaTPJHxgX_zw@mail.gmail.com
Author: Vinayak Pokale
Backpatch-through: master
Bruce Momjian [Wed, 22 Nov 2023 21:40:10 +0000 (16:40 -0500)]
doc: remove double-negative in REFRESH MATERIALIZED ... CONCURR
Reported-by: ap@robillo.net
Discussion: https://postgr.es/m/
20170208152743.1411.6073@wrigleys.postgresql.org
Backpatch-through: master
Amit Kapila [Wed, 22 Nov 2023 06:14:14 +0000 (11:44 +0530)]
Fix the initial sync tables with no columns.
The copy command formed for initial sync was using parenthesis for tables
with no columns leading to syntax error. This patch avoids adding
parenthesis for such tables.
Reported-by: Justin G
Author: Vignesh C
Reviewed-by: Peter Smith, Amit Kapila
Backpatch-through: 15
Discussion: http://postgr.es/m/18203-
df37fe354b626670@postgresql.org
Amit Kapila [Wed, 22 Nov 2023 03:09:24 +0000 (08:39 +0530)]
Stop the search once the slot for replication origin is found.
In replorigin_session_setup(), we were needlessly looping for
max_replication_slots even after finding an existing slot for the origin.
This shouldn't hurt us much except for probably large values of
max_replication_slots.
Author: Antonin Houska
Discussion: http://postgr.es/m/2694.
1700471273@antos