pgsql: Fix BF failure introduced by commit b3f6b14cf4.

2024-02-29 Thread Amit Kapila
Fix BF failure introduced by commit b3f6b14cf4.

The test added by commit b3f6b14cf4 uses a non-superuser and forgot to set
up pg_hba.conf to allow connections from it. The special setup is only
needed on Windows machines that don't use UNIX sockets.

As per buildfarm

Discussion: 
https://postgr.es/m/cajpy0ucfrsspv1x3vwkgamqyhyauwqzpp0nqjjx4ypvkqn6...@mail.gmail.com

Branch
--
master

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

Modified Files
--
src/test/recovery/t/040_standby_failover_slots_sync.pl | 6 +-
1 file changed, 5 insertions(+), 1 deletion(-)



pgsql: Convert unloggedLSN to an atomic variable.

2024-02-29 Thread Nathan Bossart
Convert unloggedLSN to an atomic variable.

Currently, this variable is an XLogRecPtr protected by a spinlock.
By converting it to an atomic variable, we can remove the spinlock,
which saves a small amount of shared memory space.  Since this code
is not performance-critical, we use atomic operations with full
barrier semantics to make it easy to reason about correctness.

Author: John Morris
Reviewed-by: Michael Paquier, Robert Haas, Andres Freund, Stephen Frost, 
Bharath Rupireddy
Discussion: 
https://postgr.es/m/BYAPR13MB26772534335255E50318C574A0409%40BYAPR13MB2677.namprd13.prod.outlook.com
Discussion: 
https://postgr.es/m/MN2PR13MB2688FD8B757316CB5C54C8A2A0DDA%40MN2PR13MB2688.namprd13.prod.outlook.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/963d3072af21afbcb1183b3c960135cc7df02f3f

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



pgsql: Convert archiver's force_dir_scan variable to an atomic variable

2024-02-29 Thread Nathan Bossart
Convert archiver's force_dir_scan variable to an atomic variable.

Commit bd5132db55 introduced new atomic read/write functions with
full barrier semantics, which are intended to simplify converting
non-performance-critical code to use atomic variables.  This commit
demonstrates one such conversion.

Reviewed-by: Yong Li
Discussion: https://postgr.es/m/20231110205128.GB1315705%40nathanxps13

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/3179701505b9ec58243ffba9d22b1803f320bf60

Modified Files
--
src/backend/postmaster/pgarch.c | 21 +
1 file changed, 5 insertions(+), 16 deletions(-)



pgsql: Introduce atomic read/write functions with full barrier semantic

2024-02-29 Thread Nathan Bossart
Introduce atomic read/write functions with full barrier semantics.

Writing correct code using atomic variables is often difficult due
to the memory barrier semantics (or lack thereof) of the underlying
operations.  This commit introduces atomic read/write functions
with full barrier semantics to ease this cognitive load.  For
example, some spinlocks protect a single value, and these new
functions make it easy to convert the value to an atomic variable
(thus eliminating the need for the spinlock) without modifying the
barrier semantics previously provided by the spinlock.  Since these
functions may be less performant than the other atomic reads and
writes, they are not suitable for every use-case.  However, using a
single atomic operation with full barrier semantics may be more
performant in cases where a separate explicit barrier would
otherwise be required.

The base implementations for these new functions are atomic
exchanges (for writes) and atomic fetch/adds with 0 (for reads).
These implementations can be overwritten with better architecture-
specific versions as they are discovered.

This commit leaves converting existing code to use these new
functions as a future exercise.

Reviewed-by: Andres Freund, Yong Li, Jeff Davis
Discussion: https://postgr.es/m/20231110205128.GB1315705%40nathanxps13

Branch
--
master

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

Modified Files
--
src/include/port/atomics.h | 58 ++
src/include/port/atomics/generic.h | 36 +++
2 files changed, 94 insertions(+)



pgsql: Support MERGE into updatable views.

2024-02-29 Thread Dean Rasheed
Support MERGE into updatable views.

This allows the target relation of MERGE to be an auto-updatable or
trigger-updatable view, and includes support for WITH CHECK OPTION,
security barrier views, and security invoker views.

A trigger-updatable view must have INSTEAD OF triggers for every type
of action (INSERT, UPDATE, and DELETE) mentioned in the MERGE command.
An auto-updatable view must not have any INSTEAD OF triggers. Mixing
auto-update and trigger-update actions (i.e., having a partial set of
INSTEAD OF triggers) is not supported.

Rule-updatable views are also not supported, since there is no
rewriter support for non-SELECT rules with MERGE operations.

Dean Rasheed, reviewed by Jian He and Alvaro Herrera.

