59127 Commits

Author SHA1 Message Date
Dean Rasheed
e676bdac1a Fix wrong varnullingrels error for MERGE WHEN NOT MATCHED BY SOURCE.
If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
source relation appears on the outer side of the join. Thus, any Vars
referring to the source in the merge join condition, actions, and
RETURNING list should be marked as nullable by the join, since they
are used in the ModifyTable node above the join. Note that this only
applies to the copy of join condition used in the executor to
distinguish MATCHED from NOT MATCHED BY SOURCE cases. Vars in the
original join condition, inside the join node itself, should not be
marked.

Failure to correctly mark these Vars led to a "wrong varnullingrels"
error in the final stage of query planning, in some circumstances. We
happened to get away without this in all previous tests, since they
all involved a ModifyTable node directly on top of the join node, so
that the top plan targetlist coincided with the output of the join,
and the varnullingrels check was more lax. However, if another plan
node, such as a one-time filter Result node, gets inserted between the
ModifyTable node and the join node, then a stricter check is applied,
which fails.

Per bug #18634 from Alexander Lakhin. Thanks to Tom Lane and Richard
Guo for review and analysis.

Back-patch to v17, where WHEN NOT MATCHED BY SOURCE support was added
to MERGE.

Discussion: https://postgr.es/m/18634-db5299c937877f2b%40postgresql.org
2024-11-13 14:15:08 +05:00
Dean Rasheed
bf26cc945b Fix incorrect non-strict join recheck in MERGE WHEN NOT MATCHED BY SOURCE.
If a MERGE command contains WHEN NOT MATCHED BY SOURCE actions, the
merge join condition is used by the executor to distinguish MATCHED
from NOT MATCHED BY SOURCE cases. However, this qual is executed using
the output from the join subplan node, which nulls the output from the
source relation in the not matched case, and so the result may be
incorrect if the join condition is "non-strict" -- for example,
something like "src.col IS NOT DISTINCT FROM tgt.col".

Fix this by enhancing the join recheck condition with an additional
"src IS NOT NULL" check, so that it does the right thing when
evaluated using the output from the join subplan.

Noted by Tom Lane while investigating bug #18634 from Alexander
Lakhin.

Back-patch to v17, where WHEN NOT MATCHED BY SOURCE support was added
to MERGE.

Discussion: https://postgr.es/m/18634-db5299c937877f2b%40postgresql.org
2024-11-13 14:15:08 +05:00
Tom Lane
4281ba3f0c Parse libpq's "keepalives" option more like other integer options.
Use pqParseIntParam (nee parse_int_param) instead of using strtol
directly.  This allows trailing whitespace, which the previous coding
didn't, and makes the spelling of the error message consistent with
other similar cases.

This seems to be an oversight in commit e7a221797, which introduced
parse_int_param.  That fixed places that were using atoi(), but missed
this place which was randomly using strtol() instead.

Ordinarily I'd consider this minor cleanup not worth back-patching.
However, it seems that ecpg assumes it can add trailing whitespace
to URL parameters, so that use of the keepalives option fails in
that context.  Perhaps that's worth improving as a separate matter.
In the meantime, back-patch this to all supported branches.

Yuto Sasaki (some further cleanup by me)

Discussion: https://postgr.es/m/TY2PR01MB36286A7B97B9A15793335D18C1772@TY2PR01MB3628.jpnprd01.prod.outlook.com
2024-11-13 14:15:08 +05:00
Michael Paquier
5465846054 doc: Clarify name of files generated by pg_waldump --save-fullpage
The fork name is always separated with the block number by an underscore
in the names of the files generated, but the docs stuck them together
without a separator, which was confusing.

Author: Christoph Berg
Discussion: https://postgr.es/m/ZvxtSLiix9eceMRM@msg.df7cb.de
Backpatch-through: 16
2024-11-13 14:15:08 +05:00
Tatsuo Ishii
d9d7ede0e9 Doc: replace unnecessary non-breaking space with ordinal space.
There were unnecessary non-breaking spaces (nbsp, U+00A0, 0xc2a0 in
UTF-8) in the docs.  This commit replaces them with ASCII spaces
(0x20).

