pgsql: Better handle indirect constraint drops

2024-04-19 Thread Alvaro Herrera
Better handle indirect constraint drops

It is possible for certain cases to remove not-null constraints without
maintaining the attnotnull in its correct state; for example if you drop
a column that's part of the primary key, and the other columns of the PK don't
have not-null constraints, then we should reset the attnotnull flags for
those other columns; up to this commit, we didn't.  Handle those cases
better by doing the attnotnull reset in RemoveConstraintById() instead
of in dropconstraint_internal().

However, there are some cases where we must not do so.  For example if
those other columns are in replica identity indexes or are generated
identity columns, we must keep attnotnull set, even though it results in
the catalog inconsistency that no not-null constraint supports that.

Because the attnotnull reset now happens in more places than before, for
instance when a column of the primary key changes type, we need an
additional trick to reinstate it as necessary.  Introduce a new
alter-table pass that does this, which needs simply reschedule some
AT_SetAttNotNull subcommands that were already being generated and
ignored.

Because of the exceptions in which attnotnull is not reset noted above,
we also include a pg_dump hack to include a not-null constraint when the
attnotnull flag is set even if no pg_constraint row exists.  This part
is undesirable but necessary, because failing to handle the case can
result in unrestorable dumps.

Reported-by: Tender Wang 
Co-authored-by: Tender Wang 
Reviewed-by: jian he 
Discussion: 
https://postgr.es/m/CAHewXN=hMbNa3d43NOR=ocgdgptt18s-1fmuecoegesyek4...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/0cd711271d42b0888d36f8eda50e1092c2fed4b3

Modified Files
--
src/backend/catalog/pg_constraint.c   | 117 +-
src/backend/commands/tablecmds.c  | 135 +++---
src/bin/pg_dump/pg_dump.c |  30 +--
src/test/regress/expected/constraints.out |  78 +
src/test/regress/sql/constraints.sql  |  39 +
5 files changed, 323 insertions(+), 76 deletions(-)



pgsql: Don't try to assign smart names to constraints

2024-04-18 Thread Alvaro Herrera
Don't try to assign smart names to constraints

This part of my previous commit seems to have broken pg_upgrade on
crake, at least from 9.2.  I'll see if there's a better fix, but in the
meantime this should suffice to keep the buildfarm green.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d72d32f52d26c9588256de90b9bc54fe312cee60

Modified Files
--
src/bin/pg_dump/pg_dump.c | 16 +++-
1 file changed, 3 insertions(+), 13 deletions(-)



Re: pgsql: Fix restore of not-null constraints with inheritance

2024-04-18 Thread Alvaro Herrera
On 2024-Apr-18, Alvaro Herrera wrote:

> Lastly, make two changes to pg_dump: 1) do not try to drop a not-null
> constraint that's marked as inherited; this allows a dump to restore
> with no errors if a table with a PK inherits from another which also has
> a PK; 2) avoid giving inherited constraints throwaway names, for the
> rare cases where such a constraint survives after the restore.

Hmm, this last bit broke pg_upgrade on crake.  I'll revert this part,
meanwhile I'll be installing 9.2 to see if it can be fixed in a better way.

-- 
Álvaro Herrera PostgreSQL Developer  —  https://www.EnterpriseDB.com/




pgsql: Fix restore of not-null constraints with inheritance

2024-04-18 Thread Alvaro Herrera
Fix restore of not-null constraints with inheritance

In tables with primary keys, pg_dump creates tables with primary keys by
initially dumping them with throw-away not-null constraints (marked "no
inherit" so that they don't create problems elsewhere), to later drop
them once the primary key is restored.  Because of a unrelated
consideration, on tables with children we add not-null constraints to
all columns of the primary key when it is created.

If both a table and its child have primary keys, and pg_dump happens to
emit the child table first (and its throw-away not-null) and later its
parent table, the creation of the parent's PK will fail because the
throw-away not-null constraint collides with the permanent not-null
constraint that the PK wants to add, so the dump fails to restore.

We can work around this problem by letting the primary key "take over"
the child's not-null.  This requires no changes to pg_dump, just two
changes to ALTER TABLE: first, the ability to convert a no-inherit
not-null constraint into a regular inheritable one (including recursing
down to children, if there are any); second, the ability to "drop" a
constraint that is defined both directly in the table and inherited from
a parent (which simply means to mark it as no longer having a local
definition).

Secondarily, change ATPrepAddPrimaryKey() to acquire locks all the way
down the inheritance hierarchy, in case we need to recurse when
propagating constraints.

These two changes allow pg_dump to reproduce more cases involving
inheritance from versions 16 and older.

Lastly, make two changes to pg_dump: 1) do not try to drop a not-null
constraint that's marked as inherited; this allows a dump to restore
with no errors if a table with a PK inherits from another which also has
a PK; 2) avoid giving inherited constraints throwaway names, for the
rare cases where such a constraint survives after the restore.

Reported-by: Andrew Bille 
Reported-by: Justin Pryzby 
Discussion: 
https://postgr.es/m/cajnzarwkfru76_yi3dqvf_wl-mpvt54zmwaxfwjcexdhb76...@mail.gmail.com
Discussion: https://postgr.es/m/Zh0aAH7tbZb-9HbC@pryzbyj2023

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d9f686a72ee91f6773e5d2bc52994db8d7157a8e

Modified Files
--
src/backend/catalog/heap.c| 36 +++--
src/backend/catalog/pg_constraint.c   | 43 +---
src/backend/commands/tablecmds.c  | 65 +++
src/bin/pg_dump/pg_dump.c | 26 +++--
src/include/catalog/pg_constraint.h   |  2 +-
src/test/regress/expected/constraints.out | 56 ++
src/test/regress/sql/constraints.sql  | 22 +++
7 files changed, 221 insertions(+), 29 deletions(-)



pgsql: ATTACH PARTITION: Don't match a PK with a UNIQUE constraint

2024-04-15 Thread Alvaro Herrera
ATTACH PARTITION: Don't match a PK with a UNIQUE constraint

When matching constraints in AttachPartitionEnsureIndexes() we weren't
testing the constraint type, which could make a UNIQUE key lacking a
not-null constraint incorrectly satisfy a primary key requirement.  Fix
this by testing that the constraint types match.  (Other possible
mismatches are verified by comparing index properties.)

Discussion: https://postgr.es/m/202402051447.wimb4xmtiiyb@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/cee8db3f680b737b64d747530b48d30828cf4790

Modified Files
--
src/backend/commands/tablecmds.c  |  5 +
src/backend/utils/cache/lsyscache.c   | 22 ++
src/include/utils/lsyscache.h |  2 ++
src/test/regress/expected/constraints.out | 16 
src/test/regress/sql/constraints.sql  |  7 +++
5 files changed, 52 insertions(+)



pgsql: Fix propagating attnotnull in multiple inheritance

2024-04-15 Thread Alvaro Herrera
Fix propagating attnotnull in multiple inheritance

In one of the many strange corner cases of multiple inheritance being
used, commit b0e96f311985 missed a CommandCounterIncrement() call after
updating the attnotnull flag during ALTER TABLE ADD COLUMN, which caused
a catalog tuple to be update attempted twice in the same command, giving
rise to a "tuple already updated by self" error.  Add the missing call
to solve that, and a test case that reproduces the scenario.

As a (perhaps surprising) secondary effect, this CCI addition triggers
another behavior change: when a primary key is added to a parent
partitioned table and the column in an existing partition does not have
a not-null constraint, we no longer error out.  This will probably be a
welcome change by some users, and I think it's unlikely that anybody
will miss the old behavior.

Reported-by: Alexander Lakhin 
Discussion: http://postgr.es/m/045dec3f-9b3d-aa44-0c99-85f699230...@gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/c3709100be73ad5af7ff536476d4d713bca41b1a

Modified Files
--
src/backend/commands/tablecmds.c  |  4 
src/test/regress/expected/constraints.out | 10 +-
src/test/regress/expected/inherit.out |  8 
src/test/regress/sql/constraints.sql  |  7 +++
src/test/regress/sql/inherit.sql  |  7 +++
5 files changed, 35 insertions(+), 1 deletion(-)



pgsql: Use conditional variable to wait for next MultiXact offset

2024-04-07 Thread Alvaro Herrera
Use conditional variable to wait for next MultiXact offset

In one multixact.c edge case, we need a mechanism to wait for one
multixact offset to be written before being allowed to read the next
one.  We used to handle this case by sleeping for one millisecond and
retrying, but such sleeps have been reported as problematic in
production cases.  We can avoid the problem by using a condition
variable: readers sleep on it and then every creator of multixacts
broadcasts into the CV when creation is sufficiently far along.

Author: Kyotaro Horiguchi 
Reviewed-by: Andrey Borodin 
Discussion: 
https://postgr.es/m/47a598f4-b4e7-4029-8fec-a06a6c3cb...@yandex-team.ru
Discussion: https://postgr.es/m/20200515.090333.24867479329066911.horikyota.ntt

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a0e0fb1ba56ff4323542c75ce997a41d31ad28a0

Modified Files
--
src/backend/access/transam/multixact.c  | 30 +++--
src/backend/utils/activity/wait_event_names.txt |  1 +
2 files changed, 29 insertions(+), 2 deletions(-)



pgsql: Add XLogCtl->logInsertResult

2024-04-07 Thread Alvaro Herrera
Add XLogCtl->logInsertResult

This tracks the position of WAL that's been fully copied into WAL
buffers by all processes emitting WAL.  (For some reason we call that
"WAL insertion").  This is updated using atomic monotonic advance during
WaitXLogInsertionsToFinish, which is not when the insertions actually
occur, but it's the only place where we know where have all the
insertions have completed.

This value is useful in WALReadFromBuffers, which can verify that
callers don't try to read past what has been inserted.  (However, more
infrastructure is needed in order to actually use WAL after the flush
point, since it could be lost.)