Discussion: 
https://postgr.es/m/CAEZATCVcB1g0nmxuEc-A+gGB0HnfcGQNGYH7gS=7rq0u0zo...@mail.gmail.com

Branch
--
master

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

Modified Files
--
doc/src/sgml/ref/create_view.sgml |  42 +-
doc/src/sgml/ref/merge.sgml   |  22 +-
doc/src/sgml/rules.sgml   |  40 +-
src/backend/commands/copyfrom.c   |   2 +-
src/backend/executor/execMain.c   |  51 +--
src/backend/executor/execPartition.c  |   4 +-
src/backend/executor/nodeModifyTable.c| 138 +--
src/backend/optimizer/prep/prepjointree.c |  20 +-
src/backend/optimizer/util/appendinfo.c   |   3 +-
src/backend/parser/parse_merge.c  |  21 +-
src/backend/rewrite/rewriteHandler.c  | 403 +--
src/backend/rewrite/rewriteManip.c|  20 +-
src/bin/psql/tab-complete.c   |   1 +
src/include/catalog/catversion.h  |   2 +-
src/include/executor/executor.h   |   3 +-
src/include/nodes/parsenodes.h|   8 +
src/include/rewrite/rewriteHandler.h  |   6 +
src/test/regress/expected/merge.out   |  10 -
src/test/regress/expected/rules.out   |  12 +
src/test/regress/expected/updatable_views.out | 553 +-
src/test/regress/sql/merge.sql|   9 -
src/test/regress/sql/rules.sql|  13 +
src/test/regress/sql/updatable_views.sql  | 285 -
23 files changed, 1380 insertions(+), 288 deletions(-)



pgsql: Add missing RangeTblEntry field to jumble

2024-02-29 Thread Peter Eisentraut
Add missing RangeTblEntry field to jumble

RangeTblEntry.funcordinality should be jumbled, because the WITH
ORDINALITY clause changes the query result.

This was apparently an oversight in the past.

Discussion: 
https://www.postgresql.org/message-id/flat/d7f421f8-fd6d-4759-adc3-247090a5d44b%40eisentraut.org

Branch
--
master

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

Modified Files
--
src/backend/nodes/queryjumblefuncs.c | 1 +
1 file changed, 1 insertion(+)



pgsql: Remove field UpdateContext->updated in nodeModifyTable.c

2024-02-29 Thread Dean Rasheed
Remove field UpdateContext->updated in nodeModifyTable.c

This field has been redundant ever since it was added by commit
25e777cf8e, which split up ExecUpdate() and ExecDelete() into reusable
pieces. The only place that reads it is ExecMergeMatched(), if the
result from ExecUpdateAct() is TM_Ok. However, all paths through
ExecUpdateAct() that return TM_Ok also set this field to true, so the
return status by itself is sufficient to tell if the update happened.

Removing this field is a modest simplification, and it brings the
UPDATE path in ExecMergeMatched() more into line with ExecUpdate(),
ensuring that ExecUpdateEpilogue() is always called if ExecUpdateAct()
returns TM_Ok, reducing the chance of bugs.

Dean Rasheed, reviewed by Alvaro Herrera.

Discussion: 
https://postgr.es/m/CAEZATCWGGmigGBzLHkJm5Ccv2mMxXmwi3%2Buq0yhwDHm-tsvSLg%40mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/362de947cd7e8c826d9b3c5dc2590348263ed3c1

Modified Files
--
src/backend/executor/nodeModifyTable.c | 6 +-
1 file changed, 1 insertion(+), 5 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
REL_12_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/24dc4afebd5a82f30aed6bd18d48ff42ef787410

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
REL_13_STABLE

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

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
REL_14_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/217928ddb45a8a3b03fc1f9d3d97166f1d9a9d12

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
REL_15_STABLE

Details
---
https://git.postgresql.org/pg/commitdiff/55ea12a2827791b7fb3f30b207a122a35df951d8

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
REL_16_STABLE

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

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)



pgsql: Fix integer underflow in shared memory debugging

2024-02-29 Thread Daniel Gustafsson
Fix integer underflow in shared memory debugging

dsa_dump would print a large negative number instead of zero for
segment bin 0.  Fix by explicitly checking for underflow and add
special case for bin 0. Backpatch to all supported versions.

Author: Ian Ilyasov 
Reviewed-by: Robert Haas 
Discussion: 
https://postgr.es/m/gv1p251mb1004e0d09d117d3cecf9256ecd...@gv1p251mb1004.eurp251.prod.outlook.com
Backpatch-through: v12

Branch
--
master

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

Modified Files
--
src/backend/utils/mmgr/dsa.c | 10 +++---
1 file changed, 7 insertions(+), 3 deletions(-)