config.sgml is backpatched through 17.
ref/drop_extension.sgml is backpatched through 13.

Discussion: https://postgr.es/m/20240930.153404.202479334310259810.ishii%40postgresql.org
Reviewed-by: Yugo Nagata, Daniel Gustafsson
Backpatch-through: 17, 13
2024-11-13 14:15:08 +05:00
Michael Paquier
139b2d549e Fix race condition in COMMIT PREPARED causing orphaned 2PC files
COMMIT PREPARED removes on-disk 2PC files near its end, but the state
checked if a file is on-disk or not gets read from shared memory while
not holding the two-phase state lock.

Because of that, there was a small window where a second backend doing a
PREPARE TRANSACTION could reuse the GlobalTransaction put back into the
2PC free list by the COMMIT PREPARED, overwriting the "ondisk" flag read
afterwards by the COMMIT PREPARED to decide if its on-disk two-phase
state file should be removed, preventing the file deletion.

This commit fixes this issue so as the "ondisk" flag in the
GlobalTransaction is read while holding the two-phase state lock, not
from shared memory after its entry has been added to the free list.

Orphaned two-phase state files flushed to disk after a checkpoint are
discarded at the beginning of recovery.  However, a truncation of
pg_xact/ would make the startup process issue a FATAL when it cannot
read the SLRU page holding the state of the transaction whose 2PC file
was orphaned, which is a necessary step to decide if the 2PC file should
be removed or not.  Removing manually the file would be necessary in
this case.

Issue introduced by effe7d9552dd, so backpatch all the way down.

Mea culpa.

Author: wuchengwen
Discussion: https://postgr.es/m/tencent_A7F059B5136A359625C7B2E4A386B3C3F007@qq.com
Backpatch-through: 12
2024-11-13 14:15:08 +05:00
Tom Lane
b9629211a8 Remove incorrect entries in pg_walsummary's getopt_long call.
For some reason this listed "-f" and "-w" as valid switches, though
the code doesn't implement any such thing nor do the docs mention
them.  The effect of this was that if you tried to use one of these
switches, you'd get an unhelpful error message.

Yusuke Sugie

Discussion: https://postgr.es/m/68e72a2a70f4d84c1c7847b13bcdaef8@oss.nttdata.com
2024-11-13 14:15:08 +05:00
Fujii Masao
4fa2b58c45 reindexdb: Skip reindexing temporary tables and indexes.
Reindexing temp tables or indexes of other sessions is not allowed.
However, reindexdb in parallel mode previously listed them as
the objects to process, leading to failures.

This commit ensures reindexdb in parallel mode skips temporary tables
and indexes by adding a condition based on the relpersistence column
in pg_class to the object listing queries, preventing these issues.

Note that this commit does not affect reindexdb when temporary tables
or indexes are explicitly specified using the -t or -j options;
reindexdb in that case still does not skip them and can cause an error.

Back-patch to v13 where parallel mode was introduced in reindexdb.

Author: Fujii Masao
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/5f37ee56-14fb-44fe-9150-9eb97e10538b@oss.nttdata.com
2024-11-13 14:15:08 +05:00
Noah Misch
9363b329b2 Remove NULL dereference from RenameRelationInternal().
Defect in last week's commit aac2c9b4fde889d13f859c233c2523345e72d32b,
per Coverity.  Reaching this would need catalog corruption.  Back-patch
to v12, like that commit.
2024-11-13 14:15:08 +05:00
Noah Misch
05c4d930e1 Avoid 037_invalid_database.pl hang under debug_discard_caches.
Back-patch to v12 (all supported versions).
2024-11-13 14:15:07 +05:00
Nathan Bossart
3a81d61e06 doc: Note that CREATE MATERIALIZED VIEW restricts search_path.
Since v17, CREATE MATERIALIZED VIEW has set search_path to
"pg_catalog, pg_temp" while running the query.  The docs for the
other commands that restrict search_path mention it, but the page
for CREATE MATERIALIZED VIEW does not.  Fix that.