The value is also useful in WaitXLogInsertionsToFinish() itself, since
we can now exit quickly when all WAL has been already inserted, without
even having to take any locks.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/f3ff7bf83bce11709add9a6d31d4bebe95e086e3

Modified Files
--
src/backend/access/transam/xlog.c | 40 ++-
src/include/port/atomics.h| 36 +++
2 files changed, 75 insertions(+), 1 deletion(-)



pgsql: Make libpqsrv_cancel's return const char *, not char *

2024-04-05 Thread Alvaro Herrera
Make libpqsrv_cancel's return const char *, not char *

Per headerscheck's C++ check.

Discussion: https://postgr.es/m/372769.1712179...@sss.pgh.pa.us

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/b8b37e41ba4aae1e79dcfaeb9eb0fd7549773ff5

Modified Files
--
contrib/dblink/dblink.c | 2 +-
contrib/postgres_fdw/connection.c   | 2 +-
src/include/libpq/libpq-be-fe-helpers.h | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)



pgsql: Operate XLogCtl->log{Write,Flush}Result with atomics

2024-04-05 Thread Alvaro Herrera
Operate XLogCtl->log{Write,Flush}Result with atomics

This removes the need to hold both the info_lck spinlock and
WALWriteLock to update them.  We use stock atomic write instead, with
WALWriteLock held.  Readers can use atomic read, without any locking.

This allows for some code to be reordered: some places were a bit
contorted to avoid repeated spinlock acquisition, but that's no longer a
concern, so we can turn them to more natural coding.  Some further
changes are possible (maybe to performance wins), but in this commit I
did rather minimal ones only, to avoid increasing the blast radius.

Reviewed-by: Bharath Rupireddy 
Reviewed-by: Jeff Davis 
Reviewed-by: Andres Freund  (earlier versions)
Discussion: https://postgr.es/m/20200831182156.GA3983@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/ee1cbe806dad47674ded35427c6ba217531847d6

Modified Files
--
src/backend/access/transam/xlog.c | 107 +-
1 file changed, 59 insertions(+), 48 deletions(-)



pgsql: Split XLogCtl->LogwrtResult into separate struct members

2024-04-03 Thread Alvaro Herrera
Split XLogCtl->LogwrtResult into separate struct members

After this change we have XLogCtl->logWriteResult and ->logFlushResult.
There's no functional change, other than the fact that the assignment
from shared memory to local is no longer done via struct assignment, but
instead using a macro that copies each member separately.

The current representation is inconvenient going forward; notably, we
would like to add a new member "Copy" (to keep track of the last
position copied into WAL buffers), so the symmetry between the values in
shared memory vs. those in local would be lost.

This also gives us freedom to later change the concurrency model for the
values in shared memory: we can make them use atomics instead of relying
on the info_lck spinlock.

Reviewed-by: Bharath Rupireddy 
Discussion: https://postgr.es/m/202404031119.cd2kugjk2vho@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/c9920a9068eac2e6c8fb34988d18c0b42b9bf811

Modified Files
--
src/backend/access/transam/xlog.c | 59 +++
1 file changed, 35 insertions(+), 24 deletions(-)



pgsql: Fix zeroing of pg_serial page without SLRU bank lock

2024-04-03 Thread Alvaro Herrera
Fix zeroing of pg_serial page without SLRU bank lock

Bug in commit 53c2a97a9266: we failed to acquire the correct SLRU bank
lock when iterating to zero-out intermediate pages in predicate.c.
Rewrite the code block so that we follow the locking protocol correctly.

Also update an outdated comment in the same file -- SerialSLRULock
exists no more.

Reported-by: Alexander Lakhin 
Reviewed-by: Dilip Kumar 
Discussion: https://postgr.es/m/2a25eaf4-a3a4-5fd1-6241-9d7c73142...@gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/be2f0731006300876b008fd78a265471984cbcd9

Modified Files
--
src/backend/storage/lmgr/predicate.c | 19 ---
1 file changed, 12 insertions(+), 7 deletions(-)



pgsql: Don't use the pg_am system catalog in new test

2024-04-02 Thread Alvaro Herrera
Don't use the pg_am system catalog in new test

This causes deadlocks because it's a highly trafficked catalog.  Use a
regular table created by the same test instead.

Discussion: https://postgr.es/m/f3e61e27-19d0-5e40-3eb2-53282fa05...@gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/13b3b62746ec8bd9c8e3f0bc23862f1172996333

Modified Files
--
src/test/regress/expected/create_am.out | 4 ++--
src/test/regress/sql/create_am.sql  | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)



pgsql: Stabilize postgres_fdw test

2024-03-30 Thread Alvaro Herrera
Stabilize postgres_fdw test

The test fails when RESET statement_timeout takes longer than 10ms.
Avoid the problem by using SET LOCAL instead.

Overall, this test is not ideal: 10ms could be shorter than the time to
have sent the query to the "remote" server, so it's possible that on
some machines this test doesn't actually witness a remote query being
cancelled.  We may want to improve on this someday by using some other
testing technique, but for now it's better than nothing.  I verified
manually that one round of remote cancellation occurs when this runs on
my machine.

Discussion: 
https://postgr.es/m/CAGECzQRsdWnj=yaapcna8d7e1adbxrpbymybqrmpuijr2mp...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/ecf741cfae0603d1df269d8b799455bbcaef86e7

Modified Files
--
contrib/postgres_fdw/expected/postgres_fdw.out | 5 +++--
contrib/postgres_fdw/sql/postgres_fdw.sql  | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)



pgsql: doc: Improve "Partition Maintenance" section

2024-03-30 Thread Alvaro Herrera
doc: Improve "Partition Maintenance" section

This adds some reference links and clarifies the wording a bit.

Author: Robert Treat 
Reviewed-by: Ashutosh Bapat 
Discussion: 
https://postgr.es/m/CABV9wwNGn-pweak6_pvL5PJ1mivDNPKfg0Tck_1oTUETv5Y=d...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/056c565742742e2eafe681c0a3ee7710503a556b

Modified Files
--
doc/src/sgml/ddl.sgml | 72 +--
1 file changed, 36 insertions(+), 36 deletions(-)



pgsql: ALTER TABLE: rework determination of access method ID

2024-03-28 Thread Alvaro Herrera
ALTER TABLE: rework determination of access method ID

Avoid setting an access method OID for relation kinds that don't take
one.  Code review for new feature added in 374c7a229042.

Author: Justin Pryzby 
Reported-by: Alexander Lakhin 
Discussion: https://postgr.es/m/e5516ac1-5264-c3c0-d822-9e6f614ea...@gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/e2395cdbe83adc50ac03dd17474ee88c5a97359a

Modified Files
--
src/backend/commands/tablecmds.c| 26 +++---
src/test/regress/expected/create_am.out |  3 +++
src/test/regress/sql/create_am.sql  |  3 +++
3 files changed, 21 insertions(+), 11 deletions(-)



pgsql: Remove translation markers from libpq-be-fe-helpers.h

2024-03-28 Thread Alvaro Herrera
Remove translation markers from libpq-be-fe-helpers.h

Apparently these markers cause the modules to not link correctly in some
platforms, at least per buildfarm member indri; moreover, this code is
only used in modules that don't have a translation.  If we someday add
i18n support to contrib/ it might be worth revisiting this.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/213c959a294d56445bfe79d7f28a9b1f8a928746

Modified Files
--
src/include/libpq/libpq-be-fe-helpers.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)



pgsql: libpq-be-fe-helpers.h: wrap new cancel APIs

2024-03-28 Thread Alvaro Herrera
libpq-be-fe-helpers.h: wrap new cancel APIs

Commit 61461a300c1c introduced new functions to libpq for cancelling
queries.  This commit introduces a helper function that backend-side
libraries and extensions can use to invoke those.  This function takes a
timeout and can itself be interrupted while it is waiting for a cancel
request to be sent and processed, instead of being blocked.

This replaces the usage of the old functions in postgres_fdw and dblink.

Finally, it also adds some test coverage for the cancel support in
postgres_fdw.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/cageczqt_vgowwenuqvuv9xqmbacyxjtrrayo8w07oqashk_...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/2466d6654f85d7ec136d09d52ae22771452a19df

Modified Files
--
contrib/dblink/dblink.c| 21 ++
contrib/postgres_fdw/connection.c  | 47 +++---
contrib/postgres_fdw/expected/postgres_fdw.out | 15 +
contrib/postgres_fdw/sql/postgres_fdw.sql  |  7 ++
src/include/libpq/libpq-be-fe-helpers.h| 89 ++
5 files changed, 140 insertions(+), 39 deletions(-)



pgsql: Allow specifying an access method for partitioned tables

2024-03-25 Thread Alvaro Herrera
Allow specifying an access method for partitioned tables

It's now possible to specify a table access method via
CREATE TABLE ... USING for a partitioned table, as well change it with
ALTER TABLE ... SET ACCESS METHOD.  Specifying an AM for a partitioned
table lets the value be used for all future partitions created under it,
closely mirroring the behavior of the TABLESPACE option for partitioned
tables.  Existing partitions are not modified.

For a partitioned table with no AM specified, any new partitions are
created with the default_table_access_method.

Also add ALTER TABLE ... SET ACCESS METHOD DEFAULT, which reverts to the
original state of using the default for new partitions.

The relcache of partitioned tables is not changed: rd_tableam is not
set, even if a partitioned table has a relam set.

Author: Justin Pryzby 
Author: Soumyadeep Chakraborty 
Author: Michaël Paquier 
Reviewed-by: The authors themselves
Discussion: 
https://postgr.es/m/CAE-ML+9zM4wJCGCBGv01k96qQ3gFv4WFcFy=zqphkeaefww...@mail.gmail.com
Discussion: https://postgr.es/m/20210308010707.GA29832%40telsasoft.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/374c7a2290429eac3217b0c7b0b485db9c2bcc72

