Michael Paquier [Thu, 13 Jan 2022 00:43:36 +0000 (09:43 +0900)]
Fix incorrect comments in hmac.c and hmac_openssl.c
Both files referred to pg_hmac_ctx->data, which, I guess, comes from the
early versions of the patch that has resulted in commit
e6bdfd9.
Author: Sergey Shinderuk
Discussion: https://postgr.es/m/
8cbb56dd-63d6-a581-7a65-
25a97ac4be03@postgrespro.ru
Backpatch-through: 14
Peter Geoghegan [Wed, 12 Jan 2022 23:41:04 +0000 (15:41 -0800)]
Fix memory leak in indexUnchanged hint mechanism.
Commit
9dc718bd added a "logically unchanged by UPDATE" hinting
mechanism, which is currently used within nbtree indexes only (see
commit
d168b666). This mechanism determined whether or not the incoming
item is a logically unchanged duplicate (a duplicate needed only for
MVCC versioning purposes) once per row updated per non-HOT update. This
approach led to memory leaks which were noticeable with an UPDATE
statement that updated sufficiently many rows, at least on tables that
happen to have an expression index.
On HEAD, fix the issue by adding a cache to the executor's per-index
IndexInfo struct.
Take a different approach on Postgres 14 to avoid an ABI break: simply
pass down the hint to all indexes unconditionally with non-HOT UPDATEs.
This is deemed acceptable because the hint is currently interpreted
within btinsert() as "perform a bottom-up index deletion pass if and
when the only alternative is splitting the leaf page -- prefer to delete
any LP_DEAD-set items first". nbtree must always treat the hint as a
noisy signal about what might work, as a strategy of last resort, with
costs imposed on non-HOT updaters. (The same thing might not be true
within another index AM that applies the hint, which is why the original
behavior is preserved on HEAD.)
Author: Peter Geoghegan <pg@bowt.ie>
Reported-By: Klaudie Willis <Klaudie.Willis@protonmail.com>
Diagnosed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/261065.
1639497535@sss.pgh.pa.us
Backpatch: 14-, where the hinting mechanism was added.
Peter Geoghegan [Wed, 12 Jan 2022 22:13:35 +0000 (14:13 -0800)]
vacuumlazy.c: fix "garbage tuples" reference.
Another minor oversight in commit
4f8d9d12.
Tomas Vondra [Wed, 12 Jan 2022 18:59:30 +0000 (19:59 +0100)]
Consider fractional paths in generate_orderedappend_paths
When building append paths, we've been looking only at startup and total
costs for the paths. When building fractional paths that may eliminate
the cheapest one, because it may be dominated by two separate paths (one
for startup, one for total cost).
This extends generate_orderedappend_paths() to also consider which paths
have lowest fractional cost. Currently we only consider paths matching
pathkeys - in the future this may be improved by also considering paths
that are only partially sorted, with an incremental sort on top.
Original report of an issue by Arne Roland, patch by me (based on a
suggestion by Tom Lane).
Reviewed-by: Arne Roland, Zhihong Yu
Discussion: https://postgr.es/m/
e8f9ec90-546d-e948-acce-
0525f3e92773%40enterprisedb.com
Discussion: https://postgr.es/m/
1581042da8044e71ada2d6e3a51bf7bb%40index.de
Alvaro Herrera [Wed, 12 Jan 2022 19:23:42 +0000 (16:23 -0300)]
Add index on pg_publication_rel.prpubid
This should have been added for the benefit of GetPublicationRelations;
let's add it now.
I couldn't measure a performance difference in the TAP tests, but that
may be because the tests use very few publications.
Discussion: https://postgr.es/m/
202201120041.p24wvsfcsope@alvherre.pgsql
Tom Lane [Wed, 12 Jan 2022 19:23:13 +0000 (14:23 -0500)]
Include permissive/enforcing state in sepgsql log messages.
SELinux itself does this (at least in modern releases), and it
seems like a good idea to reduce confusion.
Dave Page
Discussion: https://postgr.es/m/CA+OCxowsQoLEYc=jN7OtNvOdX0Jg5L7nMYt++=k0X78HGq-sXg@mail.gmail.com
Peter Eisentraut [Wed, 12 Jan 2022 09:39:57 +0000 (10:39 +0100)]
ecpg: Catch zero-length Unicode identifiers correctly
The previous code to detect a zero-length identifier when using
Unicode identifiers such as
exec sql select u&"";
did not work. This fixes that.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/
82fafa79-331c-9d65-e51b-
8b5d1b2383fc%40enterprisedb.com
Michael Paquier [Wed, 12 Jan 2022 06:03:48 +0000 (15:03 +0900)]
Move any code specific to log_destination=csvlog to its own file
The recent refactoring done in
ac7c807 makes this move possible and
simple, as this just moves some code around. This reduces the size of
elog.c by 7%.
Author: Michael Paquier, Sehrope Sarkuni
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
simply moves the routines related to csvlog into their own file
Michael Paquier [Wed, 12 Jan 2022 05:16:59 +0000 (14:16 +0900)]
Refactor set of routines specific to elog.c
This refactors the following routines and facilities coming from
elog.c, to ease their use across multiple log destinations:
- Start timestamp, including its reset, to store when a process has been
started.
- The log timestamp, associated to an entry (the same timestamp is used
when logging across multiple destinations).
- Routine deciding if a query can be logged or not.
- The backend type names, depending on the process that logs any
information (postmaster, bgworker name or just GetBackendTypeDesc() with
a regular backend).
- Write of logs using the logging piped protocol, with the log collector
enabled.
- Error severity converted to a string.
These refactored routines will be used for some follow-up changes
to move all the csvlog logic into its own file and to potentially add
JSON as log destination, reducing the overall size of elog.c as the end
result.
Author: Michael Paquier, Sehrope Sarkuni
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
Michael Paquier [Wed, 12 Jan 2022 03:39:36 +0000 (12:39 +0900)]
Fix comment related to pg_cryptohash_error()
One of the comments introduced in
b69aba7 was worded a bit weirdly, so
improve it.
Reported-by: Sergey Shinderuk
Discussion: https://postgr.es/m/
71b9a5d2-a3bf-83bc-a243-
93dcf0bcfb3b@postgrespro.ru
Backpatch-through: 14
Thomas Munro [Tue, 11 Jan 2022 21:11:50 +0000 (10:11 +1300)]
Add missing include guard to win32ntdll.h.
Oversight in commit
e2f0f8ed. Also add this file to the exclusion lists
in headerscheck and cpluscpluscheck, because Unix systems don't have a
header it includes.
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/
2760528.
1641929756%40sss.pgh.pa.us
Tom Lane [Tue, 11 Jan 2022 19:22:00 +0000 (14:22 -0500)]
Improve error message for missing extension.
If we get ENOENT while trying to read an extension control file,
report that as a missing extension (with a HINT to install it)
rather than as a filesystem access problem. The message wording
was extensively bikeshedded in hopes of pointing people to the
idea that they need to do a software installation before they
can install the extension into the current database.
Nathan Bossart, with review/wording suggestions from Daniel
Gustafsson, Chapman Flack, and myself
Discussion: https://postgr.es/m/
3950D56A-4E47-48E7-BF9B-
F5F22E268BE7@amazon.com
Tom Lane [Tue, 11 Jan 2022 18:46:12 +0000 (13:46 -0500)]
Clean up messy API for src/port/thread.c.
The point of this patch is to reduce inclusion spam by not needing
to #include <netdb.h> or <pwd.h> in port.h (which is read by every
compile in our tree). To do that, we must remove port.h's
declarations of pqGetpwuid and pqGethostbyname.
pqGethostbyname is only used, and is only ever likely to be used,
in src/port/getaddrinfo.c --- which isn't even built on most
platforms, making pqGethostbyname dead code for most people.
Hence, deal with that by just moving it into getaddrinfo.c.
To clean up pqGetpwuid, invent a couple of simple wrapper
functions with less-messy APIs. This allows removing some
duplicate error-handling code, too.
In passing, remove thread.c from the MSVC build, since it
contains nothing we use on Windows.
Noted while working on
376ce3e40.
Discussion: https://postgr.es/m/
1634252654444.90107@mit.edu
John Naylor [Tue, 7 Dec 2021 22:31:47 +0000 (22:31 +0000)]
Improve warning message in pg_signal_backend()
Previously, invoking pg_terminate_backend() or pg_cancel_backend()
with the postmaster PID produced a "PID XXXX is not a PostgresSQL
server process" warning, which does not make sense. Change to
"backend process" to make the message more exact.
Nathan Bossart, based on an idea from Bharath Rupireddy with
input from Tom Lane and Euler Taveira
Discussion: https://www.postgresql.org/message-id/flat/CALj2ACW7Rr-R7mBcBQiXWPp=JV5chajjTdudLiF5YcpW-BmHhg@mail.gmail.com
Tom Lane [Tue, 11 Jan 2022 17:03:06 +0000 (12:03 -0500)]
Clean up error message reported after \password encryption failure.
Experimenting with FIPS mode enabled, I saw
regression=# \password joe
Enter new password for user "joe":
Enter it again:
could not encrypt password: disabled for FIPS
out of memory
because PQencryptPasswordConn was still of the opinion that "out of
memory" is always appropriate to print.
Minor oversight in
b69aba745. Like that one, back-patch to v14.
Fujii Masao [Tue, 11 Jan 2022 14:19:59 +0000 (23:19 +0900)]
Enhance pg_log_backend_memory_contexts() for auxiliary processes.
Previously pg_log_backend_memory_contexts() could request to
log the memory contexts of backends, but not of auxiliary processes
such as checkpointer. This commit enhances the function so that
it can also send the request to auxiliary processes. It's useful to
look at the memory contexts of those processes for debugging purpose
and better understanding of the memory usage pattern of them.
Note that pg_log_backend_memory_contexts() cannot send the request
to logger or statistics collector. Because this logging request
mechanism is based on shared memory but those processes aren't
connected to that.
Author: Bharath Rupireddy
Reviewed-by: Vignesh C, Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACU1nBzpacOK2q=a65S_4+Oaz_rLTsU1Ri0gf7YUmnmhfQ@mail.gmail.com
Amit Kapila [Tue, 11 Jan 2022 06:31:48 +0000 (12:01 +0530)]
Update docs of logical replication for commit
8d74fc96db.
After commit
8d74fc96db, the details of logical replication conflicts can
be found in pg_stat_subscription_workers view.
Author: Masahiko Sawada
Reviewed-by: Amit Kapila
Discussion: https://postgr.es/m/CAD21AoC+zm5tGN8x88AJZYcX0g_eiEuu5XdrksNmSeR3Xzwjfg@mail.gmail.com
Amit Kapila [Tue, 11 Jan 2022 05:20:18 +0000 (10:50 +0530)]
Fix typo in rewriteheap.c.
Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACW7SvfFW8r2uKH6oQm1kNpt8aQMG61kSBPK0S2PHhFbMw@mail.gmail.com
Michael Paquier [Tue, 11 Jan 2022 00:55:16 +0000 (09:55 +0900)]
Improve error handling of cryptohash computations
The existing cryptohash facility was causing problems in some code paths
related to MD5 (frontend and backend) that relied on the fact that the
only type of error that could happen would be an OOM, as the MD5
implementation used in PostgreSQL ~13 (the in-core implementation is
used when compiling with or without OpenSSL in those older versions),
could fail only under this circumstance.
The new cryptohash facilities can fail for reasons other than OOMs, like
attempting MD5 when FIPS is enabled (upstream OpenSSL allows that up to
1.0.2, Fedora and Photon patch OpenSSL 1.1.1 to allow that), so this
would cause incorrect reports to show up.
This commit extends the cryptohash APIs so as callers of those routines
can fetch more context when an error happens, by using a new routine
called pg_cryptohash_error(). The error states are stored within each
implementation's internal context data, so as it is possible to extend
the logic depending on what's suited for an implementation. The default
implementation requires few error states, but OpenSSL could report
various issues depending on its internal state so more is needed in
cryptohash_openssl.c, and the code is shaped so as we are always able to
grab the necessary information.
The core code is changed to adapt to the new error routine, painting
more "const" across the call stack where the static errors are stored,
particularly in authentication code paths on variables that provide
log details. This way, any future changes would warn if attempting to
free these strings. The MD5 authentication code was also a bit blurry
about the handling of "logdetail" (LOG sent to the postmaster), so
improve the comments related that, while on it.
The origin of the problem is
87ae969, that introduced the centralized
cryptohash facility. Extra changes are done for pgcrypto in v14 for the
non-OpenSSL code path to cope with the improvements done by this
commit.
Reported-by: Michael Mühlbeyer
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/
89B7F072-5BBE-4C92-903E-
D83E865D9367@trivadis.com
Backpatch-through: 14
Tom Lane [Mon, 10 Jan 2022 16:46:16 +0000 (11:46 -0500)]
Doc: fix bogus example about ambiguous timestamps.
I had a brain fade in commit
d32899157, and used 2:30AM as the
example timestamp for both spring-forward and fall-back cases.
But it's not actually ambiguous at all in the fall-back case,
because that transition is from 2AM to 1AM under USA rules.
Fix the example to use 1:30AM, which *is* ambiguous.
Noted while answering a question from Aleksander Alekseev.
Back-patch to all supported branches.
Discussion: https://postgr.es/m/
2191355.
1641828552@sss.pgh.pa.us
Andrew Dunstan [Mon, 10 Jan 2022 15:08:44 +0000 (10:08 -0500)]
Avoid warning about uninitialized value in MSVC python3 tests
Juan José Santamaría Flecha
Backpatch to all live branches
Thomas Munro [Mon, 10 Jan 2022 10:54:11 +0000 (23:54 +1300)]
Make EXEC_BACKEND more convenient on Linux and FreeBSD.
Try to disable ASLR when building in EXEC_BACKEND mode, to avoid random
memory mapping failures while testing. For developer use only, no
effect on regular builds.
Suggested-by: Andres Freund <andres@anarazel.de>
Tested-by: Bossart, Nathan <bossartn@amazon.com>
Discussion: https://postgr.es/m/
20210806032944.m4tz7j2w47mant26%40alap3.anarazel.de
Peter Eisentraut [Mon, 10 Jan 2022 08:37:43 +0000 (09:37 +0100)]
Rename functions to avoid future conflicts
Rename range_serialize/range_deserialize to
brin_range_serialize/brin_range_deserialize, since there are already
public range_serialize/range_deserialize in rangetypes.h.
Author: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://www.postgresql.org/message-id/CA+renyX0ipvY6A_jUOHeB1q9mL4bEYfAZ5FBB7G7jUo5bykjrA@mail.gmail.com
Tom Lane [Mon, 10 Jan 2022 00:19:02 +0000 (19:19 -0500)]
Prefer $HOME when looking up the current user's home directory.
When we need to identify the home directory on non-Windows, first
consult getenv("HOME"). If that's empty or unset, fall back
on our previous method of checking the <pwd.h> database.
Preferring $HOME allows the user to intentionally point at some
other directory, and it seems to be in line with the behavior of
most other utilities. However, we shouldn't rely on it completely,
as $HOME is likely to be unset when running as a daemon.
Anders Kaseorg
Discussion: https://postgr.es/m/
1634252654444.90107@mit.edu
Tom Lane [Sun, 9 Jan 2022 17:43:09 +0000 (12:43 -0500)]
Make pg_get_expr() more bulletproof.
Since this function is defined to accept pg_node_tree values, it could
get applied to any nodetree that can appear in a cataloged pg_node_tree
column. Some such cases can't be supported --- for example, its API
doesn't allow providing referents for more than one relation --- but
we should try to throw a user-facing error rather than an internal
error when encountering such a case.
In support of this, extend expression_tree_walker/mutator to be sure
they'll work on any such node tree (which basically means adding
support for relpartbound node types). That allows us to run pull_varnos
and check for the case of multiple relations before we start processing
the tree. The alternative of changing the low-level error thrown for an
out-of-range varno isn't appealing, because that could mask actual bugs
in other usages of ruleutils.
Per report from Justin Pryzby. This is basically cosmetic, so no
back-patch.
Discussion: https://postgr.es/m/
20211219205422.GT17618@telsasoft.com
Jeff Davis [Sat, 8 Jan 2022 21:40:23 +0000 (13:40 -0800)]
More cleanup of
a2ab9c06ea.
Require SELECT privileges when performing UPDATE or DELETE, to be
consistent with the way a normal UPDATE or DELETE command works.
Simplify subscription test it so that it runs faster. Also, wait for
initial table sync to complete to avoid intermittent failures.
Minor doc fixup.
Discussion: https://postgr.es/m/CAA4eK1L3-qAtLO4sNGaNhzcyRi_Ufmh2YPPnUjkROBK0tN%3Dx%3Dg%40mail.gmail.com
Discussion: https://postgr.es/m/
1514479.
1641664638%40sss.pgh.pa.us
Discussion: https://postgr.es/m/Ydkfj5IsZg7mQR0g@paquier.xyz
Tom Lane [Sat, 8 Jan 2022 19:54:39 +0000 (14:54 -0500)]
Fix results of index-only scans on btree_gist char(N) indexes.
If contrib/btree_gist is used to make a GIST index on a char(N)
(bpchar) column, and that column is retrieved via an index-only
scan, what came out had all trailing spaces removed. Since
that doesn't happen in any other kind of table scan, this is
clearly a bug. The cause is that gbt_bpchar_compress() strips
trailing spaces (using rtrim1) before a new index entry is made.
That was probably a good idea when this code was first written,
but since we invented index-only scans, it's not so good.
One answer could be to mark this opclass as incapable of index-only
scans. But to do so, we'd need an extension module version bump,
followed by manual action by DBAs to install the updated version
of btree_gist. And it's not really a desirable place to end up,
anyway.
Instead, let's fix the code by removing the unwanted space-stripping
action and adjusting the opclass's comparison logic to ignore
trailing spaces as bpchar normally does. This will not hinder
cases that work today, since index searches with this logic will
act the same whether trailing spaces are stored or not. It will
not by itself fix the problem of getting space-stripped results
from index-only scans, of course. Users who care about that can
REINDEX affected indexes after installing this update, to immediately
replace all improperly-truncated index entries. Otherwise, it can
be expected that the index's behavior will change incrementally as
old entries are replaced by new ones.
Per report from Alexander Lakhin. Back-patch to all supported branches.
Discussion: https://postgr.es/m/
696c995b-b37f-5526-f45d-
04abe713179f@gmail.com
Jeff Davis [Sat, 8 Jan 2022 17:17:02 +0000 (09:17 -0800)]
Fix pgperlcritic complaint, per buildfarm.
Author: Michael Paquier
Discussion: https://postgr.es/m/YdlYfS/l%2BPQA0ehs%40paquier.xyz
Michael Paquier [Sat, 8 Jan 2022 07:44:45 +0000 (16:44 +0900)]
Fix issues with describe queries of extended statistics in psql
This addresses some problems in the describe queries used for extended
statistics:
- Two schema qualifications for the text type were missing for \dX.
- The list of extended statistics listed for a table through \d was
ordered based on the object OIDs, but it is more consistent with the
other commands to order by namespace and then by object name.
- A couple of aliases were not used in \d. These are removed.
This is similar to commits
1f092a3 and
07f8a9e.
Author: Justin Pryzby
Discussion: https://postgr.es/m/
20220107022235.GA14051@telsasoft.com
Backpatch-through: 14
Jeff Davis [Sat, 8 Jan 2022 01:38:20 +0000 (17:38 -0800)]
Respect permissions within logical replication.
Prevent logical replication workers from performing insert, update,
delete, truncate, or copy commands on tables unless the subscription
owner has permission to do so.
Prevent subscription owners from circumventing row-level security by
forbidding replication into tables with row-level security policies
which the subscription owner is subject to, without regard to whether
the policy would ordinarily allow the INSERT, UPDATE, DELETE or
TRUNCATE which is being replicated. This seems sufficient for now, as
superusers, roles with bypassrls, and target table owners should still
be able to replicate despite RLS policies. We can revisit the
question of applying row-level security policies on a per-row basis if
this restriction proves too severe in practice.
Author: Mark Dilger
Reviewed-by: Jeff Davis, Andrew Dunstan, Ronan Dunklau
Discussion: https://postgr.es/m/
9DFC88D3-1300-4DE8-ACBC-
4CEF84399A53%40enterprisedb.com
Michael Paquier [Sat, 8 Jan 2022 00:12:21 +0000 (09:12 +0900)]
Fix thinko coming from
000f3adf
pg_basebackup.c relies on the compression level to not be 0 to decide if
compression should be used, but
000f3adf missed the fact that the
default compression (Z_DEFAULT_COMPRESSION) is -1, which would be used
if specifying --gzip without --compress.
While on it, add some coverage for --gzip, as this is rather easy to
miss.
Reported-by: Christoph Berg
Discussion: https://postgr.es/m/YdhRDMLjabtXOnhY@msg.df7cb.de
Bruce Momjian [Sat, 8 Jan 2022 00:04:57 +0000 (19:04 -0500)]
Update copyright for 2022
Backpatch-through: 10
Andrew Dunstan [Fri, 7 Jan 2022 21:07:45 +0000 (16:07 -0500)]
Allow MSVC .bat wrappers to be called from anywhere
Instead of using a hardcoded or default path to the perl file the .bat
file is a wrapper for, we use a path that means the file is found in
the same directory as the .bat file.
Patch by Anton Voloshin, slightly tweaked by me.
Backpatch to all live branches
Discussion: https://postgr.es/m/
2b7a674b-5fb0-d264-75ef-
ecc7a31e54f8@postgrespro.ru
Andrew Dunstan [Fri, 7 Jan 2022 20:48:53 +0000 (15:48 -0500)]
Skip install/test of pgcrypto on MSVC when not built with openssl
Commit
db7d1a7b05 missed a couple of places that needed adjustment now
we are not building pgcrypto when openssl is not configured, causing
contrib installcheck to fail in such a case.
Michael Paquier [Fri, 7 Jan 2022 07:05:31 +0000 (16:05 +0900)]
Fix comment in fe-connect.c about PQping and pg_ctl
Since
f13ea95f, pg_ctl does not use PQping(), but one comment did not
get the call.
Author: Euler Taveira
Discussion: https://postgr.es/m/
4b1deb4a-2771-416d-9710-
ccd2fa66f058@www.fastmail.com
Fujii Masao [Fri, 7 Jan 2022 06:31:56 +0000 (15:31 +0900)]
postgres_fdw: Add regression test for postgres_fdw.application_name GUC.
Commit
449ab63505 added postgres_fdw.application_name GUC that specifies
a value for application_name configuration parameter used when postgres_fdw
establishes a connection to a foreign server. Also commit
6e0cb3dec1
allowed it to include escape sequences. Both commits added the regression
tests for the GUC, but those tests were reverted by commits
98dbef90eb and
5e64ad3697 because they were unstable and caused some buildfarm members
to report the failure.
This is the third try to add the regression test for
postgres_fdw.application_name GUC.
One of issues to make the test unstable was to have used
postgres_fdw_disconnect_all() to close the existing remote connections.
The test expected that the remote connection and its corresponding backend
at the remote server disappeared just after postgres_fdw_disconnect_all()
was executed, but it could take a bit time for them to disappear.
To make sure that they exit, this commit makes the test use
pg_terminate_backend() with the timeout at the remote server, instead.
If the timeout is set to greater than zero, this function waits until
they are actually terminated (or until the given time has passed).
Another issue was that the test didn't take into consideration the case
where postgres_fdw.application_name containing some escape sequences was
converted to the string larger than NAMEDATALEN. In this case it was
truncated to less than NAMEDATALEN when it's passed to the remote server,
but the test expected wrongly that full string of application_name was
always viewable. This commit changes the test so that it can handle that case.
Author: Fujii Masao
Reviewed-by: Masahiko Sawada, Hayato Kuroda, Kyotaro Horiguchi
Discussion: https://postgr.es/m/
3220909.
1631054766@sss.pgh.pa.us
Discussion: https://postgr.es/m/
20211224.180006.
2247635208768233073.horikyota.ntt@gmail.com
Discussion: https://postgr.es/m/
e7b61420-a97b-8246-77c4-
a0d48fba5a45@oss.nttdata.com
Michael Paquier [Fri, 7 Jan 2022 05:13:35 +0000 (14:13 +0900)]
Add TAP tests for pg_basebackup with compression
pg_basebackup is able to use gzip to compress the contents of backups
with the tar format, but there were no tests for that. This adds a
minimalistic set of tests to check the contents of such base backups,
including sanity checks on the contents generated with gzip commands.
The tests are skipped if Postgres is compiled --without-zlib, and the
checks based on the gzip command are skipped if nothing can be found,
following the same model as the existing tests for pg_receivewal.
Reviewed-by: Georgios Kokolatos
Discussion: https://postgr.es/m/Yb3GEgWwcu4wZDuA@paquier.xyz
Michael Paquier [Fri, 7 Jan 2022 04:48:59 +0000 (13:48 +0900)]
Refactor tar method of walmethods.c to rely on the compression method
Since
d62bcc8, the directory method of walmethods.c uses the compression
method to determine which code path to take. The tar method, used by
pg_basebackup --format=t, was inconsistent regarding that, as it relied
on the compression level to check if no compression or gzip should be
used. This commit makes the code more consistent as a whole in this
file, making the tar logic use a compression method rather than
assigning COMPRESSION_NONE that would be ignored.
The options of pg_basebackup are planned to be reworked but we are not
sure yet of the shape they should have as this has some dependency with
the integration of the server-side compression for base backups, so this
is left out for the moment. This change has as benefit to make easier
the future integration of new compression methods for the tar method of
walmethods.c, for the client-side compression.
Reviewed-by: Georgios Kokolatos
Discussion: https://postgr.es/m/Yb3GEgWwcu4wZDuA@paquier.xyz
Tom Lane [Thu, 6 Jan 2022 21:46:46 +0000 (16:46 -0500)]
Prevent altering partitioned table's rowtype, if it's used elsewhere.
We disallow altering a column datatype within a regular table,
if the table's rowtype is used as a column type elsewhere,
because we lack code to go around and rewrite the other tables.
This restriction should apply to partitioned tables as well, but it
was not checked because ATRewriteTables and ATPrepAlterColumnType
were not on the same page about who should do it for which relkinds.
Per bug #17351 from Alexander Lakhin. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/17351-
6db1870f3f4f612a@postgresql.org
Tom Lane [Thu, 6 Jan 2022 18:09:05 +0000 (13:09 -0500)]
Extend psql's \lo_list/\dl to be able to print large objects' ACLs.
The ACL is printed when you add + to the command, similarly to
various other psql backslash commands.
Along the way, move the code for this into describe.c,
where it is a better fit (and can share some code).
Pavel Luzanov, reviewed by Georgios Kokolatos
Discussion: https://postgr.es/m/
6d722115-6297-bc53-bb7f-
5f150e765299@postgrespro.ru
Michael Paquier [Thu, 6 Jan 2022 02:41:09 +0000 (11:41 +0900)]
doc: Remove link to JSON support in the SQL specification
The link used in the documentation is dead, and the only options to have
an access to this part of the SQL specification are not free. Like any
other books referred, just remove the link to keep some neutrality but
keep its reference.
Reported-by: Erik Rijkers
Discussion: https://postgr.es/m/
989abd7d-af30-ab52-1201-
bf0b4f33b872@xs4all.nl
Backpatch-through: 12
Tom Lane [Wed, 5 Jan 2022 23:18:44 +0000 (18:18 -0500)]
On second thought, remove regex.linux.utf8 regression test altogether.
The code-coverage report says that this test doesn't increase
coverage by one single line, which I now realize is because
I made src/test/modules/test_regex/sql/test_regex_utf8.sql
to cover all the code that this would. So really it's pointless
and we should just drop it.
Tom Lane [Wed, 5 Jan 2022 22:31:54 +0000 (17:31 -0500)]
Enable routine running of regex.linux.utf8 regression test.
Up to now this has just sat there as a test you could invoke via
EXTRA_TESTS, which of course nobody does. I'm feeling encouraged
because
c2e8bd275 hasn't yet broke anything, so let's try making this
run with a suitable guard condition (similar to collate.linux.utf8).
Alvaro Herrera [Wed, 5 Jan 2022 22:00:13 +0000 (19:00 -0300)]
Create foreign key triggers in partitioned tables too
While user-defined triggers defined on a partitioned table have
a catalog definition for both it and its partitions, internal
triggers used by foreign keys defined on partitioned tables only
have a catalog definition for its partitions. This commit fixes
that so that partitioned tables get the foreign key triggers too,
just like user-defined triggers. Moreover, like user-defined
triggers, partitions' internal triggers will now also have their
tgparentid set appropriately. This is to allow subsequent commit(s)
to make the foreign key related events to be fired in some cases
using the parent table triggers instead of those of partitions'.
This also changes what tgisinternal means in some cases. Currently,
it means either that the trigger is an internal implementation object
of a foreign key constraint, or a "child" trigger on a partition
cloned from the trigger on the parent. This commit changes it to
only mean the former to avoid confusion. As for the latter, it can
be told by tgparentid being nonzero, which is now true both for user-
defined and foreign key's internal triggers.
Author: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Arne Roland <A.Roland@index.de>
Discussion: https://postgr.es/m/CA+HiwqG7LQSK+n8Bki8tWv7piHD=PnZro2y6ysU2-28JS6cfgQ@mail.gmail.com
Tom Lane [Wed, 5 Jan 2022 18:30:07 +0000 (13:30 -0500)]
Enable routine running of citext's UTF8-specific test cases.
These test cases have been commented out since citext was invented,
because at the time we had no nice way to deal with tests that
have restrictions such as requiring UTF8 encoding. But now we do
have a convention for that, ie put them into a separate test file
with an early-exit path. So let's enable these tests to run when
their prerequisites are satisfied.
(We may have to tighten the prerequisites beyond the "encoding = UTF8
and locale != C" checks made here. But let's put it on the buildfarm
and see what blows up.)
Dag Lem
Discussion: https://postgr.es/m/ygezgoacs4e.fsf_-_@sid.nimrod.no
Michael Paquier [Wed, 5 Jan 2022 01:27:07 +0000 (10:27 +0900)]
Reduce relcache access in WAL sender streaming logical changes
get_rel_sync_entry(), which is called each time a change needs to be
logically replicated, is a rather hot code path in the WAL sender
sending logical changes. This code path was doing a relcache access on
relkind and relpartition for each logical change, but we only need to
know this information when building or re-building the cached
information for a relation.
Some measurements prove that this is noticeable in perf profiles,
particularly when attempting to replicate changes from relations that
are not published as these cause less overhead in the WAL sender,
delaying further the replication of changes for relations that are
published.
Issue introduced in
83fd453.
Author: Hou Zhijie
Reviewed-by: Kyotaro Horiguchi, Euler Taveira
Discussion: https://postgr.es/m/OS0PR01MB5716E863AA9E591C1F010F7A947D9@OS0PR01MB5716.jpnprd01.prod.outlook.com
Backpatch-through: 13
Tom Lane [Tue, 4 Jan 2022 21:52:51 +0000 (16:52 -0500)]
Remove redundant initialization of BrinMemTuple.
brin_new_memtuple already did this, so there's no need
for initialize_brin_buildstate to do it again.
Richard Guo, reviewed by Bharath Rupireddy
Discussion: https://postgr.es/m/CAMbWs4-kYYpKNOdiWtsCZ3jbkFFj4nhOVH22JH7dsrMYX=aGjg@mail.gmail.com
Alvaro Herrera [Tue, 4 Jan 2022 16:21:23 +0000 (13:21 -0300)]
Fix silly mistake in Assert
Alvaro Herrera [Tue, 4 Jan 2022 16:01:05 +0000 (13:01 -0300)]
Allow special SKIP LOCKED condition in Assert()
Under concurrency, it is possible for two sessions to be merrily locking
and releasing a tuple and marking it again as HEAP_XMAX_INVALID all the
while a third session attempts to lock it, miserably fails at it, and
then contemplates life, the universe and everything only to eventually
fail an assertion that said bit is not set. Before SKIP LOCKED that was
indeed a reasonable expectation, but alas! commit
df630b0dd5ea falsified
it.
This bug is as old as time itself, and even older, if you think time
begins with the oldest supported branch. Therefore, backpatch to all
supported branches.
Author: Simon Riggs <simon.riggs@enterprisedb.com>
Discussion: https://postgr.es/m/CANbhV-FeEwMnN8yuMyss7if1ZKjOKfjcgqB26n8pqu1e=q0ebg@mail.gmail.com
Peter Eisentraut [Tue, 4 Jan 2022 15:19:48 +0000 (16:19 +0100)]
pg_dump: Refactor dumpDatabase()
Rearrange the version-dependent pieces in the new more modular style.
Tom Lane [Mon, 3 Jan 2022 23:14:01 +0000 (18:14 -0500)]
Tab completion: don't offer valid constraints in VALIDATE CONSTRAINT.
Improve psql so that "ALTER TABLE foo VALIDATE CONSTRAINT <TAB>"
only offers not-convalidated entries. While it's not formally
wrong to offer validated ones, there's not much point either,
and it can save some typing if we incorporate this knowledge.
David Fetter, reviewed by Aleksander Alekseev
Discussion: https://postgr.es/m/
20210427002433.GB17834@fetter.org
Tom Lane [Mon, 3 Jan 2022 21:12:11 +0000 (16:12 -0500)]
Handle mixed returnable and non-returnable columns better in IOS.
We can revert the code changes of commit
b5febc1d1 now, because
commit
9a3ddeb51 installed a real solution for the difficulty
that
b5febc1d1 just dodged, namely that the planner might pick
the wrong one of several index columns nominally containing the
same value. It only matters which one we pick if we pick one
that's not returnable, and that mistake is now foreclosed.
Although both of the aforementioned commits were back-patched,
I don't feel a need to take any risk by back-patching this one.
The cases that it improves are very corner-ish.
Discussion: https://postgr.es/m/
3179992.
1641150853@sss.pgh.pa.us
Tom Lane [Mon, 3 Jan 2022 20:42:27 +0000 (15:42 -0500)]
Fix index-only scan plans, take 2.
Commit
4ace45677 failed to fix the problem fully, because the
same issue of attempting to fetch a non-returnable index column
can occur when rechecking the indexqual after using a lossy index
operator. Moreover, it broke EXPLAIN for such indexquals (which
indicates a gap in our test cases :-().
Revert the code changes of
4ace45677 in favor of adding a new field
to struct IndexOnlyScan, containing a version of the indexqual that
can be executed against the index-returned tuple without using any
non-returnable columns. (The restrictions imposed by check_index_only
guarantee this is possible, although we may have to recompute indexed
expressions.) Support construction of that during setrefs.c
processing by marking IndexOnlyScan.indextlist entries as resjunk
if they can't be returned, rather than removing them entirely.
(We could alternatively require setrefs.c to look up the IndexOptInfo
again, but abusing resjunk this way seems like a reasonably safe way
to avoid needing to do that.)
This solution isn't great from an API-stability standpoint: if there
are any extensions out there that build IndexOnlyScan structs directly,
they'll be broken in the next minor releases. However, only a very
invasive extension would be likely to do such a thing. There's no
change in the Path representation, so typical planner extensions
shouldn't have a problem.
As before, back-patch to all supported branches.
Discussion: https://postgr.es/m/
3179992.
1641150853@sss.pgh.pa.us
Discussion: https://postgr.es/m/17350-
b5bdcf476e5badbb@postgresql.org
Tom Lane [Mon, 3 Jan 2022 19:05:03 +0000 (14:05 -0500)]
Clean up error messages related to bad datetime units.
Adjust the error texts used for unrecognized/unsupported datetime
units so that there are just two strings to translate, not two
per datatype. Along the way, follow our usual error message style
of not double-quoting type names, and instead making sure that we
say the name is a type. Fix a couple of places in date.c that
were using the wrong one of "unrecognized" and "unsupported".
Nikhil Benesch, with a bit more editing by me
Discussion: https://postgr.es/m/CAPWqQZTURGixmbMH2_Z3ZtWGA0ANjUb9bwtkkxSxSfDeFHuM6Q@mail.gmail.com
Tom Lane [Mon, 3 Jan 2022 17:24:44 +0000 (12:24 -0500)]
Use MaxLockMode symbol in more places.
As long as we have this macro, it makes sense to use it in
the LockMethodData structures.
Julien Rouhaud
Discussion: https://postgr.es/m/
20220103064722.ewdv4evlez5m7mdn@jrouhaud
Alvaro Herrera [Mon, 3 Jan 2022 13:48:48 +0000 (10:48 -0300)]
Avoid using DefElemAction in AlterPublicationStmt
Create a new enum type for it. This allows to add new values for future
functionality without disrupting unrelated uses of DefElem.
Discussion: https://postgr.es/m/
202112302021.ca7ihogysgh3@alvherre.pgsql
Michael Paquier [Mon, 3 Jan 2022 08:34:45 +0000 (17:34 +0900)]
pg_stat_statements: Remove obsolete comment
Since
4f0b096, pgss_store() does nothing if compute_query_id is disabled
or if no other module computed a query identifier, but the top comment
of this function did not reflect that. This behavior is already
documented in its own code path, and this just removes the inconsistent
comment.
Author: Kyotaro Horiguchi
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/
20211122.153823.
1325120762360533122.horikyota.ntt@gmail.com
Backpatch-through: 14
Magnus Hagander [Sun, 2 Jan 2022 16:03:32 +0000 (17:03 +0100)]
Fix typo
Reported-By: Eric Mutta
Backpatch-through: 10
Discussion: https://postgr.es/m/
164052477973.21665.
7888120874624887609@wrigleys.postgresql.org
Tom Lane [Sat, 1 Jan 2022 21:12:03 +0000 (16:12 -0500)]
Fix index-only scan plans when not all index columns can be returned.
If an index has both returnable and non-returnable columns, and one of
the non-returnable columns is an expression using a Var that is in a
returnable column, then a query returning that expression could result
in an index-only scan plan that attempts to read the non-returnable
column, instead of recomputing the expression from the returnable
column as intended.
To fix, redefine the "indextlist" list of an IndexOnlyScan plan node
as containing null Consts in place of any non-returnable columns.
This solves the problem by preventing setrefs.c from falsely matching
to such entries. The executor is happy since it only cares about the
exposed types of the entries, and ruleutils.c doesn't care because a
correct plan won't reference those entries. I considered some other
ways to prevent setrefs.c from doing the wrong thing, but this way
seems good since (a) it allows a very localized fix, (b) it makes
the indextlist structure more compact in many cases, and (c) the
indextlist is now a more faithful representation of what the index AM
will actually produce, viz. nulls for any non-returnable columns.
This is easier to hit since we introduced included columns, but it's
possible to construct failing examples without that, as per the
added regression test. Hence, back-patch to all supported branches.
Per bug #17350 from Louis Jachiet.
Discussion: https://postgr.es/m/17350-
b5bdcf476e5badbb@postgresql.org
Tom Lane [Fri, 31 Dec 2021 17:47:57 +0000 (12:47 -0500)]
pg_dump: avoid unsafe function calls in getPolicies().
getPolicies() had the same disease I fixed in other places in
commit
e3fcbbd62, i.e., it was calling pg_get_expr() for
expressions on tables that we don't necessarily have lock on.
To fix, restrict the query to only collect interesting rows,
rather than doing the filtering on the client side.
Like the previous patch, apply to HEAD only for now.
Discussion: https://postgr.es/m/
2273648.
1634764485@sss.pgh.pa.us
Discussion: https://postgr.es/m/
7d7eb6128f40401d81b3b7a898b6b4de@W2012-02.nidsa.loc
Tom Lane [Fri, 31 Dec 2021 16:39:26 +0000 (11:39 -0500)]
pg_dump: minor performance improvements from eliminating sub-SELECTs.
Get rid of the "username_subquery" mechanism in favor of doing
local lookups of role names from role OIDs. The PG backend isn't
terribly smart about scalar SubLinks in SELECT output lists,
so this offers a small performance improvement, at least in
installations with more than a couple of users. In any case
the old method didn't make for particularly readable SQL code.
While at it, I removed the various custom warning messages about
failing to find an object's owner, in favor of just fatal'ing
in the local lookup function. AFAIK there is no reason any
longer to treat that as anything but a catalog-corruption case,
and certainly no reason to make translators deal with a dozen
different messages where one would do. (If it turns out that
fatal() is indeed a bad idea, we can back off to issuing
pg_log_warning() and returning an empty string, resulting in
the same behavior as before, except more consistent.)
Also drop an entirely unnecessary sub-SELECT to check on the
pg_depend status of a sequence relation: we already have a
LEFT JOIN to fetch the row of interest in the FROM clause.
Discussion: https://postgr.es/m/
2460369.
1640903318@sss.pgh.pa.us
Andres Freund [Fri, 31 Dec 2021 02:59:20 +0000 (18:59 -0800)]
ci: Add continuous integration for github repositories via cirrus-ci.
Currently FreeBSD, Linux, macOS and Windows (Visual Studio) are tested.
The main goal of this integration is to make it easier to test in-development
patches across multiple platforms. This includes improving the testing done
automatically by cfbot [1] for commitfest entries. It is *not* the goal to
supersede the buildfarm.
cirrus-ci [2] was chosen because it was already in use for cfbot, allows using
full VMs, has good OS coverage and allows accessing the full test results
without authentication (like a github account). It might be worth adding
support for further CI providers, particularly ones supporting other git
forges, in the future.
To keep CI times tolerable, most platforms use pre-generated images. Some
platforms use containers, others use full VMs.
For instructions on how to enable the CI integration in a repository and
further details, see src/tools/ci/README
[1] http://cfbot.cputube.org/
[2] https://cirrus-ci.org/
Author: Andres Freund <andres@anarazel.de>
Author: Thomas Munro <tmunro@postgresql.org>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-By: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-By: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-By: Thomas Munro <tmunro@postgresql.org>
Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/
20211001222752.wrz7erzh4cajvgp6@alap3.anarazel.de
Tom Lane [Fri, 31 Dec 2021 00:40:37 +0000 (19:40 -0500)]
pg_dump: make dumpPublication et al. less unlike sibling functions.
dumpPublication, dumpPublicationNamespace, dumpPublicationTable, and
dumpSubscription failed to check dataOnly. This is just a latent bug,
because pg_backup_archiver.c would filter out the ArchiveEntry later;
but they're wasting cycles in data-only dumps, and the omission might
become a live bug someday. In any case, it's not good to have some
dumpFoo functions do this and some not.
On the same reasoning, make dumpPublicationNamespace follow the
same pattern as every other dumpFoo function for checking the
DUMP_COMPONENT_DEFINITION flag. (Since
5209c0ba0, we wouldn't
even get here if that flag isn't set, so checking it is just
pro forma right now. But it might not be so forever.)
Since this is just cosmetic and/or future-proofing, no need for
back-patch.
Alvaro Herrera [Thu, 30 Dec 2021 22:24:26 +0000 (19:24 -0300)]
Small cleanups related to PUBLICATION framework code
Discussion: https://postgr.es/m/
202112302021.ca7ihogysgh3@alvherre.pgsql
Tom Lane [Thu, 30 Dec 2021 19:29:32 +0000 (14:29 -0500)]
Minor cleanup/optimization in pg_dump.
In the wake of commits
05649b88c and
5209c0ba0, findComments() and
findSecLabels() no longer use their "Archive *fout" arguments,
so get rid of those.
While doing that, I noticed that there's no very good reason why
dumpCompositeTypeColComments() should be doing its own query to fetch
the column names of the composite type, when the calling function has
just fetched the same data. Tweak it to use that query result. This
probably doesn't save a lot for most people, because since
5209c0ba0
we won't get into this code at all unless the composite type has at
least one comment. Nonetheless, it's a wasted query.
Daniel Gustafsson [Thu, 30 Dec 2021 12:23:47 +0000 (13:23 +0100)]
Revert
b2a459edf "Fix GRANTED BY support in REVOKE ROLE statements"
The reverted commit attempted to fix SQL specification compliance for
the cases which
6aaaa76bb left. This however broke existing behavior
which takes precedence over spec compliance so revert. The introduced
tests are left after the revert since the codepath isn't well covered.
Per bug report 17346. Backpatch down to 14 where it was introduced.
Reported-by: Andrew Bille <andrewbille@gmail.com>
Discussion: https://postgr.es/m/17346-
f72b28bd1a341060@postgresql.org
Thomas Munro [Thu, 30 Dec 2021 03:09:53 +0000 (16:09 +1300)]
Fix overly generic name in with.sql test.
Avoid the name "test". In the 10 branch, this could clash with
alter_table.sql, as seen in the build farm. That other instance was
already renamed in later branches by commit
2cf8c7aa, but it's good to
future-proof the name here too.
Back-patch to 10.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CA%2BhUKGJf4RAXUyAYVUcQawcptX%3DnhEco3SYpuPK5cCbA-F1eLA%40mail.gmail.com
Tom Lane [Wed, 29 Dec 2021 22:02:50 +0000 (17:02 -0500)]
Fix issues in pgarch's new directory-scanning logic.
The arch_filenames[] array elements were one byte too small, so that
a maximum-length filename would get corrupted if another entry
were made after it. (Noted by Thomas Munro, fix by Nathan Bossart.)
Move these arrays into a palloc'd struct, so that we aren't wasting
a few kilobytes of static data in each non-archiver process.
Add a binaryheap_reset() call to make it plain that we start the
directory scan with an empty heap. I don't think there's any live
bug of that sort, but it seems fragile, and this is very cheap
insurance.
Cleanup for commit
beb4e9ba1, so no back-patch needed.
Discussion: https://postgr.es/m/CA+hUKGLHAjHuKuwtzsW7uMJF4BVPcQRL-UMZG_HM-g0y7yLkUg@mail.gmail.com
Peter Eisentraut [Wed, 29 Dec 2021 09:08:41 +0000 (10:08 +0100)]
Fix incorrect format placeholders
Tom Lane [Mon, 27 Dec 2021 21:01:10 +0000 (16:01 -0500)]
Revert changes about warnings/errors for placeholders.
Revert commits
5609cc01c,
2ed8a8cc5, and
75d22069e until we have
a less broken idea of how this should work in parallel workers.
Per buildfarm.
Discussion: https://postgr.es/m/
1640909.
1640638123@sss.pgh.pa.us
Tom Lane [Mon, 27 Dec 2021 19:39:08 +0000 (14:39 -0500)]
Rename EmitWarningsOnPlaceholders() to MarkGUCPrefixReserved().
This seems like a clearer name for what it does now.
Provide a compatibility macro so that extensions don't have to convert
to the new name right away.
Discussion: https://postgr.es/m/116024.
1640111629@sss.pgh.pa.us
Tom Lane [Mon, 27 Dec 2021 19:35:50 +0000 (14:35 -0500)]
Rethink handling of settings with a prefix reserved by an extension.
Commit
75d22069e made SET print a warning if you tried to set an
unrecognized parameter within namespace previously reserved by an
extension. It seems better for that to be an outright error though,
for the same reason that we don't let you set unrecognized unqualified
parameter names. In any case, the preceding implementation was
inefficient and erroneous. Perform the check in a more appropriate
spot, and be more careful about prefix-match cases.
Discussion: https://postgr.es/m/116024.
1640111629@sss.pgh.pa.us
Michael Paquier [Sun, 26 Dec 2021 08:41:59 +0000 (17:41 +0900)]
Fix incorrect field count in pg_control_checkpoint()
18 columns are generated in this function, but we had enough space for
19 of them. Introduced by
4b0d28d.
Author: Bharath Rupireddy
Reviewed-by: Justin Pryzby, Euler Taveira
Discussion: https://postgr.es/m/CALj2ACVQ=hAs=sT0n4xriimqRrrgECySfg_tSqA+26Rb_yfs2A@mail.gmail.com
Fujii Masao [Fri, 24 Dec 2021 08:39:59 +0000 (17:39 +0900)]
postgres_fdw: Revert unstable tests for postgres_fdw.application_name.
Commit
6e0cb3dec1 added the tests that check that escape sequences in
postgres_fdw.application_name setting are replaced with status information
expectedly. But they were unstable and caused some buildfarm
members to report the failure. This commit reverts those unstable tests.
Fujii Masao [Fri, 24 Dec 2021 07:55:11 +0000 (16:55 +0900)]
postgres_fdw: Allow postgres_fdw.application_name to include escape sequences.
application_name that used when postgres_fdw establishes a connection to
a foreign server can be specified in either or both a connection parameter
of a server object and GUC postgres_fdw.application_name. This commit
allows those parameters to include escape sequences that begins with
% character. Then postgres_fdw replaces those escape sequences with
status information. For example, %d and %u are replaced with user name
and database name in local server, respectively. This feature enables us
to add information more easily to track remote transactions or queries,
into application_name of a remote connection.
Author: Hayato Kuroda
Reviewed-by: Kyotaro Horiguchi, Masahiro Ikeda, Hou Zhijie, Fujii Masao
Discussion: https://postgr.es/m/TYAPR01MB5866FAE71C66547C64616584F5EB9@TYAPR01MB5866.jpnprd01.prod.outlook.com
Discussion: https://postgr.es/m/TYCPR01MB5870D1E8B949DAF6D3B84E02F5F29@TYCPR01MB5870.jpnprd01.prod.outlook.com
Amit Kapila [Thu, 23 Dec 2021 07:14:45 +0000 (12:44 +0530)]
Fix compilation error introduced by commit
8e1fae1938.
Author: Masahiko Sawada
Discussion: https://postgr.es/m/E1n0HSK-00048l-RE@gemulon.postgresql.org
Amit Kapila [Thu, 23 Dec 2021 06:12:52 +0000 (11:42 +0530)]
Move parallel vacuum code to vacuumparallel.c.
This commit moves parallel vacuum related code to a new file
commands/vacuumparallel.c so that any table AM supporting indexes can
utilize parallel vacuum in order to call index AM callbacks (ambulkdelete
and amvacuumcleanup) with parallel workers.
Another reason for this refactoring is that the parallel vacuum isn't
specific to heap so it doesn't make sense to keep this code in
heap/vacuumlazy.c.
Author: Masahiko Sawada, based on suggestion from Andres Freund
Reviewed-by: Hou Zhijie, Amit Kapila, Haiying Tang
Discussion: https://www.postgresql.org/message-id/
20211030212101.ae3qcouatwmy7tbr%40alap3.anarazel.de
Bruce Momjian [Wed, 22 Dec 2021 21:29:16 +0000 (16:29 -0500)]
doc: clarify when expression indexes evaluate their expressions
Only non-HOT updates evaluate the index expression.
Reported-by: Chris Lowder
Discussion: https://postgr.es/m/
163967385701.26064.
15365003480975321072@wrigleys.postgresql.org
Backpatch-through: 10
Peter Eisentraut [Wed, 22 Dec 2021 14:04:42 +0000 (15:04 +0100)]
Remove unused include
"utils/builtins.h" was used for pg_strtouint64(), added by
cff440d368690f94fbda1a475277e90ea2263843, removed by
3c6f8c011f85df7b35c32f4ccaac5c86c9064a4a.
Peter Eisentraut [Wed, 22 Dec 2021 14:02:57 +0000 (15:02 +0100)]
Remove unused include
"fmgr.h" was used for load_external_function(), added by
a05dc4d7fd57d4ae084c1f0801973e5c1a1aa26e, removed by
f9143d102ffd0947ca904c62b1d3d6fd587e0c80.
Peter Eisentraut [Wed, 22 Dec 2021 07:34:10 +0000 (08:34 +0100)]
Fix incorrect format placeholders
Michael Paquier [Wed, 22 Dec 2021 07:37:58 +0000 (16:37 +0900)]
Correct comment and some documentation about REPLICA_IDENTITY_INDEX
catalog/pg_class.h was stating that REPLICA_IDENTITY_INDEX with a
dropped index is equivalent to REPLICA_IDENTITY_DEFAULT. The code tells
a different story, as it is equivalent to REPLICA_IDENTITY_NOTHING.
The behavior exists since the introduction of replica identities, and
fe7fd4e even added tests for this case but I somewhat forgot to fix this
comment.
While on it, this commit reorganizes the documentation about replica
identities on the ALTER TABLE page, and a note is added about the case
of dropped indexes with REPLICA_IDENTITY_INDEX.
Author: Michael Paquier, Wei Wang
Reviewed-by: Euler Taveira
Discussion: https://postgr.es/m/OS3PR01MB6275464AD0A681A0793F56879E759@OS3PR01MB6275.jpnprd01.prod.outlook.com
Backpatch-through: 10
Peter Eisentraut [Wed, 22 Dec 2021 06:52:18 +0000 (07:52 +0100)]
Fix typo in code comment
Reported-by: Kevin Zheng <1642644905@qq.com>
Discussion: https://www.postgresql.org/message-id/flat/17341-
d913ddb626c5c08c%40postgresql.org
Michael Paquier [Wed, 22 Dec 2021 06:38:00 +0000 (15:38 +0900)]
Remove assertion for ALTER TABLE .. DETACH PARTITION CONCURRENTLY
One code path related to this flavor of ALTER TABLE was checking that
the relation to detach has to be a normal table or a partitioned table,
which would fail if using the command with a different relation kind.
Views, sequences and materialized views cannot be part of a partition
tree, so these would cause the command to fail anyway, but the assertion
was triggered. Foreign tables can be part of a partition tree, and
again the assertion would have failed. The simplest solution is just to
remove this assertion, so as we get the same failure as the
non-concurrent code path.
While on it, add a regression test in postgres_fdw for the concurrent
partition detach of a foreign table, as per a suggestion from Alexander
Lakhin.
Issue introduced in
71f4c8c.
Reported-by: Alexander Lakhin
Author: Michael Paquier, Alexander Lakhin
Reviewed-by: Peter Eisentraut, Kyotaro Horiguchi
Discussion: https://postgr.es/m/17339-
a9e09aaf38a3457a@postgresql.org
Backpatch-through: 14
Amit Kapila [Wed, 22 Dec 2021 02:25:14 +0000 (07:55 +0530)]
Move index vacuum routines to vacuum.c.
An upcoming patch moves parallel vacuum code out of vacuumlazy.c. This
code restructuring will allow both lazy vacuum and parallel vacuum to use
index vacuum functions.
Author: Masahiko Sawada
Reviewed-by: Hou Zhijie, Amit Kapila
Discussion: https://www.postgresql.org/message-id/
20211030212101.ae3qcouatwmy7tbr%40alap3.anarazel.de
Tom Lane [Tue, 21 Dec 2021 21:18:41 +0000 (16:18 -0500)]
Add help & tab-complete support for psql's \getenv.
I forgot about these details in
33d3eeadb :-(.
Noted by Christoph Berg.
Discussion: https://postgr.es/m/YcI8i/mduMi91uXY@msg.df7cb.de
Tom Lane [Tue, 21 Dec 2021 17:12:24 +0000 (12:12 -0500)]
Add missing EmitWarningsOnPlaceholders() calls.
Extensions that define any custom GUCs should call
EmitWarningsOnPlaceholders after doing so, to help catch misspellings.
Many of our contrib modules hadn't gotten the memo on that, though.
Also add such calls to src/test/modules extensions that have GUCs.
While these aren't really user-facing, they should illustrate good
practice not faulty practice.
Shinya Kato
Discussion: https://postgr.es/m/
524fa2c0a34f34b68fbfa90d0760d515@oss.nttdata.com
Tom Lane [Mon, 20 Dec 2021 21:49:13 +0000 (16:49 -0500)]
Merge dblink's paths test script into its main test.
There's no longer any reason to fire up a separate psql run
to create these functions. (Some refactoring in the main
regression tests is also called for, but that will take
more thought.)
Discussion: https://postgr.es/m/
1655733.
1639871614@sss.pgh.pa.us
Tom Lane [Mon, 20 Dec 2021 19:15:52 +0000 (14:15 -0500)]
Remove dynamic translation of regression test scripts, step 2.
"git mv" all the input/*.source and output/*.source files into
the corresponding sql/ and expected/ directories. Then remove
the pg_regress and Makefile infrastructure associated with
dynamic translation.
Discussion: https://postgr.es/m/
1655733.
1639871614@sss.pgh.pa.us
Tom Lane [Mon, 20 Dec 2021 19:06:15 +0000 (14:06 -0500)]
Remove dynamic translation of regression test scripts, step 1.
pg_regress has long had provisions for dynamically substituting path
names into regression test scripts and result files, but use of that
feature has always been a serious pain in the neck, mainly because
updating the result files requires tedious manual editing. Let's
get rid of that in favor of passing down the paths in environment
variables.
In addition to being easier to maintain, this way is capable of
dealing with path names that require escaping at runtime, for example
paths containing single-quote marks. (There are other stumbling
blocks in the way of actually building in a path that looks like
that, but removing this one seems like a good thing to do.) The key
coding rule that makes that possible is to concatenate pieces of a
dynamically-variable string using psql's \set command, and then use
the :'variable' notation to quote and escape the string for the next
level of interpretation.
In hopes of making this change more transparent to "git blame",
I've split it into two steps. This commit adds the necessary
pg_regress.c support and changes all the *.source files in-place
so that they no longer require any dynamic translation. The next
commit will just "git mv" them into the regular sql/ and expected/
directories.
Discussion: https://postgr.es/m/
1655733.
1639871614@sss.pgh.pa.us
Tom Lane [Mon, 20 Dec 2021 18:17:58 +0000 (13:17 -0500)]
Add a \getenv command to psql.
\getenv fetches the value of an environment variable into a psql
variable. This is the inverse of the \setenv command that was added
over ten years ago. We'd not seen a compelling use-case for \getenv
at the time, but upcoming regression test refactoring provides a
sufficient reason to add it now.
Discussion: https://postgr.es/m/
1655733.
1639871614@sss.pgh.pa.us
John Naylor [Tue, 19 Oct 2021 20:43:14 +0000 (16:43 -0400)]
Add fast path for validating UTF-8 text
Our previous validator used a traditional algorithm that performed
comparison and branching one byte at a time. It's useful in that
we always know exactly how many bytes we have validated, but that
precision comes at a cost. Input validation can show up prominently
in profiles of COPY FROM, and future improvements to COPY FROM such
as parallelism or faster line parsing will put more pressure on input
validation. Hence, add fast paths for both ASCII and multibyte UTF-8:
Use bitwise operations to check 16 bytes at a time for ASCII. If
that fails, use a "shift-based" DFA on those bytes to handle the
general case, including multibyte. These paths are relatively free
of branches and thus robust against all kinds of byte patterns. With
these algorithms, UTF-8 validation is several times faster, depending
on platform and the input byte distribution.
The previous coding in pg_utf8_verifystr() is retained for short
strings and for when the fast path returns an error.
Review, performance testing, and additional hacking by: Heikki
Linakangas, Vladimir Sitnikov, Amit Khandekar, Thomas Munro, and
Greg Stark
Discussion:
https://www.postgresql.org/message-id/CAFBsxsEV_SzH%2BOLyCiyon%3DiwggSyMh_eF6A3LU2tiWf3Cy2ZQg%40mail.gmail.com
Peter Eisentraut [Mon, 20 Dec 2021 10:08:05 +0000 (11:08 +0100)]
pg_dump: Refactor getIndexes()
Rearrange the version-dependent pieces in the new more modular style.
Discussion: https://www.postgresql.org/message-id/flat/
67a28a3f-7b79-a5a9-fcc7-
947b170e66f0%40enterprisedb.com
Peter Eisentraut [Mon, 20 Dec 2021 09:12:25 +0000 (10:12 +0100)]
doc: More documentation on regular expressions and SQL standard
Reviewed-by: Gilles Darold <gilles@darold.net>
Discussion: https://www.postgresql.org/message-id/
b7988566-daa2-80ed-2fdc-
6f6630462d26@enterprisedb.com
Tom Lane [Sun, 19 Dec 2021 22:18:34 +0000 (17:18 -0500)]
Remove some more dead code in pg_dump.
Coverity complained that parts of dumpFunc() and buildACLCommands()
were now unreachable, as indeed they are. Remove 'em.
In passing, make dumpFunc's handling of protrftypes less gratuitously
different from other fields.
Michael Paquier [Sat, 18 Dec 2021 07:30:01 +0000 (16:30 +0900)]
Fix typo in TAP tests of pg_receivewal
Introduced in
d62bcc8, noticed while hacking in the area.
Michael Paquier [Sat, 18 Dec 2021 07:18:45 +0000 (16:18 +0900)]
Add option -N/--no-sync to pg_upgrade
This is an option consistent with what the other tools of src/bin/
(pg_checksums, pg_dump, pg_rewind and pg_basebackup) provide which is
useful for leveraging the I/O effort when testing things. This is not
to be used in a production environment.
All the regression tests of pg_upgrade are updated to use this new
option. This happens to cut at most a couple of seconds in environments
constrained on I/O, by avoiding a flush of data folder for the new
cluster upgraded.
Author: Michael Paquier
Reviewed-by: Peter Eisentraut
Discussion: https://postgr.es/m/YbrhzuBmBxS/DkfX@paquier.xyz
Tom Lane [Fri, 17 Dec 2021 21:22:26 +0000 (16:22 -0500)]
Fix the public schema's permissions in a separate test script.
In the wake of commit
b073c3ccd, it's necessary to grant create
permissions on the public schema to PUBLIC to get many of the
core regression test scripts to pass. That commit did so via the
quick-n-dirty expedient of adding the GRANT to the tablespace test,
which runs first. This is problematic for single-machine
replication testing, though. The least painful way to run the
regression tests on such a setup is to skip the tablespace test,
and that no longer works.
To fix, let's invent a separate "test_setup" script to run first,
and put the GRANT there. Revert
b073c3ccd's changes to
the tablespace.source files.
In the future it might be good to try to reduce coupling between
the various test scripts by having test_setup create widely-used
objects, with the goal that most of the scripts could run after
having run only test_setup. That's going to take some effort,
so this commit just addresses my immediate pain point.
Discussion: https://postgr.es/m/
1363170.
1639763559@sss.pgh.pa.us
Peter Eisentraut [Fri, 17 Dec 2021 05:05:54 +0000 (06:05 +0100)]
Simplify the general-purpose 64-bit integer parsing APIs
pg_strtouint64() is a wrapper around strtoull/strtoul/_strtoui64, but
it seems no longer necessary to have this indirection.
msvc/Solution.pm claims HAVE_STRTOULL, so the "MSVC only" part seems
unnecessary. Also, we have code in c.h to substitute alternatives for
strtoull() if not found, and that would appear to cover all currently
supported platforms, so having a further fallback in pg_strtouint64()
seems unnecessary.
Therefore, we could remove pg_strtouint64(), and use strtoull()
directly in all call sites. However, it seems useful to keep a
separate notation for parsing exactly 64-bit integers, matching the
type definition int64/uint64. For that, add new macros strtoi64() and
strtou64() in c.h as thin wrappers around strtol()/strtoul() or
strtoll()/stroull(). This makes these functions available everywhere
instead of just in the server code, and it makes the function naming
notably different from the pg_strtointNN() functions in numutils.c,
which have a different API.
Discussion: https://www.postgresql.org/message-id/flat/
a3df47c9-b1b4-29f2-7e91-
427baf8b75a3%40enterprisedb.com
Tom Lane [Thu, 16 Dec 2021 20:36:02 +0000 (15:36 -0500)]
Ensure casting to typmod -1 generates a RelabelType.
Fix the code changed by commit
5c056b0c2 so that we always generate
RelabelType, not something else, for a cast to unspecified typmod.
Otherwise planner optimizations might not happen.
It appears we missed this point because the previous experiments were
done on type numeric: the parser undesirably generates a call on the
numeric() length-coercion function, but then numeric_support()
optimizes that down to a RelabelType, so that everything seems fine.
It misbehaves for types that have a non-optimized length coercion
function, such as bpchar.
Per report from John Naylor. Back-patch to all supported branches,
as the previous patch eventually was. Unfortunately, that no longer
includes 9.6 ... we really shouldn't put this type of change into a
nearly-EOL branch.
Discussion: https://postgr.es/m/CAFBsxsEfbFHEkouc+FSj+3K1sHipLPbEC67L0SAe-9-da8QtYg@mail.gmail.com