Oversight in commit 4b74ebf726.

Author: Yugo Nagata
Reviewed-by: Jeff Davis
Discussion: https://postgr.es/m/20240805160502.d2a4975802a832b1e04afb80%40sraoss.co.jp
Backpatch-through: 17
2024-11-13 14:15:07 +05:00
Michael Paquier
350ddc718e Fix incorrect memory access in VACUUM FULL with invalid toast indexes
An invalid toast index is skipped in reindex_relation().  These would be
remnants of a failed REINDEX CONCURRENTLY and they should never been
rebuilt as there can only be one valid toast index at a time.

REINDEX_REL_SUPPRESS_INDEX_USE, used by CLUSTER and VACUUM FULL, needs
to maintain a list of the indexes being processed.  The list of indexes
is retrieved from the relation cache, and includes invalid indexes.  The
code has missed that invalid toast indexes are ignored in
reindex_relation() as this leads to a hard failure in reindex_index(),
and they were left in the reindex pending list, making the list
inconsistent when rechecked.  The incorrect memory access was happening
when scanning pg_class for the refresh of pg_database.datfrozenxid, when
doing a scan of pg_class.

This issue exists since REINDEX CONCURRENTLY exists, where invalid toast
indexes can exist, so backpatch all the way down.

Reported-by: Alexander Lakhin
Author: Tender Wang
Discussion: https://postgr.es/m/18630-9aed99c38830657d@postgresql.org
Backpatch-through: 12
2024-11-13 14:15:07 +05:00
Tom Lane
098fbb52f0 Doc: InitPlans aren't parallel-restricted any more.
Commit e08d74ca1 removed that restriction, but missed updating
the documentation about it.  Noted by Egor Rogov.

Discussion: https://postgr.es/m/cdc8f87b-a378-4e22-6d29-40ae32dd97d1@postgrespro.ru
2024-11-13 14:15:07 +05:00
Zsolt Parragi
1a02832e9c
Merge pull request #17 from dutow/vercheck
PG-1126: Expose Percona API version
2024-11-12 14:08:48 +00:00
Zsolt Parragi
fda7cb2f56
Fixup: Update src/include/utils/percona.h
Co-authored-by: Andrew Pogrebnoi <absourd.noise@gmail.com>
2024-11-12 13:07:06 +00:00
Zsolt Parragi
dc12ac2270
Merge pull request #14 from dutow/smgrcreatefix
Refactor smgr API: mdcreate needs the old relfilelocator
2024-11-12 11:28:25 +00:00
Zsolt Parragi
c79499cf5b PG-1126: Expose Percona API version 2024-11-11 07:48:43 +00:00
Zsolt Parragi
2e538c74b8 Refactor smgr API: mdcreate needs the old relfilelocator
With this change, mdcreate receives the old relfilelocator along
with the new for operations that create a new file for an existing
relation.

This is required for tde_heap in pg_tde.
2024-10-12 22:01:28 +01:00
Zsolt Parragi
3f007cac5d
Merge pull request #12 from dutow/pextfix
Expose percona_ext as a meson variable
2024-10-02 16:51:16 +01:00
Zsolt Parragi
fef64fc19a Updated submodule pointer 2024-10-02 16:50:37 +01:00
Zsolt Parragi
f97400152a
Merge pull request #13 from dutow/ver2
Changing the format of version string
2024-10-01 13:58:50 +01:00
Zsolt Parragi
e6c8113068 Changing the format of version string
psql (PostgreSQL) 17.0 - Percona Server for PostgreSQL 17.0.1
2024-10-01 13:38:02 +01:00
Zsolt Parragi
8d8acecd29 Expose percona_ext as a meson variable
As get_option returns an error for non existent variables, this is better for pg_tde
2024-09-30 18:50:53 +01:00
Zsolt Parragi
4fb6401e7b
Merge pull request #11 from dutow/newrename
Modify version string display.
2024-09-30 18:07:12 +01:00
Zsolt Parragi
8ca2b2b47f Remove pg_tde from the make build 2024-09-30 17:46:14 +01:00
Zsolt Parragi
4124f3e1cd Modify version string display.
The original part of the version is kept as is, and Percona specific
information is added after.