Modified Files
--
doc/src/sgml/catalogs.sgml  |  10 +-
doc/src/sgml/ref/alter_table.sgml   |  18 +++-
doc/src/sgml/ref/create_table.sgml  |   4 +
src/backend/commands/tablecmds.c| 165 ++--
src/backend/utils/cache/lsyscache.c |  22 +
src/backend/utils/cache/relcache.c  |   7 ++
src/bin/pg_dump/pg_dump.c   |   3 +-
src/bin/pg_dump/t/002_pg_dump.pl|  35 +++
src/include/catalog/pg_class.h  |   4 +-
src/include/utils/lsyscache.h   |   1 +
src/test/regress/expected/create_am.out | 158 --
src/test/regress/sql/create_am.sql  |  91 +-
12 files changed, 469 insertions(+), 49 deletions(-)



Re: pgsql: Do not translate dummy SpecialJoinInfos for child joins

2024-03-25 Thread Alvaro Herrera
On 2024-Mar-25, Amit Langote wrote:

> I noticed a failure that I don't know what to make of after this and
> the other commit (5278d0a2e) reached the buildfarm animal morepork:
> 
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=morepork=2024-03-25%2009%3A30%3A38
> 
> In file included from ginbtree.c:17:
> In file included from ../../../../src/include/access/gin_private.h:20:
> ../../../../src/include/lib/rbtree.h:1:1: error: unknown type name 'ator'
> ator yes_or_no
> ^

Surely this is a kernel bug.  This text appears in
doc/src/sgml/information_schema.sgml and nowhere else.  The animal is
now green, so I don't think you need to do anything about this.

-- 
Álvaro HerreraBreisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Digital and video cameras have this adjustment and film cameras don't for the
same reason dogs and cats lick themselves: because they can."   (Ken Rockwell)




pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
REL_12_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/58efabdc0ce932c9e927d8616f25e0e1f651b601

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/ea299d78251144a99f9fe16cd619386919f8312b

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/33bfbef1d60fdccbfb72423b2e1e7c4074a640b9

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
REL_13_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/520e7afa5732b0ba27b55f99dbabeea5e2591bb7

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/e6c4e01bf4405ea779ec0b942d7eaa81e18423e1

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Review wording on tablespaces w.r.t. partitioned tables

2024-03-20 Thread Alvaro Herrera
Review wording on tablespaces w.r.t. partitioned tables

Remove a redundant comment, and document pg_class.reltablespace properly
in catalogs.sgml.

After commits a36c84c3e4a9, 87259588d0ab and others.

Backpatch to 12.

Discussion: https://postgr.es/m/202403191013.w2kr7wqlamqz@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a0390f6ca6c730949577e0d3c1fde7a77696ca17

Modified Files
--
doc/src/sgml/catalogs.sgml   | 9 ++---
src/backend/commands/tablecmds.c | 4 
2 files changed, 6 insertions(+), 7 deletions(-)



pgsql: Rework lwlocknames.txt to become lwlocklist.h

2024-03-20 Thread Alvaro Herrera
Rework lwlocknames.txt to become lwlocklist.h

This way, we can fold the list of lock names to occur in
BuiltinTrancheNames instead of having its own separate array.  This
saves two lines of code in GetLWTrancheName and some space in
BuiltinTrancheNames, as foreseen in commit 74a730631065, as well as
removing the need for a separate lwlocknames.c file.

We still have to build lwlocknames.h using Perl code, which initially I
wanted to avoid, but it gives us the chance to cross-check
wait_event_names.txt.

Discussion: https://postgr.es/m/202401231025.gbv4nnte5fmm@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/da952b415ffcc85ea79c3f006af142d3c90a

Modified Files
--
src/backend/Makefile |  4 +-
src/backend/storage/lmgr/.gitignore  |  1 -
src/backend/storage/lmgr/Makefile|  9 +--
src/backend/storage/lmgr/generate-lwlocknames.pl | 60 -
src/backend/storage/lmgr/lwlock.c| 15 ++---
src/backend/storage/lmgr/lwlocknames.txt | 60 -
src/backend/storage/lmgr/meson.build |  2 -
src/backend/utils/activity/wait_event_names.txt  |  8 +--
src/include/storage/lwlock.h |  4 +-
src/include/storage/lwlocklist.h | 85 
src/include/storage/meson.build  | 12 ++--
src/tools/pginclude/headerscheck |  1 +
12 files changed, 136 insertions(+), 125 deletions(-)



pgsql: dblink/isolationtester/fe_utils: Use new cancel API

2024-03-18 Thread Alvaro Herrera
dblink/isolationtester/fe_utils: Use new cancel API

Commit 61461a300c1c introduced new functions to libpq for cancelling
queries.  This replaces the usage of the old ones in parts of the
codebase with these newer ones.  This specifically leaves out changes to
psql and pgbench, as those would need a much larger refactor to be able
to call them due to the new functions not being signal-safe; and also
postgres_fdw, because the original code there is not clear to me
(Álvaro) and not fully tested.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/cageczqt_vgowwenuqvuv9xqmbacyxjtrrayo8w07oqashk_...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/66ab9371a23320cf608e68e8e5d2811992941bea

Modified Files
--
contrib/dblink/dblink.c  | 26 --
src/fe_utils/connect_utils.c | 11 +++
src/test/isolation/isolationtester.c | 29 -
3 files changed, 31 insertions(+), 35 deletions(-)



pgsql: Put libpq_pipeline cancel test back

2024-03-18 Thread Alvaro Herrera
Put libpq_pipeline cancel test back

I disabled it in cc6e64afda53 because it was unstable; hopefully the
changes here make it more stable.  (Jelte proposed to submit the queries
using simple query protocol, but I chose to instead make the monitor
connection wait until the PgSleep wait event is seen.  This is probably
not a terribly meaningful increase in coverage ...)

Discussion: 
https://postgr.es/m/CAGECzQRQh_5tSy+5cndgv08eNJ2O0Zpwn2YddJtSsmC=wpy...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/6b3678d3474ff456b3229e4829c595be1c0c2888

Modified Files
--
src/test/modules/libpq_pipeline/libpq_pipeline.c | 37 ++--
1 file changed, 22 insertions(+), 15 deletions(-)



pgsql: Comment out noisy libpq_pipeline test

2024-03-14 Thread Alvaro Herrera
Comment out noisy libpq_pipeline test

libpq_pipeline's new 'cancel' test needs more research; disable it
temporarily to prevent measles in the buildfarm.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/cc6e64afda530576d83e331365d36c758495a7cd

Modified Files
--
src/test/modules/libpq_pipeline/libpq_pipeline.c | 3 +++
1 file changed, 3 insertions(+)



pgsql: Hopefully make libpq_pipeline's new cancel test more reliable

2024-03-13 Thread Alvaro Herrera
Hopefully make libpq_pipeline's new cancel test more reliable

The newly introduced cancel test in libpq_pipeline was flaky. It's not
completely clear why, but one option is that the check for "active" was
actually seeing the active state for the previous query. This change
should address any such race condition by first waiting until the
connection is reported as idle.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/cageczqrvmuk5-d68a+cm+fgmfht9dv2uz28-qq3qiaf6eaz...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/1ee910ce437188eab40eddf32dc7d81952e99f82

Modified Files
--
src/test/modules/libpq_pipeline/libpq_pipeline.c | 78 +++-
1 file changed, 49 insertions(+), 29 deletions(-)



pgsql: libpq: Add encrypted and non-blocking query cancellation routine

2024-03-12 Thread Alvaro Herrera
libpq: Add encrypted and non-blocking query cancellation routines

The existing PQcancel API uses blocking IO, which makes PQcancel
impossible to use in an event loop based codebase without blocking the
event loop until the call returns.  It also doesn't encrypt the
connection over which the cancel request is sent, even when the original
connection required encryption.

This commit adds a PQcancelConn struct and assorted functions, which
provide a better mechanism of sending cancel requests; in particular all
the encryption used in the original connection are also used in the
cancel connection.  The main entry points are:

- PQcancelCreate creates the PQcancelConn based on the original
  connection (but does not establish an actual connection).
- PQcancelStart can be used to initiate non-blocking cancel requests,
  using encryption if the original connection did so, which must be
  pumped using
- PQcancelPoll.
- PQcancelReset puts a PQcancelConn back in state so that it can be
  reused to send a new cancel request to the same connection.
- PQcancelBlocking is a simpler-to-use blocking API that still uses
  encryption.

Additional functions are
 - PQcancelStatus, mimicks PQstatus;
 - PQcancelSocket, mimicks PQcancelSocket;
 - PQcancelErrorMessage, mimicks PQerrorMessage;
 - PQcancelFinish, mimicks PQfinish.

Author: Jelte Fennema-Nio 
Reviewed-by: Denis Laxalde 
Discussion: 
https://postgr.es/m/am5pr83mb0178d3b31ca1b6ec4a8ecc42f7...@am5pr83mb0178.eurprd83.prod.outlook.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/61461a300c1cb5d53955ecd792ad0ce75a104736

Modified Files
--
doc/src/sgml/libpq.sgml  | 507 +--
src/interfaces/libpq/exports.txt |   9 +
src/interfaces/libpq/fe-cancel.c | 296 -
src/interfaces/libpq/fe-connect.c| 129 +-
src/interfaces/libpq/libpq-fe.h  |  31 +-
src/interfaces/libpq/libpq-int.h |   5 +
src/test/modules/libpq_pipeline/libpq_pipeline.c | 121 ++
src/tools/pgindent/typedefs.list |   1 +
8 files changed, 1044 insertions(+), 55 deletions(-)



pgsql: libpq: Move pg_cancel to fe-cancel.c

2024-03-12 Thread Alvaro Herrera
libpq: Move pg_cancel to fe-cancel.c

No other files need to access this struct, so there is no need to have
its definition in a header file.

Author: Jelte Fennema-Nio 
Discussion: https://postgr.es/m/202403061822.spfzqbf7dsgg@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/4dec98c2af64851b643af14c36c8b99215dfd70d

Modified Files
--
src/interfaces/libpq/fe-cancel.c | 20 
src/interfaces/libpq/libpq-int.h | 18 --
2 files changed, 20 insertions(+), 18 deletions(-)



pgsql: Add tests for libpq query cancellation APIs

2024-03-11 Thread Alvaro Herrera
Add tests for libpq query cancellation APIs

This is in preparation of making changes and additions to these APIs.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/CAGECzQRb21spiiykQ48rzz8w+Hcykz+mB2_hxR65D9Qk6nnw=w...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/319e9e53f3797fe4a4753b54a98ab717bb2f2ca0

Modified Files
--
src/test/modules/libpq_pipeline/libpq_pipeline.c | 175 ++-
1 file changed, 173 insertions(+), 2 deletions(-)



pgsql: Add missing connection statuses to docs

2024-03-11 Thread Alvaro Herrera
Add missing connection statuses to docs

The list of connection statuses that PQstatus might return during an
asynchronous connection attempt was outdated:

1. CONNECTION_SETENV is never returned anymore and is only part of the
   enum for backwards compatibility, so remove it from the docs.
2. CONNECTION_CHECK_STANDBY and CONNECTION_GSS_STARTUP were not listed,
   so add them.

CONNECTION_NEEDED and CONNECTION_CHECK_TARGET are not listed in the docs
on purpose, since these are internal states that can never be observed
by a caller of PQstatus.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/CAGECzQRb21spiiykQ48rzz8w+Hcykz+mB2_hxR65D9Qk6nnw=w...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/095493a3771a99d0e4c906ad1cc33791efaa7248

Modified Files
--
doc/src/sgml/libpq.sgml | 15 ---
src/interfaces/libpq/libpq-fe.h |  5 +++--
2 files changed, 15 insertions(+), 5 deletions(-)



pgsql: Admit deferrable PKs into rd_pkindex, but flag them as such

2024-03-08 Thread Alvaro Herrera
Admit deferrable PKs into rd_pkindex, but flag them as such

... and in particular don't return them as replica identity.

The motivation for this change is letting the primary keys be seen by
code that derives NOT NULL constraints from them, when creating
inheritance children; before this change, if you had a deferrable PK,
pg_dump would not recreate the attnotnull marking properly, because the
column would not be considered as having anything to back said marking
after dropping the throwaway NOT NULL constraint.

The reason we don't want these PKs as replica identities is that
replication can corrupt data, if the uniqueness constraint is
transiently broken.

Reported-by: Amul Sul 
Reviewed-by: Dean Rasheed 
Discussion: 
https://postgr.es/m/caaj_b94qonkgsbdxofakhdnorqngafd1y3oa5qxfpqnjyxy...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/270af6f0df764d326e1a7355f4ce10dc73b05dac

Modified Files
--
src/backend/replication/logical/relation.c |  6 +-
src/backend/utils/cache/relcache.c | 27 ++--
src/include/utils/rel.h|  3 +-
src/test/regress/expected/constraints.out  | 92 ++
src/test/regress/expected/publication.out  | 10 +++
src/test/regress/expected/replica_identity.out |  5 ++
src/test/regress/sql/constraints.sql   | 25 +++
src/test/regress/sql/publication.sql   |  9 +++
src/test/regress/sql/replica_identity.sql  |  4 ++
9 files changed, 170 insertions(+), 11 deletions(-)



Re: pgsql: Add template for adaptive radix tree

2024-03-07 Thread Alvaro Herrera
On 2024-Mar-07, John Naylor wrote:

> Understandably so. FWIW, the use case proposed by the authors was for
> secondary indexes within in-memory databases, not as a type of
> associative array. I'm unable to find patents for the thing itself,
> but IANAL. I believe I've been in contact with some of the same
> authors about a different subject, and they seemed open to people
> trying to implement their ideas (it was a different paper, to be sure,
> and unfortunately I no longer email account).

Well, surely we can email them.  Their profiles show they're still
active.
https://db.in.tum.de/people/sites/kemper/?lang=en
https://db.in.tum.de/people/sites/neumann/?lang=en
https://db.in.tum.de/people/sites/leis/?lang=en

-- 
Álvaro Herrera   48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Pido que me den el Nobel por razones humanitarias" (Nicanor Parra)




pgsql: Fix misspelled assertions

2024-03-05 Thread Alvaro Herrera
Fix misspelled assertions

Remove an extra & operator, per Tom Lane.  My bugs, introduced with
commit 53c2a97a9266.

Discussion: https://postgr.es/m/3885480.1709590...@sss.pgh.pa.us

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/0d3a71d0c8a762247cf558cf41847e599a1f5539

Modified Files
--
src/backend/access/transam/slru.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)



pgsql: Rework redundant code in subtrans.c

2024-03-05 Thread Alvaro Herrera
Rework redundant code in subtrans.c

When this code was written the duplicity didn't matter, but with all the
SLRU-bank stuff we just added, it has become excessive.  Turn it into a
simpler loop with no code duplication.  Also add a test so that this
code becomes covered.

Discussion: https://postgr.es/m/202403041517.3a35jw53os65@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/1a2654b32b546d25e39a0c02410049559a3d4573

Modified Files
--
src/backend/access/transam/subtrans.c | 29 ++--
src/test/recovery/t/009_twophase.pl   | 42 +++
2 files changed, 49 insertions(+), 22 deletions(-)



pgsql: Rework locking code in GetMultiXactIdMembers

2024-03-04 Thread Alvaro Herrera
Rework locking code in GetMultiXactIdMembers

After commit 53c2a97a9266, the code flow around the "retry" goto label
in GetMultiXactIdMembers was confused about what was possible: we never
return there with a held lock, so there's no point in testing for one.
This realization lets us simplify the code a bit.  While at it, make the
scope of a couple of local variables in the same function a bit tighter.

Per Coverity.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a0b808baef39e9f9465b7f63f2d735f35852aa21

Modified Files
--
src/backend/access/transam/multixact.c | 53 ++
1 file changed, 22 insertions(+), 31 deletions(-)



pgsql: Simplify coding in slru.c

2024-03-04 Thread Alvaro Herrera
Simplify coding in slru.c

New code in 53c2a97a9266 uses direct array access to
shared->bank_locks[bankno].lock which can be made a little bit more
legible by using the SimpleLruGetBankLock helper function.
Nothing terribly serious, but let's add some clarity.

Discussion: https://postgr.es/m/202403041517.3a35jw53os65@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/f9baaf96d3395c3afc2c558fb74279c4923ddb24

Modified Files
--
src/backend/access/transam/slru.c | 18 +-
1 file changed, 9 insertions(+), 9 deletions(-)



Re: pgsql: Remove the adminpack contrib extension

2024-03-04 Thread Alvaro Herrera
On 2024-Mar-04, Daniel Gustafsson wrote:

> The pg_upgrade Xversion test on crake failed on this, I'm trying to reproduce
> the cross-version test locally to verify the below diff but it's right now
> failing on an unrelated thing.

What unrelated thing?  I suggest to try to initdb the old version with
the current REL_12_STABLE branch tip, because IIRC there are changes
that cause the pg_upgrade test to fail.

-- 
Álvaro Herrera PostgreSQL Developer  —  https://www.EnterpriseDB.com/
Y una voz del caos me habló y me dijo
"Sonríe y sé feliz, podría ser peor".
Y sonreí. Y fui feliz.
Y fue peor.




pgsql: GUC table: Add description to computed variables

2024-03-03 Thread Alvaro Herrera
GUC table: Add description to computed variables

Per suggestion from Kyotaro Horiguchi
Discussion: 
https://postgr.es/m/20240229.130404.1411153273308142188.horikyota@gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/30b8d6e4ce1112168ddfe8cdbba76fbefd304b34

Modified Files
--
src/backend/utils/misc/guc_tables.c | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Improve performance of subsystems on top of SLRU

2024-02-28 Thread Alvaro Herrera
Improve performance of subsystems on top of SLRU

More precisely, what we do here is make the SLRU cache sizes
configurable with new GUCs, so that sites with high concurrency and big
ranges of transactions in flight (resp. multixacts/subtransactions) can
benefit from bigger caches.  In order for this to work with good
performance, two additional changes are made:

1. the cache is divided in "banks" (to borrow terminology from CPU
   caches), and algorithms such as eviction buffer search only affect
   one specific bank.  This forestalls the problem that linear searching
   for a specific buffer across the whole cache takes too long: we only
   have to search the specific bank, whose size is small.  This work is
   authored by Andrey Borodin.

2. Change the locking regime for the SLRU banks, so that each bank uses
   a separate LWLock.  This allows for increased scalability.  This work
   is authored by Dilip Kumar.  (A part of this was previously committed as
   d172b717c6f4.)

Special care is taken so that the algorithms that can potentially
traverse more than one bank release one bank's lock before acquiring the
next.  This should happen rarely, but particularly clog.c's group commit
feature needed code adjustment to cope with this.  I (Álvaro) also added
lots of comments to make sure the design is sound.

The new GUCs match the names introduced by bcdfa5f2e2f2 in the
pg_stat_slru view.

The default values for these parameters are similar to the previous
sizes of each SLRU.  commit_ts, clog and subtrans accept value 0, which
means to adjust by dividing shared_buffers by 512 (so 2MB for every 1GB
of shared_buffers), with a cap of 8MB.  (A new slru.c function
SimpleLruAutotuneBuffers() was added to support this.)  The cap was
previously 1MB for clog, so for sites with more than 512MB of shared
memory the total memory used increases, which is likely a good tradeoff.
However, other SLRUs (notably multixact ones) retain smaller sizes and
don't support a configured value of 0.  These values based on
shared_buffers may need to be revisited, but that's an easy change.

There was some resistance to adding these new GUCs: it would be better
to adjust to memory pressure automatically somehow, for example by
stealing memory from shared_buffers (where the caches can grow and
shrink naturally).  However, doing that seems to be a much larger
project and one which has made virtually no progress in several years,
and because this is such a pain point for so many users, here we take
the pragmatic approach.