For example, psql displays the following after this commit:

SELECT version();
PostgreSQL 17.0.1 (Percona Server for PostgreSQL) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 6
4-bit

Where the addition is ".1 (Percona Server for PostgreSQL)", with the
".1" being the Percona version number.

Similarly, commands show the same information:

bin/pg_ctl --version
pg_ctl (PostgreSQL) 17.0.1 (Percona Server for PostgreSQL)
2024-09-29 20:30:03 +01:00
Zsolt Parragi
763491857c Build fix: reran autoconf 2024-09-27 11:08:50 +01:00
Zsolt Parragi
4879037b53 Updated submodule pointer 2024-09-25 20:50:54 +01:00
Muhammad Usama
88ba689295 PG-1008: Change product name and version number
Updated product name from PostgreSQL to Percona Server for PostgreSQL
and incremented the version number from 17rc1 to 17rc1.1.
2024-09-25 20:48:10 +01:00
Zsolt Parragi
b55f1d2d16 PERCONA_EXT is now a configuration option, not hardcoded
This way the build scripts are aware of its value, and we can use
it to add tests specifically to tde_heap, or other percona features.
2024-09-25 20:45:09 +01:00
Zsolt Parragi
32270fad42 Basic test for PG17
This commit adds two test runners which build Postgres with make
and meson, and run the basic regression tests.

Tests are executed for every PR, and also every day using the
latest pg_tde code.
2024-09-25 20:45:09 +01:00
Muhammad Usama
530dbed567 PG-847: exclude pg_tde* files from checksum validation 2024-09-25 20:45:09 +01:00
Zsolt Parragi
30c8b7a48b PG-981: Renamed PERCONA_FORK to PERCONA_EXT 2024-09-25 20:45:09 +01:00
Zsolt Parragi
c4db8c8dd4 Added pg_tde to makefile 2024-09-25 20:45:09 +01:00
Zsolt Parragi
07c2236937 Updated pg_tde submodule reference 2024-09-25 20:45:09 +01:00
Zsolt Parragi
2b58593956 Removed fsync_checker extension from patch as we do not want to
include it
2024-09-25 20:45:09 +01:00
Zsolt Parragi
8696ccb1b0 fixing rebase bug 2024-09-25 20:45:09 +01:00
Zsolt Parragi
ce431e03d1 Downloaded smgr patch 2024-09-25 20:45:09 +01:00
Zsolt Parragi
7689301f3f Applied patch 2024-09-25 20:45:09 +01:00
Zsolt Parragi
b5257f83bf added pg_tde to meson build 2024-09-25 20:45:09 +01:00
Zsolt Parragi
86d6dca8cb Added pg_tde as submodule following the smgr branch 2024-09-25 20:45:09 +01:00
Andrew Pogrebnoy
8e1dd620fb Make XLog storage extensible
and allow extensions to override it
For now, it extends on `pread` and `pwrite` from/into segment files.
This is the minimum we need for full XLog encryption with pg_de.
2024-09-25 20:45:09 +01:00
Zsolt Parragi
4a3f56c5f8 Added a Percona specific definition to pg_config, allowing our
extension to see if custom features can be used
2024-09-25 20:45:09 +01:00
Nathan Bossart
4e0864af16 Remove extra whitespace in pg_upgrade status message.
There's no need to add another level of indentation to this status
message.  pg_log() will put it in the right place.

Oversight in commit 347758b120.

Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/ZunW7XHLd2uTts4f%40nathan
Backpatch-through: 17
2024-09-25 11:18:56 -05:00
Michael Paquier
85cb21df67 vacuumdb: Skip temporary tables in query to build list of relations
Running vacuumdb with a non-superuser while another user has created a
temporary table would lead to a mid-flight permission failure,
interrupting the operation.  vacuum_rel() skips temporary relations of
other backends, and it makes no sense for vacuumdb to know about these
relations, so let's switch it to ignore temporary relations entirely.