Author: Andrey Borodin 
Author: Dilip Kumar 
Reviewed-by: Amul Sul, Gilles Darold, Anastasia Lubennikova,
Ivan Lazarev, Robert Haas, Thomas Munro, Tomas Vondra,
Yura Sokolov, Васильев Дмитрий (Dmitry Vasiliev).
Discussion: 
https://postgr.es/m/2bec2b3f-9b61-4c1d-9fb5-5fab0f05e...@yandex-team.ru
Discussion: 
https://postgr.es/m/CAFiTN-vzDvNz=exgxz6gdyjtzgixksqs0mkhmmaq8sosefz...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/53c2a97a92665be6bd7d70bd62ae6158fe4db96e

Modified Files
--
doc/src/sgml/config.sgml| 139 +
doc/src/sgml/monitoring.sgml|   9 +-
src/backend/access/transam/clog.c   | 243 +++-
src/backend/access/transam/commit_ts.c  |  88 --
src/backend/access/transam/multixact.c  | 190 +
src/backend/access/transam/slru.c   | 357 +---
src/backend/access/transam/subtrans.c   | 110 ++--
src/backend/commands/async.c|  61 ++--
src/backend/storage/lmgr/lwlock.c   |   9 +-
src/backend/storage/lmgr/lwlocknames.txt|  14 +-
src/backend/storage/lmgr/predicate.c|  34 ++-
src/backend/utils/activity/wait_event_names.txt |  15 +-
src/backend/utils/init/globals.c|   9 +
src/backend/utils/misc/guc_tables.c |  78 ++
src/backend/utils/misc/postgresql.conf.sample   |   9 +
src/include/access/clog.h   |   1 -
src/include/access/commit_ts.h  |   1 -
src/include/access/multixact.h  |   4 -
src/include/access/slru.h   |  86 --
src/include/access/subtrans.h   |   3 -
src/include/commands/async.h|   5 -
src/include/miscadmin.h |   8 +
src/include/storage/lwlock.h|   7 +
src/include/storage/predicate.h |   4 -
src/include/utils/guc_hooks.h   |  11 +
src/test/modules/test_slru/test_slru.c  |  35 +--
26 files changed, 1177 insertions(+), 353 deletions(-)



pgsql: Rename SLRU elements in view pg_stat_slru

2024-02-28 Thread Alvaro Herrera
Rename SLRU elements in view pg_stat_slru

The new names are intended to match those in an upcoming patch that adds
a few GUCs to configure the SLRU buffer sizes.

Backwards compatibility concern: this changes the accepted names for
function pg_stat_slru_rest().  Since this function recognizes "any other
string" as a request to reset the entry for "other", this means that
calling it with the old names would silently reset "other" instead of
doing nothing or throwing an error.

Reviewed-by: Andrey M. Borodin 
Discussion: https://postgr.es/m/202402261616.dlriae7b6emv@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/bcdfa5f2e2f274caeed20b2f986012a9cb6a259c

Modified Files
--
doc/src/sgml/monitoring.sgml| 14 +--
src/backend/access/transam/clog.c   |  2 +-
src/backend/access/transam/commit_ts.c  |  2 +-
src/backend/access/transam/multixact.c  |  4 +--
src/backend/access/transam/subtrans.c   |  2 +-
src/backend/commands/async.c|  2 +-
src/backend/storage/lmgr/predicate.c|  2 +-
src/include/utils/pgstat_internal.h | 14 +--
src/test/isolation/expected/stats.out   | 44 -
src/test/isolation/expected/stats_1.out | 44 -
src/test/isolation/specs/stats.spec |  4 +--
src/test/regress/expected/stats.out | 14 +--
src/test/regress/sql/stats.sql  | 14 +--
13 files changed, 81 insertions(+), 81 deletions(-)



pgsql: Revise MERGE documentation

2024-02-26 Thread Alvaro Herrera
Revise MERGE documentation

Add a note about the additional privileges required after the fix in
4989ce72644b (wording per Tom Lane); also change marked-up mentions of
"target_table_name" to be simply "the target table" or the like.  Also,
note that "join_condition" is scouted for requisite privileges.

Backpatch to 15.

Discussion: https://postgr.es/m/202402211653.zuh6objy3z72@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/6979ea2638a51c40acf6d04b816550b2c35b3e55

Modified Files
--
doc/src/sgml/ref/merge.sgml | 50 +++--
1 file changed, 26 insertions(+), 24 deletions(-)



pgsql: Revise MERGE documentation

2024-02-26 Thread Alvaro Herrera
Revise MERGE documentation

Add a note about the additional privileges required after the fix in
4989ce72644b (wording per Tom Lane); also change marked-up mentions of
"target_table_name" to be simply "the target table" or the like.  Also,
note that "join_condition" is scouted for requisite privileges.

Backpatch to 15.

Discussion: https://postgr.es/m/202402211653.zuh6objy3z72@alvherre.pgsql

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/172d7f7e666ee0612b7d56d7b73a7ebc98476a66

Modified Files
--
doc/src/sgml/ref/merge.sgml | 50 +++--
1 file changed, 26 insertions(+), 24 deletions(-)



pgsql: Revise MERGE documentation

2024-02-26 Thread Alvaro Herrera
Revise MERGE documentation

Add a note about the additional privileges required after the fix in
4989ce72644b (wording per Tom Lane); also change marked-up mentions of
"target_table_name" to be simply "the target table" or the like.  Also,
note that "join_condition" is scouted for requisite privileges.

Backpatch to 15.

Discussion: https://postgr.es/m/202402211653.zuh6objy3z72@alvherre.pgsql

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/c4bd6ff57c9a7b188cbd93855755f1029d7a5662

Modified Files
--
doc/src/sgml/ref/merge.sgml | 50 +++--
1 file changed, 26 insertions(+), 24 deletions(-)



pgsql: slru.c: Reduce scope of variables in 'for' blocks

2024-02-26 Thread Alvaro Herrera
slru.c: Reduce scope of variables in 'for' blocks

Pretty boring.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/5f79cb7629a4ce6321f509694ebf475a931608b6

Modified Files
--
src/backend/access/transam/slru.c | 33 +++--
1 file changed, 11 insertions(+), 22 deletions(-)



pgsql: MERGE ... DO NOTHING: require SELECT privileges

2024-02-21 Thread Alvaro Herrera
MERGE ... DO NOTHING: require SELECT privileges

Verify that a user running MERGE with a DO NOTHING clause has
privileges to read the table, even if no columns are referenced.  Such
privileges were already required if the ON clause or any of the WHEN
conditions referenced any column at all, so there's no functional change
in practice.

This change fixes an assertion failure in the case where no column is
referenced by the command and the WHEN clauses are all DO NOTHING.

Backpatch to 15, where MERGE was introduced.

Reported-by: Alena Rybakina 
Reported-by: Alexander Lakhin 
Discussion: 
https://postgr.es/m/4d65a385-7efa-4436-a825-0869f89d9...@postgrespro.ru

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/90ad85db6a4e06c517c72de84e725c0222e0c529

Modified Files
--
src/backend/parser/parse_merge.c|  7 ++-
src/test/regress/expected/merge.out | 10 ++
src/test/regress/sql/merge.sql  | 11 +++
3 files changed, 27 insertions(+), 1 deletion(-)



pgsql: Fix typo

2024-02-21 Thread Alvaro Herrera
Fix typo

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/ed345c2728b3ebc160d8335464765679a08031b9

Modified Files
--
src/backend/tcop/postgres.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: MERGE ... DO NOTHING: require SELECT privileges

2024-02-21 Thread Alvaro Herrera
MERGE ... DO NOTHING: require SELECT privileges

Verify that a user running MERGE with a DO NOTHING clause has
privileges to read the table, even if no columns are referenced.  Such
privileges were already required if the ON clause or any of the WHEN
conditions referenced any column at all, so there's no functional change
in practice.

This change fixes an assertion failure in the case where no column is
referenced by the command and the WHEN clauses are all DO NOTHING.

Backpatch to 15, where MERGE was introduced.

Reported-by: Alena Rybakina 
Reported-by: Alexander Lakhin 
Discussion: 
https://postgr.es/m/4d65a385-7efa-4436-a825-0869f89d9...@postgrespro.ru

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/a3f5d2056ceba95d94607be3138fa52499a957e6

Modified Files
--
src/backend/parser/parse_merge.c|  7 ++-
src/test/regress/expected/merge.out | 10 ++
src/test/regress/sql/merge.sql  | 11 +++
3 files changed, 27 insertions(+), 1 deletion(-)



pgsql: MERGE ... DO NOTHING: require SELECT privileges

2024-02-21 Thread Alvaro Herrera
MERGE ... DO NOTHING: require SELECT privileges

Verify that a user running MERGE with a DO NOTHING clause has
privileges to read the table, even if no columns are referenced.  Such
privileges were already required if the ON clause or any of the WHEN
conditions referenced any column at all, so there's no functional change
in practice.

This change fixes an assertion failure in the case where no column is
referenced by the command and the WHEN clauses are all DO NOTHING.

Backpatch to 15, where MERGE was introduced.

Reported-by: Alena Rybakina 
Reported-by: Alexander Lakhin 
Discussion: 
https://postgr.es/m/4d65a385-7efa-4436-a825-0869f89d9...@postgrespro.ru

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/4989ce72644b9d636b9b23c7a1719a405e62670b

Modified Files
--
src/backend/parser/parse_merge.c|  7 ++-
src/test/regress/expected/merge.out | 10 ++
src/test/regress/sql/merge.sql  | 11 +++
3 files changed, 27 insertions(+), 1 deletion(-)



pgsql: Update PQparameterStatus and ParameterStatus docs

2024-02-07 Thread Alvaro Herrera
Update PQparameterStatus and ParameterStatus docs

Cover scram_iterations, which was added in commit b577743000cd.  While
at it, turn the list into a  with 2 columns, which is much
nicer to read.

In master, remove mentions of antediluvian versions before which some
parameters were not reported.

Noticed while investigating a question by Maiquel Grassi.