Adding a qual in the query based on relpersistence simplifies the
generation of its WHERE clause in vacuum_one_database(), per se the
removal of "has_where".

Author: VaibhaveS, Michael Paquier
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/CAM_eQjwfAR=y3G1fGyS1U9FTmc+FyJm9amNfY2QCZBnDDbNPZg@mail.gmail.com
Backpatch-through: 12
2024-09-25 14:44:50 +09:00
Noah Misch
3b7a689e1a For inplace update durability, make heap_update() callers wait.
The previous commit fixed some ways of losing an inplace update.  It
remained possible to lose one when a backend working toward a
heap_update() copied a tuple into memory just before inplace update of
that tuple.  In catalogs eligible for inplace update, use LOCKTAG_TUPLE
to govern admission to the steps of copying an old tuple, modifying it,
and issuing heap_update().  This includes MERGE commands.  To avoid
changing most of the pg_class DDL, don't require LOCKTAG_TUPLE when
holding a relation lock sufficient to exclude inplace updaters.
Back-patch to v12 (all supported versions).  In v13 and v12, "UPDATE
pg_class" or "UPDATE pg_database" can still lose an inplace update.  The
v14+ UPDATE fix needs commit 86dc90056dfdbd9d1b891718d2e5614e3e432f35,
and it wasn't worth reimplementing that fix without such infrastructure.

Reviewed by Nitin Motiani and (in earlier versions) Heikki Linnakangas.

Discussion: https://postgr.es/m/20231027214946.79.nmisch@google.com
2024-09-24 15:25:22 -07:00
Noah Misch
fd27b878c2 Fix data loss at inplace update after heap_update().
As previously-added tests demonstrated, heap_inplace_update() could
instead update an unrelated tuple of the same catalog.  It could lose
the update.  Losing relhasindex=t was a source of index corruption.
Inplace-updating commands like VACUUM will now wait for heap_update()
commands like GRANT TABLE and GRANT DATABASE.  That isn't ideal, but a
long-running GRANT already hurts VACUUM progress more just by keeping an
XID running.  The VACUUM will behave like a DELETE or UPDATE waiting for
the uncommitted change.

For implementation details, start at the systable_inplace_update_begin()
header comment and README.tuplock.  Back-patch to v12 (all supported
versions).  In back branches, retain a deprecated heap_inplace_update(),
for extensions.

Reported by Smolkin Grigory.  Reviewed by Nitin Motiani, (in earlier
versions) Heikki Linnakangas, and (in earlier versions) Alexander
Lakhin.

Discussion: https://postgr.es/m/CAMp+ueZQz3yDk7qg42hk6-9gxniYbp-=bG2mgqecErqR5gGGOA@mail.gmail.com
2024-09-24 15:25:21 -07:00
Noah Misch
f33bf1c7d5 Warn if LOCKTAG_TUPLE is held at commit, under debug_assertions.
The current use always releases this locktag.  A planned use will
continue that intent.  It will involve more areas of code, making unlock
omissions easier.  Warn under debug_assertions, like we do for various
resource leaks.  Back-patch to v12 (all supported versions), the plan
for the commit of the new use.

Reviewed by Heikki Linnakangas.

Discussion: https://postgr.es/m/20240512232923.aa.nmisch@google.com
2024-09-24 15:25:21 -07:00
Tom Lane
923a71584f Fix psql describe commands' handling of ACL columns for old servers.
Commit d1379ebf4 carelessly broke printACLColumn for pre-9.4 servers,
by using the cardinality() function which we introduced in 9.4.
We expect psql's describe-related commands to work back to 9.2, so
this is bad.  Use the longstanding array_length() function instead.

Per report from Christoph Berg.  Back-patch to v17.

Discussion: https://postgr.es/m/ZvLXYglRS6hMMhtr@msg.df7cb.de
2024-09-24 17:21:38 -04:00
Tom Lane
d7ec59a63d Stamp 17.0. REL_17_0 2024-09-23 16:02:53 -04:00