Backpatch to 16.

Reviewed-by: Daniel Gustafsson 
Reviewed-by: Jelte Fennema-Nio 
Discussion: https://postgr.es/m/202401301236.mc5ebrohhtsd@alvherre.pgsql

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/17f3196599303abbfc605f5ea5c5e314ce856e38

Modified Files
--
doc/src/sgml/libpq.sgml| 34 +++---
doc/src/sgml/protocol.sgml | 34 +++---
2 files changed, 38 insertions(+), 30 deletions(-)



pgsql: Update PQparameterStatus and ParameterStatus docs

2024-02-07 Thread Alvaro Herrera
Update PQparameterStatus and ParameterStatus docs

Cover scram_iterations, which was added in commit b577743000cd.  While
at it, turn the list into a  with 2 columns, which is much
nicer to read.

In master, remove mentions of antediluvian versions before which some
parameters were not reported.

Noticed while investigating a question by Maiquel Grassi.

Backpatch to 16.

Reviewed-by: Daniel Gustafsson 
Reviewed-by: Jelte Fennema-Nio 
Discussion: https://postgr.es/m/202401301236.mc5ebrohhtsd@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a39f1a365a3b99149ba0038ef7e39d6bff2560c9

Modified Files
--
doc/src/sgml/libpq.sgml| 43 ---
doc/src/sgml/protocol.sgml | 43 ---
2 files changed, 40 insertions(+), 46 deletions(-)



pgsql: Change initial use of pg_atomic_write_u64 to init

2024-02-06 Thread Alvaro Herrera
Change initial use of pg_atomic_write_u64 to init

This only matters when using atomics emulation with semaphores.

Per buildfarm member rorqual.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/e4b27b53552c19c50b3ca00b697a1f745c247d0d

Modified Files
--
src/backend/access/transam/slru.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



Re: pgsql: Use atomic access for SlruShared->latest_page_number

2024-02-06 Thread Alvaro Herrera
On 2024-Feb-06, Alvaro Herrera wrote:

> Use atomic access for SlruShared->latest_page_number

rorqual failed (--disable-atomics --disable-spinlocks).  Looking into it ...

-- 
Álvaro HerreraBreisgau, Deutschland  —  https://www.EnterpriseDB.com/
"Nunca se desea ardientemente lo que solo se desea por razón" (F. Alexandre)




pgsql: Use atomic access for SlruShared->latest_page_number

2024-02-06 Thread Alvaro Herrera
Use atomic access for SlruShared->latest_page_number

The new concurrency model proposed for slru.c to improve performance
does not include any single lock that would coordinate processes
doing concurrent reads/writes on SlruShared->latest_page_number.
We can instead use atomic reads and writes for that variable.

Author: Dilip Kumar 
Reviewed-by: Andrey M. Borodin 
Discussion: 
https://postgr.es/m/CAFiTN-vzDvNz=exgxz6gdyjtzgixksqs0mkhmmaq8sosefz...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d172b717c6f436738cc8383a4e9f611ae227fd93

Modified Files
--
src/backend/access/transam/clog.c  |  6 +-
src/backend/access/transam/commit_ts.c |  7 +++---
src/backend/access/transam/multixact.c | 28 ++--
src/backend/access/transam/slru.c  | 39 --
src/include/access/slru.h  |  5 -
5 files changed, 53 insertions(+), 32 deletions(-)



pgsql: libpq: Change some static functions to extern

2024-02-04 Thread Alvaro Herrera
libpq: Change some static functions to extern

This is in preparation of a follow up commit that starts using these
functions from fe-cancel.c.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/am5pr83mb0178d3b31ca1b6ec4a8ecc42f7...@am5pr83mb0178.eurprd83.prod.outlook.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/774bcffe4a9853a24e61d758637c0aad2871f1fb

Modified Files
--
src/interfaces/libpq/fe-connect.c | 87 ++-
src/interfaces/libpq/libpq-int.h  |  5 +++
2 files changed, 46 insertions(+), 46 deletions(-)



pgsql: libpq: Add pqReleaseConnHosts function

2024-02-04 Thread Alvaro Herrera
libpq: Add pqReleaseConnHosts function

In a follow up commit we'll need to free this connhost field in a
function defined in fe-cancel.c, so here we extract the logic to a
dedicated extern function.

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/am5pr83mb0178d3b31ca1b6ec4a8ecc42f7...@am5pr83mb0178.eurprd83.prod.outlook.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/53747f78d2cd4d7054c4d509b27dc89306ae

Modified Files
--
src/interfaces/libpq/fe-connect.c | 39 ++-
src/interfaces/libpq/libpq-int.h  |  1 +
2 files changed, 27 insertions(+), 13 deletions(-)



pgsql: Fix copy typo in comment

2024-01-31 Thread Alvaro Herrera
Fix copy typo in comment

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/402388946fb3ac54f0fd5944d7e177ef7737eab2

Modified Files
--
src/backend/storage/lmgr/lwlock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Update pg_walsummary copyright notices to 2024

2024-01-31 Thread Alvaro Herrera
Update pg_walsummary copyright notices to 2024

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/f0106b6d2dc28660d9ecba3de77cee14de921c94

Modified Files
--
src/bin/pg_walsummary/Makefile| 2 +-
src/bin/pg_walsummary/meson.build | 2 +-
src/bin/pg_walsummary/pg_walsummary.c | 2 +-
src/bin/pg_walsummary/t/001_basic.pl  | 2 +-
src/bin/pg_walsummary/t/002_blocks.pl | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)



pgsql: Split use of SerialSLRULock, creating SerialControlLock

2024-01-30 Thread Alvaro Herrera
Split use of SerialSLRULock, creating SerialControlLock

predicate.c has been using SerialSLRULock (the control lock for its SLRU
structure) to coordinate access to SerialControlData, another of its
numerous shared memory structures; this is unnecessary and confuses
further SLRU scalability work.  Create a separate LWLock to cover
SerialControlData.

Extracted from a larger patch from the same author, and some additional
changes by Álvaro.

Author: Dilip Kumar 
Discussion: 
https://postgr.es/m/CAFiTN-vzDvNz=exgxz6gdyjtzgixksqs0mkhmmaq8sosefz...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/7b745d85b80d4492c4df8d9769592c7aad1f63d2

Modified Files
--
src/backend/storage/lmgr/lwlocknames.txt|  1 +
src/backend/storage/lmgr/predicate.c| 41 ++---
src/backend/utils/activity/wait_event_names.txt |  1 +
3 files changed, 32 insertions(+), 11 deletions(-)



pgsql: Add EXPLAIN (MEMORY) to report planner memory consumption

2024-01-29 Thread Alvaro Herrera
Add EXPLAIN (MEMORY) to report planner memory consumption

This adds a new "Memory:" line under the "Planning:" group (which
currently only has "Buffers:") when the MEMORY option is specified.

In order to make the reporting reasonably accurate, we create a separate
memory context for planner activities, to be used only when this option
is given.  The total amount of memory allocated by that context is
reported as "allocated"; we subtract memory in the context's freelists
from that and report that result as "used".  We use
MemoryContextStatsInternal() to obtain the quantities.

The code structure to show buffer usage during planning was not in
amazing shape, so I (Álvaro) modified the patch a bit to clean that up
in passing.

Author: Ashutosh Bapat
Reviewed-by: David Rowley, Andrey Lepikhov, Jian He, Andy Fan
Discussion: 
https://www.postgresql.org/message-id/CAExHW5sZA=5lj_zppro-w09ck8z9p7eayaqq3ks9gdfhrxe...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/5de890e3610d5a12cdaea36413d967cf5c544e20

Modified Files
--
contrib/auto_explain/auto_explain.c   |   2 +
doc/src/sgml/ref/explain.sgml |  14 
src/backend/commands/explain.c| 152 --
src/backend/commands/prepare.c|  22 -
src/backend/utils/mmgr/mcxt.c |  13 +++
src/include/commands/explain.h|   4 +-
src/include/utils/memutils.h  |   2 +
src/test/regress/expected/explain.out |  76 +
src/test/regress/sql/explain.sql  |   8 ++
9 files changed, 265 insertions(+), 28 deletions(-)



pgsql: libpq: Move cancellation related functions to fe-cancel.c

2024-01-29 Thread Alvaro Herrera
libpq: Move cancellation related functions to fe-cancel.c

In follow up commits we'll add more functions related to query
cancellations.  This groups those all together instead of mixing them
with the other functions in fe-connect.c.

The formerly static parse_int_param() function had to be exported to
other libpq users, so it's been renamed pqParseIntParam() and moved to a
more reasonable place within fe-connect.c (rather than randomly between
various keepalive-related routines).

Author: Jelte Fennema-Nio 
Discussion: 
https://postgr.es/m/am5pr83mb0178d3b31ca1b6ec4a8ecc42f7...@am5pr83mb0178.eurprd83.prod.outlook.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/6d4565a05f3fb9b7a439e7ecfc2be68bf4dabf48

Modified Files
--
src/interfaces/libpq/Makefile |   1 +
src/interfaces/libpq/fe-cancel.c  | 387 ++
src/interfaces/libpq/fe-connect.c | 483 +-
src/interfaces/libpq/libpq-int.h  |   5 +
src/interfaces/libpq/meson.build  |   1 +
5 files changed, 451 insertions(+), 426 deletions(-)



pgsql: Make spelling of cancelled/cancellation consistent

2024-01-26 Thread Alvaro Herrera
Make spelling of cancelled/cancellation consistent

This fixes places where words derived from cancel were not using their
common en-US ugly^H^H^H^Hspelling.

Author: Jelte Fennema-Nio 
Reported-by: Thomas Munro 
Discussion: 
https://postgr.es/m/ca+hukg+lrq+ty6ywxf5572qnq8kwxgwg5n4fseccuap685n...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/8c9da1441df18bd609f025778e8349873a3e9bbd

Modified Files
--
doc/src/sgml/event-trigger.sgml   | 2 +-
doc/src/sgml/libpq.sgml   | 2 +-
src/backend/storage/lmgr/proc.c   | 2 +-
src/test/isolation/specs/detach-partition-concurrently-4.spec | 2 +-
src/test/recovery/t/001_stream_rep.pl | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)



pgsql: Remove dummy_spinlock

2024-01-25 Thread Alvaro Herrera
Remove dummy_spinlock

It's been unused since 1b468a131bd2 (2015).

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/55627ba2d334ce98e1f5916354c46472d414bda6

Modified Files
--
src/backend/main/main.c   | 6 --
src/backend/storage/lmgr/s_lock.c | 2 --
src/include/storage/s_lock.h  | 1 -
3 files changed, 9 deletions(-)



pgsql: Fix s_lock_test compile

2024-01-25 Thread Alvaro Herrera
Fix s_lock_test compile

This is a mostly unused tool, but I discovered while nosing around the
Makefile that it hasn't been kept in line with other changes.  Fix it.

Backpatching doesn't appear to be necessary.

Discussion: https://postgr.es/m/202401241114.ied53jcich72@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/46778187f5373f6072b58d5e4c298b775333a37c

Modified Files
--
src/backend/storage/lmgr/Makefile | 2 +-
src/backend/storage/lmgr/s_lock.c | 8 
2 files changed, 9 insertions(+), 1 deletion(-)



pgsql: Improve notation of BuiltinTrancheNames

2024-01-24 Thread Alvaro Herrera
Improve notation of BuiltinTrancheNames

Use C99 designated initializer syntax for array elements, instead of
writing the position in a comment.  This is less verbose and much more
readable.  Akin to cc150596341e.

One disadvantage is that the BuiltinTrancheNames array now has a hole of
51 NULLs -- previously, the array elements were shifted 51 elements
 downward to avoid this.  This can be fixed by merging the
IndividualLWLockNames array into BuiltinTrancheNames, which would occupy
those 51 pointers, but because it requires some arguably ugly Meson
hackery, it's left for later.

Discussion: https://postgr.es/m/202401231025.gbv4nnte5fmm@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/74a73063106583b1f49274a2cd1df42e35107361

Modified Files
--
src/backend/storage/lmgr/lwlock.c | 97 +--
1 file changed, 33 insertions(+), 64 deletions(-)



pgsql: Abort pgbench if script end is reached with an open pipeline

2024-01-22 Thread Alvaro Herrera
Abort pgbench if script end is reached with an open pipeline

When a pipeline is opened with \startpipeline and not closed, pgbench
will either error on the next transaction with a "already in pipeline
mode" error or successfully end if this was the last transaction --
despite not sending anything that was piped in the pipeline.

Make it an error to reach end of script is reached while there's an
open pipeline.

Backpatch to 14, where pgbench got support for pipelines.

Author: Anthonin Bonnefoy 
Reported-by: Michael Paquier 
Discussion: https://postgr.es/m/za4iobzkdjro4...@paquier.xyz

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/07b53de700390c8bdee99ce373d84f0cdcad74d6

Modified Files
--
src/bin/pgbench/pgbench.c| 15 +--
src/bin/pgbench/t/001_pgbench_with_server.pl | 28 
2 files changed, 41 insertions(+), 2 deletions(-)



pgsql: Abort pgbench if script end is reached with an open pipeline

2024-01-22 Thread Alvaro Herrera
Abort pgbench if script end is reached with an open pipeline

When a pipeline is opened with \startpipeline and not closed, pgbench
will either error on the next transaction with a "already in pipeline
mode" error or successfully end if this was the last transaction --
despite not sending anything that was piped in the pipeline.

Make it an error to reach end of script is reached while there's an
open pipeline.

Backpatch to 14, where pgbench got support for pipelines.

Author: Anthonin Bonnefoy 
Reported-by: Michael Paquier 
Discussion: https://postgr.es/m/za4iobzkdjro4...@paquier.xyz

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/3fd36be52b70b95eea6fe7d296ce871f49eedb50

Modified Files
--
src/bin/pgbench/pgbench.c| 15 +--
src/bin/pgbench/t/001_pgbench_with_server.pl | 28 
2 files changed, 41 insertions(+), 2 deletions(-)



pgsql: Abort pgbench if script end is reached with an open pipeline

2024-01-22 Thread Alvaro Herrera
Abort pgbench if script end is reached with an open pipeline

When a pipeline is opened with \startpipeline and not closed, pgbench
will either error on the next transaction with a "already in pipeline
mode" error or successfully end if this was the last transaction --
despite not sending anything that was piped in the pipeline.

Make it an error to reach end of script is reached while there's an
open pipeline.

Backpatch to 14, where pgbench got support for pipelines.

Author: Anthonin Bonnefoy 
Reported-by: Michael Paquier 
Discussion: https://postgr.es/m/za4iobzkdjro4...@paquier.xyz

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/85ecff891525d61bc975584e2dc2d3c01e5a48ee

Modified Files
--
src/bin/pgbench/pgbench.c| 15 +--
src/bin/pgbench/t/001_pgbench_with_server.pl | 28 
2 files changed, 41 insertions(+), 2 deletions(-)



pgsql: Abort pgbench if script end is reached with an open pipeline

2024-01-22 Thread Alvaro Herrera
Abort pgbench if script end is reached with an open pipeline

When a pipeline is opened with \startpipeline and not closed, pgbench
will either error on the next transaction with a "already in pipeline
mode" error or successfully end if this was the last transaction --
despite not sending anything that was piped in the pipeline.

Make it an error to reach end of script is reached while there's an
open pipeline.

Backpatch to 14, where pgbench got support for pipelines.

Author: Anthonin Bonnefoy 
Reported-by: Michael Paquier 
Discussion: https://postgr.es/m/za4iobzkdjro4...@paquier.xyz

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/49f7c6c44a5f6a7f7b39d140e490c9c627511893

Modified Files
--
src/bin/pgbench/pgbench.c| 15 +--
src/bin/pgbench/t/001_pgbench_with_server.pl | 28 
2 files changed, 41 insertions(+), 2 deletions(-)



pgsql: Test EXPLAIN (FORMAT JSON) ... XMLTABLE

2024-01-22 Thread Alvaro Herrera
Test EXPLAIN (FORMAT JSON) ... XMLTABLE

Also, add an alias to the XMLTABLE expression in an existing test.  This
covers some code in explain.c that wasn't previously covered.

I patched xml_2.out blindly :-(

Discussion: https://postgr.es/m/202401181146.fuoeskfzriq7@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/752533d40fd50de0b09d4b956cc32c38f5df2f05

Modified Files
--
src/test/regress/expected/xml.out   | 51 +
src/test/regress/expected/xml_1.out | 51 +
src/test/regress/expected/xml_2.out | 51 +
src/test/regress/sql/xml.sql|  5 +++-
4 files changed, 142 insertions(+), 16 deletions(-)



pgsql: Rework text in replication slots documentation

2024-01-18 Thread Alvaro Herrera
Rework text in replication slots documentation

This is cosmetic, so no backpatch.

Reviewed-by: Bharath Rupireddy 
Discussion: https://postgr.es/m/20230413111838.e7yxke2dtwrxw3qy@alvherre.pgsql
Discussion: https://postgr.es/m/202401151537.ryhysqfncs6d@alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/27d04ed5310ad33dd3364322ae53ea685b28a8b6

Modified Files
--
doc/src/sgml/high-availability.sgml | 26 +-
1 file changed, 17 insertions(+), 9 deletions(-)



pgsql: struct XmlTableRoutine: use C99 designated initializers

2024-01-16 Thread Alvaro Herrera
struct XmlTableRoutine: use C99 designated initializers

As in c27f8621eed et al.

Not as critical as other cases we've handled, but I figure if we're
going to add JsonbTableRoutine using TableFuncRoutine, this makes it
easier to jump around the code.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/585025397337281cdce31bf1df2e0868cfbd0b92

Modified Files
--
src/backend/utils/adt/xml.c | 16 
1 file changed, 8 insertions(+), 8 deletions(-)



pgsql: Don't test already-referenced pointer for nullness

2024-01-16 Thread Alvaro Herrera
Don't test already-referenced pointer for nullness

Commit b8ba7344e9eb added in PQgetResult a derefence to a pointer
returned by pqPrepareAsyncResult(), before some other code that was
already testing that pointer for nullness.  But since commit
618c16707a6d (in Postgres 15), pqPrepareAsyncResult() doesn't ever
return NULL (a statically-allocated result is returned if OOM).  So in
branches 15 and up, we can remove the redundant pointer check with no
harm done.

However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if
it runs out of memory.  Fix things there by adding a null pointer check
before dereferencing the pointer.  This should hint Coverity that the
preexisting check is not redundant but necessary.

Backpatch to 14, like b8ba7344e9eb.

Per Coverity.

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/39aab11085177e4026cec6065a78a425c44e23e3

Modified Files
--
src/interfaces/libpq/fe-exec.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)



pgsql: Don't test already-referenced pointer for nullness

2024-01-16 Thread Alvaro Herrera
Don't test already-referenced pointer for nullness

Commit b8ba7344e9eb added in PQgetResult a derefence to a pointer
returned by pqPrepareAsyncResult(), before some other code that was
already testing that pointer for nullness.  But since commit
618c16707a6d (in Postgres 15), pqPrepareAsyncResult() doesn't ever
return NULL (a statically-allocated result is returned if OOM).  So in
branches 15 and up, we can remove the redundant pointer check with no
harm done.

However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if
it runs out of memory.  Fix things there by adding a null pointer check
before dereferencing the pointer.  This should hint Coverity that the
preexisting check is not redundant but necessary.

Backpatch to 14, like b8ba7344e9eb.

Per Coverity.

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/2b656cbd2f24edb7e2964fa3f71ca253ee9d81d8

Modified Files
--
src/interfaces/libpq/fe-exec.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)



pgsql: Don't test already-referenced pointer for nullness

2024-01-16 Thread Alvaro Herrera
Don't test already-referenced pointer for nullness

Commit b8ba7344e9eb added in PQgetResult a derefence to a pointer
returned by pqPrepareAsyncResult(), before some other code that was
already testing that pointer for nullness.  But since commit
618c16707a6d (in Postgres 15), pqPrepareAsyncResult() doesn't ever
return NULL (a statically-allocated result is returned if OOM).  So in
branches 15 and up, we can remove the redundant pointer check with no
harm done.

However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if
it runs out of memory.  Fix things there by adding a null pointer check
before dereferencing the pointer.  This should hint Coverity that the
preexisting check is not redundant but necessary.

Backpatch to 14, like b8ba7344e9eb.

Per Coverity.

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/7a7c8c98a610418ed0118e22a1793bf27e55783a

Modified Files
--
src/interfaces/libpq/fe-exec.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)



pgsql: Don't test already-referenced pointer for nullness

2024-01-16 Thread Alvaro Herrera
Don't test already-referenced pointer for nullness

Commit b8ba7344e9eb added in PQgetResult a derefence to a pointer
returned by pqPrepareAsyncResult(), before some other code that was
already testing that pointer for nullness.  But since commit
618c16707a6d (in Postgres 15), pqPrepareAsyncResult() doesn't ever
return NULL (a statically-allocated result is returned if OOM).  So in
branches 15 and up, we can remove the redundant pointer check with no
harm done.

However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if
it runs out of memory.  Fix things there by adding a null pointer check
before dereferencing the pointer.  This should hint Coverity that the
preexisting check is not redundant but necessary.

Backpatch to 14, like b8ba7344e9eb.

Per Coverity.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/c6605c1bdf07e8fc026bf857d37628cbb5746bb8

Modified Files
--
src/interfaces/libpq/fe-exec.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)



pgsql: Avoid useless ReplicationOriginExitCleanup locking

2024-01-15 Thread Alvaro Herrera
Avoid useless ReplicationOriginExitCleanup locking

When session_replication_state is NULL, we can know there's nothing to
do with no lock acquisition.  Do that.

Author: Bharath Rupireddy 
Discussion: 
https://postgr.es/m/calj2acx+yaeru5xjqr4c7klsto_f7dbrnf8wgehvjzcktnu...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/aa817c7496575b37fde6ea5e0cd65b26f29ea532

Modified Files
--
src/backend/replication/logical/origin.c | 13 -
1 file changed, 8 insertions(+), 5 deletions(-)



pgsql: Add empty placeholder LINGUAS file for pg_walsummary

2024-01-12 Thread Alvaro Herrera
Add empty placeholder LINGUAS file for pg_walsummary

Like bbf1f1340800.

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/2f696d5a290229a95fd80e351e4e6ecf8d4a

Modified Files
--
src/bin/pg_walsummary/po/LINGUAS | 0
1 file changed, 0 insertions(+), 0 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
REL_12_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/35cc9f15908f554d6fddc641536b63414eae234e

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/9c00e4c7751f50e81636b0e837809b309bfe7ef6

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/924daecf81806c340ec2153b0e096d178d28a3be

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
REL_13_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/3386afadd9a2c3c8145ffb4bc0cde97710eba2e5

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/076530887a587968947a6d1854d6f44f61c586be

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Added literal tag for RETURNING

2024-01-12 Thread Alvaro Herrera
Added literal tag for RETURNING

This is an old mistake (92e38182d7c8); backpatch all the way back.

Author: Atsushi Torikoshi 
Reviewed-by: Ashutosh Bapat 
Discussion: https://postgr.es/m/c0aa00b60a16c0ea2a4c5123b013a...@oss.nttdata.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/6780b79d5c580586ae6feb37b9c8b8bf33367886

Modified Files
--
doc/src/sgml/ref/copy.sgml | 8 
1 file changed, 4 insertions(+), 4 deletions(-)



pgsql: Remove useless LIMIT_OPTION_DEFAULT value from LimitOption

2023-12-16 Thread Alvaro Herrera
Remove useless LIMIT_OPTION_DEFAULT value from LimitOption

During the development that led to commit 357889eb17bb, for a time we
had the value LIMIT_OPTION_DEFAULT, which was mostly but not completely
removed later on, before commit.  Complete the removal now.

Author: Zhang Mingli 
Discussion: https://postgr.es/m/59d61a1a-3858-475a-964f-24468c97cc67@Spark

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a6be0600ac3b71dda8277ab0fcbe59ee101ac1ce

Modified Files
--
src/backend/parser/gram.y | 2 +-
src/include/nodes/nodes.h | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)



pgsql: Simplify productions for FORMAT JSON [ ENCODING name ]

2023-12-11 Thread Alvaro Herrera
Simplify productions for FORMAT JSON [ ENCODING name ]

This removes the production json_encoding_clause_opt, instead merging
it into json_format_clause.  Also remove the auxiliary
makeJsonEncoding() function.

Reviewed-by: Amit Langote 
Discussion: https://postgr.es/m/202312071841.u2gueb5dsrbk%40alvherre.pgsql

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/d3fe6e90bab52b8cbf085cfad5e4da110a2cd373

Modified Files
--
src/backend/nodes/makefuncs.c | 21 ---
src/backend/parser/gram.y | 49 +--
src/include/nodes/makefuncs.h |  1 -
3 files changed, 33 insertions(+), 38 deletions(-)



pgsql: Test that it works to RESET an invalid reloption

2023-12-08 Thread Alvaro Herrera
Test that it works to RESET an invalid reloption

This works today, and it's valuable to ensure it doesn't get broken
if/when we get around to refactoring the implementation.

Author: Nikolay Shaplov 
Discussion: https://postgr.es/m/4563991.km65PDbjlG@thinkpad-pgpro

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/7db01fbcefbd95a7c97afa128fab59f4a09b3ff1

Modified Files
--
src/test/regress/expected/reloptions.out | 11 +++
src/test/regress/sql/reloptions.sql  |  7 +++
2 files changed, 18 insertions(+)



pgsql: Fix handling of errors in libpq pipelines

2023-12-05 Thread Alvaro Herrera
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) 
Discussion: https://postgr.es/m/17948-fcace7557e449...@postgresql.org

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/b8ba7344e9eb9bb505a92900b2a59257ef718135

Modified Files
--
src/interfaces/libpq/fe-exec.c  | 53 +
src/interfaces/libpq/fe-protocol3.c |  9 ++-
src/interfaces/libpq/libpq-int.h|  3 ++-
3 files changed, 40 insertions(+), 25 deletions(-)



pgsql: Fix handling of errors in libpq pipelines

2023-12-05 Thread Alvaro Herrera
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) 
Discussion: https://postgr.es/m/17948-fcace7557e449...@postgresql.org

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/1171c6e7418564296e9023859f68225b247427a7

Modified Files
--
src/interfaces/libpq/fe-exec.c  | 61 -
src/interfaces/libpq/fe-protocol3.c |  9 ++
src/interfaces/libpq/libpq-int.h|  3 +-
3 files changed, 44 insertions(+), 29 deletions(-)



pgsql: Fix handling of errors in libpq pipelines

2023-12-05 Thread Alvaro Herrera
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) 
Discussion: https://postgr.es/m/17948-fcace7557e449...@postgresql.org

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/f89681816793d79584296c58960f790e6e073459

Modified Files
--
src/interfaces/libpq/fe-exec.c  | 63 -
src/interfaces/libpq/fe-protocol3.c | 16 --
src/interfaces/libpq/libpq-int.h|  3 +-
3 files changed, 49 insertions(+), 33 deletions(-)



pgsql: Fix handling of errors in libpq pipelines

2023-12-05 Thread Alvaro Herrera
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) 
Discussion: https://postgr.es/m/17948-fcace7557e449...@postgresql.org

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/878aa41f8257b1e8b36a690d62475b4e6f1ede33

Modified Files
--
src/interfaces/libpq/fe-exec.c  | 53 +
src/interfaces/libpq/fe-protocol3.c |  9 ++-
src/interfaces/libpq/libpq-int.h|  3 ++-
3 files changed, 40 insertions(+), 25 deletions(-)



pgsql: Don't use pgbench -j in tests

2023-12-04 Thread Alvaro Herrera
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 
Discussion: https://postgr.es/m/zw2g9ix4nbklc...@paquier.xyz

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/be7b4d976600fe5b52bd0d3a4e61259b55e3c0c2

Modified Files
--
src/bin/pgbench/t/001_pgbench_with_server.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Don't use pgbench -j in tests

2023-12-04 Thread Alvaro Herrera
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 
Discussion: https://postgr.es/m/zw2g9ix4nbklc...@paquier.xyz

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/25f2a43756443031239a5d212a63ae9b183e4502

Modified Files
--
src/bin/pgbench/t/001_pgbench_with_server.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Don't use pgbench -j in tests

2023-12-04 Thread Alvaro Herrera
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 
Discussion: https://postgr.es/m/zw2g9ix4nbklc...@paquier.xyz

Branch
--
REL_16_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/419cac053b6b27e4111216b8a529a1a0887580bb

Modified Files
--
src/bin/pgbench/t/001_pgbench_with_server.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Don't use pgbench -j in tests

2023-12-04 Thread Alvaro Herrera
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 
Discussion: https://postgr.es/m/zw2g9ix4nbklc...@paquier.xyz

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/a3f76a3f7e3a670728e2e2bed45499c11acb2936

Modified Files
--
src/bin/pgbench/t/001_pgbench_with_server.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



pgsql: Fix CREATE INDEX CONCURRENTLY example

2023-11-27 Thread Alvaro Herrera
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 
Discussion: 
https://postgr.es/m/CAM527d9iz6+=_c7eqskagzjqwvsecervvvhz1v3gdgjttvg...@mail.gmail.com

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/3a95d2c242eab1efd2ac89d8795ac7a5332c7581

Modified Files
--
doc/src/sgml/ddl.sgml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



  1   2   3   4   5   6   7   8   9   10   >