From 4cf21c09ea5c32466115bbbd7cc2cd322060343e Mon Sep 17 00:00:00 2001 From: nettrash Date: Wed, 25 Nov 2026 16:06:03 +0100 Subject: [PATCH v1 3/3] Allow NOTIFY without cross-transaction commit ordering To deliver notifications in commit order, PreCommit_Notify() takes a cluster-wide heavyweight lock that the notifying transaction holds until its commit is complete, including the WAL flush and any synchronous replication wait. So only one notifying transaction in the whole cluster can be committing at a time. That caps the commit rate of notifying transactions at roughly the inverse of the commit latency, regardless of the number of clients, and makes their latency grow with the number of concurrent notifiers. Many applications use notifications only to tell listeners to look at the database again, and don't need notifications from different transactions to arrive in commit order. Add an optional third argument to pg_notify(), "ordered". A transaction whose notifications were all sent with ordered => false doesn't take the heavyweight lock. Such notifications are still sent only if the transaction commits, and are still delivered in the order they were sent within the transaction. But they no longer wait for earlier notifying transactions to finish committing, so their queue entries can precede those of transactions that commit earlier. Readers stop at uncommitted entries, so the notifications behind such an entry are delayed until its transaction finishes; the preceding two commits make sure that they are not lost. NOTIFY and the two-argument pg_notify() are unchanged, and a transaction that sends both kinds keeps commit ordering for all of its notifications. The new isolation test uses an injection point to hold a notifying transaction in the middle of its commit, to check that unordered writers don't wait for it and that the notifications queued behind it are delivered once it commits. Catalog version bump needed. --- doc/src/sgml/ref/notify.sgml | 39 +++- src/backend/commands/async.c | 105 +++++++++-- src/include/catalog/pg_proc.dat | 6 + src/test/isolation/expected/async-notify.out | 63 +++++++ src/test/isolation/specs/async-notify.spec | 22 +++ src/test/modules/injection_points/Makefile | 3 +- .../expected/notify_unordered.out | 168 ++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../specs/notify_unordered.spec | 77 ++++++++ src/test/regress/expected/async.out | 30 ++++ src/test/regress/sql/async.sql | 10 ++ 11 files changed, 505 insertions(+), 19 deletions(-) create mode 100644 src/test/modules/injection_points/expected/notify_unordered.out create mode 100644 src/test/modules/injection_points/specs/notify_unordered.spec diff --git a/doc/src/sgml/ref/notify.sgml b/doc/src/sgml/ref/notify.sgml index fd6ed54e8f9..e77e7caee96 100644 --- a/doc/src/sgml/ref/notify.sgml +++ b/doc/src/sgml/ref/notify.sgml @@ -104,7 +104,9 @@ NOTIFY channel [ , NOTIFY guarantees that notifications from the same transaction get delivered in the order they were sent. It is also guaranteed that messages from different transactions are delivered in - the order in which the transactions committed. + the order in which the transactions committed, except for notifications + sent without commit ordering using pg_notify + (see ). @@ -175,7 +177,7 @@ NOTIFY channel [ , - + pg_notify @@ -184,12 +186,41 @@ NOTIFY channel [ , To send a notification you can also use the function - pg_notify(text, - text). The function takes the channel name as the + pg_notify(channel + text, payload text + , ordered boolean + ). The function takes the channel name as the first argument and the payload as the second. The function is much easier to use than the NOTIFY command if you need to work with non-constant channel names and payloads. + + + To deliver notifications from different transactions in commit order, a + transaction that has sent notifications holds a lock from just before it + commits until its commit is complete. That includes waiting for the + commit record to be flushed to disk and, with synchronous replication, + for the standby to confirm it. The lock is shared by all databases of + the cluster, so only one notifying transaction in the whole cluster can + be committing at a time, which limits how many such transactions can + commit per second. + + + + If ordered is false, the + notification need not be delivered in commit order relative to other + transactions' notifications, and a transaction that sent only such + notifications does not take that lock. This is useful when the + notification just tells listeners to look at the database again, so that + the order in which they hear about different transactions does not + matter. Such notifications are still sent only if the transaction + commits, and are still delivered in the order they were sent within + their transaction. However, they can be delayed until notifications + queued before them by transactions that have not finished committing yet + are delivered. If a transaction sends both kinds of notifications, all + of them are delivered in commit order. A null + ordered is treated as true. + diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 65fed839d83..361f3f1f8ac 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -148,6 +148,20 @@ * head; that is to ensure that we can advance the queue tail without undue * delay. * + * 9. Normally, writers also serialize on a cluster-wide heavyweight lock, + * which they hold from PreCommit_Notify() until their commit is complete. + * That keeps queue entries in commit order, and ensures that uncommitted + * entries never precede committed ones. But the lock is held across the + * commit's WAL flush and any synchronous replication wait, so it limits + * how fast notifying transactions can commit. Notifications sent with + * pg_notify(channel, payload, false) don't need to be ordered relative to + * other transactions' notifications, and a transaction that sent only such + * notifications skips the heavyweight lock. Its entries can then precede + * entries of transactions that commit before it does. Readers stop at + * uncommitted entries, so those later notifications are delayed, not lost, + * until the earlier transaction finishes; the stoppedAtUncommitted rule in + * item 8 makes sure the reader is woken again when that happens. + * * An application that listens on the same channel it notifies will get * NOTIFY messages for its own NOTIFYs. These can be ignored, if not useful, * by comparing be_pid in the NOTIFY message to the application's own backend's @@ -532,6 +546,7 @@ typedef struct NotificationList HTAB *hashtab; /* hash of NotificationHash structs, or NULL */ List *uniqueChannelNames; /* unique channel names being notified */ HTAB *uniqueChannelHash; /* hash of unique channel names, or NULL */ + bool ordered; /* does any event need commit ordering? */ struct NotificationList *upper; /* details for upper transaction levels */ } NotificationList; @@ -602,6 +617,9 @@ static dshash_hash globalChannelTableHash(const void *key, size_t size, void *arg); static void initGlobalChannelTable(void); static void initLocalChannelTable(void); +static void Async_Notify_internal(const char *channel, const char *payload, + bool ordered); +static void pg_notify_internal(FunctionCallInfo fcinfo, bool ordered); static void queue_listen(ListenActionKind action, const char *channel); static void Async_UnlistenOnExit(int code, Datum arg); static void BecomeRegisteredListener(void); @@ -871,6 +889,35 @@ AsyncShmemInit(void *arg) */ Datum pg_notify(PG_FUNCTION_ARGS) +{ + pg_notify_internal(fcinfo, true); + + PG_RETURN_VOID(); +} + +/* + * pg_notify_with_ordering - + * SQL function to send a notification event, saying whether it must be + * delivered in commit order relative to other transactions' notifications + * + * A NULL "ordered" argument means the default, true. + */ +Datum +pg_notify_with_ordering(PG_FUNCTION_ARGS) +{ + bool ordered = PG_ARGISNULL(2) ? true : PG_GETARG_BOOL(2); + + pg_notify_internal(fcinfo, ordered); + + PG_RETURN_VOID(); +} + +/* + * Common code for the pg_notify SQL functions, whose first two arguments are + * the channel name and the payload. + */ +static void +pg_notify_internal(FunctionCallInfo fcinfo, bool ordered) { const char *channel; const char *payload; @@ -888,9 +935,7 @@ pg_notify(PG_FUNCTION_ARGS) /* For NOTIFY as a statement, this is checked in ProcessUtility */ PreventCommandDuringRecovery("NOTIFY"); - Async_Notify(channel, payload); - - PG_RETURN_VOID(); + Async_Notify_internal(channel, payload, ordered); } @@ -905,6 +950,21 @@ pg_notify(PG_FUNCTION_ARGS) */ void Async_Notify(const char *channel, const char *payload) +{ + Async_Notify_internal(channel, payload, true); +} + +/* + * Async_Notify_internal + * + * Workhorse for Async_Notify. If "ordered" is false, the notification + * doesn't need to be delivered in commit order relative to other + * transactions' notifications; if no notification of the transaction + * needs that, PreCommit_Notify can skip the cluster-wide lock that + * provides it. + */ +static void +Async_Notify_internal(const char *channel, const char *payload, bool ordered) { int my_level = GetCurrentTransactionNestLevel(); size_t channel_len; @@ -976,11 +1036,20 @@ Async_Notify(const char *channel, const char *payload) /* We won't build uniqueChannelNames/Hash till later, either */ notifies->uniqueChannelNames = NIL; notifies->uniqueChannelHash = NULL; + notifies->ordered = ordered; notifies->upper = pendingNotifies; pendingNotifies = notifies; } else { + /* + * If any event of the (sub)transaction needs commit ordering, all of + * them get it. Note this before checking for duplicates, so that an + * ordered event is honored even if it duplicates an unordered one. + */ + if (ordered) + pendingNotifies->ordered = true; + /* Now check for duplicates */ if (AsyncExistsPendingNotify(n)) { @@ -1288,11 +1357,14 @@ PreCommit_Notify(void) (void) GetCurrentTransactionId(); /* - * Serialize writers by acquiring a special lock that we hold till - * after commit. This ensures that queue entries appear in commit - * order, and in particular that there are never uncommitted queue - * entries ahead of committed ones, so an uncommitted transaction - * can't block delivery of deliverable notifications. + * Unless all of our notifications were sent unordered, serialize + * writers by acquiring a special lock that we hold till after commit. + * This ensures that queue entries appear in commit order, and in + * particular that there are never uncommitted queue entries ahead of + * committed ones, so an uncommitted transaction can't block delivery + * of deliverable notifications. Writers of unordered notifications + * give up both properties for their own entries, to avoid waiting for + * this lock; see item 9 at the top of this file. * * We use a heavyweight lock so that it'll automatically be released * after either commit or abort. This also allows deadlocks to be @@ -1303,18 +1375,20 @@ PreCommit_Notify(void) * (Historical note: before PG 9.0, a similar lock on "database 0" was * used by the flatfiles mechanism.) */ - LockSharedObject(DatabaseRelationId, InvalidOid, 0, - AccessExclusiveLock); + if (pendingNotifies->ordered) + LockSharedObject(DatabaseRelationId, InvalidOid, 0, + AccessExclusiveLock); /* * Now push the notifications into the queue. * * For the direct advancement optimization in SignalBackends(), we * need to ensure that no other backend can insert queue entries - * between queueHeadBeforeWrite and queueHeadAfterWrite. We hold - * NotifyQueueLock in EXCLUSIVE mode across all our insertions, even - * if they span several pages, so that this doesn't depend on the - * heavyweight lock above serializing all writers. + * between queueHeadBeforeWrite and queueHeadAfterWrite. The + * heavyweight lock above isn't enough for that, since writers of + * unordered notifications don't take it. So we hold NotifyQueueLock + * in EXCLUSIVE mode across all our insertions, even if they span + * several pages. * * A full queue is very uncommon and should really not happen, given * that we have so much space available in the SLRU pages. @@ -2512,6 +2586,9 @@ AtSubCommit_Notify(void) if (!AsyncExistsPendingNotify(childn)) AddEventToPendingNotifies(childn); } + /* The parent needs commit ordering if the subxact did */ + if (childPendingNotifies->ordered) + pendingNotifies->ordered = true; pfree(childPendingNotifies); } } diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 50fb182cb79..797fa31da1c 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -8741,6 +8741,12 @@ proname => 'pg_notify', proisstrict => 'f', provolatile => 'v', proparallel => 'r', prorettype => 'void', proargtypes => 'text text', prosrc => 'pg_notify' }, +{ oid => '9717', + descr => 'send a notification event, optionally without commit ordering', + proname => 'pg_notify', proisstrict => 'f', provolatile => 'v', + proparallel => 'r', prorettype => 'void', proargtypes => 'text text bool', + proargnames => '{channel,payload,ordered}', + prosrc => 'pg_notify_with_ordering' }, { oid => '3296', descr => 'get the fraction of the asynchronous notification queue currently in use', proname => 'pg_notification_queue_usage', provolatile => 'v', diff --git a/src/test/isolation/expected/async-notify.out b/src/test/isolation/expected/async-notify.out index 55b7cbc6e02..04955b8ae0b 100644 --- a/src/test/isolation/expected/async-notify.out +++ b/src/test/isolation/expected/async-notify.out @@ -217,6 +217,69 @@ x listener_ch: NOTIFY "ch" with payload "aa" from notifier_ch +starting permutation: listenc llisten notifyu notifyumix lcheck +step listenc: LISTEN c1; LISTEN c2; +step llisten: LISTEN c1; LISTEN c2; +step notifyu: SELECT pg_notify('c1', 'unordered', false); +pg_notify +--------- + +(1 row) + +notifier: NOTIFY "c1" with payload "unordered" from notifier +step notifyumix: + BEGIN; + SELECT pg_notify('c1', 'mixed', false); + NOTIFY c1, 'mixed'; + SELECT pg_notify('c2', 'u1', false); + SAVEPOINT s1; + SELECT pg_notify('c2', 'u2', false); + SELECT pg_notify('c2', 'u1', false); + RELEASE SAVEPOINT s1; + SAVEPOINT s2; + SELECT pg_notify('c2', 'rolled back', false); + ROLLBACK TO SAVEPOINT s2; + COMMIT; + +pg_notify +--------- + +(1 row) + +pg_notify +--------- + +(1 row) + +pg_notify +--------- + +(1 row) + +pg_notify +--------- + +(1 row) + +pg_notify +--------- + +(1 row) + +notifier: NOTIFY "c1" with payload "mixed" from notifier +notifier: NOTIFY "c2" with payload "u1" from notifier +notifier: NOTIFY "c2" with payload "u2" from notifier +step lcheck: SELECT 1 AS x; +x +- +1 +(1 row) + +listener: NOTIFY "c1" with payload "unordered" from notifier +listener: NOTIFY "c1" with payload "mixed" from notifier +listener: NOTIFY "c2" with payload "u1" from notifier +listener: NOTIFY "c2" with payload "u2" from notifier + starting permutation: llisten lbegin usage bignotify usage step llisten: LISTEN c1; LISTEN c2; step lbegin: BEGIN; diff --git a/src/test/isolation/specs/async-notify.spec b/src/test/isolation/specs/async-notify.spec index 7aef2e8d180..855611438a5 100644 --- a/src/test/isolation/specs/async-notify.spec +++ b/src/test/isolation/specs/async-notify.spec @@ -45,6 +45,21 @@ step notify_many_with_dup { SELECT pg_notify('c1', 'msg1'); COMMIT; } +step notifyu { SELECT pg_notify('c1', 'unordered', false); } +step notifyumix { + BEGIN; + SELECT pg_notify('c1', 'mixed', false); + NOTIFY c1, 'mixed'; + SELECT pg_notify('c2', 'u1', false); + SAVEPOINT s1; + SELECT pg_notify('c2', 'u2', false); + SELECT pg_notify('c2', 'u1', false); + RELEASE SAVEPOINT s1; + SAVEPOINT s2; + SELECT pg_notify('c2', 'rolled back', false); + ROLLBACK TO SAVEPOINT s2; + COMMIT; +} step usage { SELECT pg_notification_queue_usage() > 0 AS nonzero; } step bignotify { SELECT count(pg_notify('c1', s::text)) FROM generate_series(1, 1000) s; } teardown { UNLISTEN *; } @@ -136,6 +151,13 @@ permutation l2listen l2begin notify1 lbegins llisten lcommit l2commit l2stop # are properly delivered to a listener in another backend. permutation lch_listen nch_notify lch_check +# Check notifications sent without commit ordering, alone and mixed with +# ordered ones in the same transaction (including deduplication between the +# two kinds and across subtransactions), with local and cross-backend +# delivery. Ordering between concurrent transactions is tested in +# src/test/modules/injection_points/specs/notify_unordered.spec. +permutation listenc llisten notifyu notifyumix lcheck + # Verify that pg_notification_queue_usage correctly reports a non-zero result, # after submitting notifications while another connection is listening for # those notifications and waiting inside an active transaction. We have to diff --git a/src/test/modules/injection_points/Makefile b/src/test/modules/injection_points/Makefile index a7a16d5016a..ff0edc87161 100644 --- a/src/test/modules/injection_points/Makefile +++ b/src/test/modules/injection_points/Makefile @@ -37,7 +37,8 @@ ISOLATION = basic \ $(WAIT_CLEANUP_TST) \ heap_lock_update \ on_conflict_probe_window \ - multixact-aborted-updater + multixact-aborted-updater \ + notify_unordered # some isolation tests require wal_level=replica ISOLATION_OPTS = --temp-config $(top_srcdir)/src/test/modules/injection_points/extra.conf diff --git a/src/test/modules/injection_points/expected/notify_unordered.out b/src/test/modules/injection_points/expected/notify_unordered.out new file mode 100644 index 00000000000..6c770b36e37 --- /dev/null +++ b/src/test/modules/injection_points/expected/notify_unordered.out @@ -0,0 +1,168 @@ +Parsed test spec with 4 sessions + +starting permutation: l_listen n1_unordered n2_unordered l_check w_wakeup l_check +injection_points_attach +----------------------- + +(1 row) + +step l_listen: LISTEN ch_b; +step n1_unordered: + INSERT INTO notify_unordered_tab VALUES (1); + SELECT pg_notify('ch_a', 'from n1', false); + +step n2_unordered: SELECT pg_notify('ch_b', 'from n2', false); +pg_notify +--------- + +(1 row) + +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +step w_wakeup: SELECT injection_points_wakeup('commit-before-clog-update'); +injection_points_wakeup +----------------------- + +(1 row) + +step n1_unordered: <... completed> +pg_notify +--------- + +(1 row) + +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +listener: NOTIFY "ch_b" with payload "from n2" from n2 +injection_points_detach +----------------------- + +(1 row) + + +starting permutation: l_listen n1_ordered n2_ordered w_wakeup l_check +injection_points_attach +----------------------- + +(1 row) + +step l_listen: LISTEN ch_b; +step n1_ordered: + INSERT INTO notify_unordered_tab VALUES (1); + NOTIFY ch_a, 'from n1'; + +step n2_ordered: NOTIFY ch_b, 'from n2'; +step w_wakeup: SELECT injection_points_wakeup('commit-before-clog-update'); +injection_points_wakeup +----------------------- + +(1 row) + +step n1_ordered: <... completed> +step n2_ordered: <... completed> +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +listener: NOTIFY "ch_b" with payload "from n2" from n2 +injection_points_detach +----------------------- + +(1 row) + + +starting permutation: l_listen n1_ordered n2_unordered l_check w_wakeup l_check +injection_points_attach +----------------------- + +(1 row) + +step l_listen: LISTEN ch_b; +step n1_ordered: + INSERT INTO notify_unordered_tab VALUES (1); + NOTIFY ch_a, 'from n1'; + +step n2_unordered: SELECT pg_notify('ch_b', 'from n2', false); +pg_notify +--------- + +(1 row) + +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +step w_wakeup: SELECT injection_points_wakeup('commit-before-clog-update'); +injection_points_wakeup +----------------------- + +(1 row) + +step n1_ordered: <... completed> +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +listener: NOTIFY "ch_b" with payload "from n2" from n2 +injection_points_detach +----------------------- + +(1 row) + + +starting permutation: l_listen n1_unordered n2_ordered l_check w_wakeup l_check +injection_points_attach +----------------------- + +(1 row) + +step l_listen: LISTEN ch_b; +step n1_unordered: + INSERT INTO notify_unordered_tab VALUES (1); + SELECT pg_notify('ch_a', 'from n1', false); + +step n2_ordered: NOTIFY ch_b, 'from n2'; +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +step w_wakeup: SELECT injection_points_wakeup('commit-before-clog-update'); +injection_points_wakeup +----------------------- + +(1 row) + +step n1_unordered: <... completed> +pg_notify +--------- + +(1 row) + +step l_check: SELECT 1 AS x; +x +- +1 +(1 row) + +listener: NOTIFY "ch_b" with payload "from n2" from n2 +injection_points_detach +----------------------- + +(1 row) + diff --git a/src/test/modules/injection_points/meson.build b/src/test/modules/injection_points/meson.build index cf9cb219548..fbe66a5b2bd 100644 --- a/src/test/modules/injection_points/meson.build +++ b/src/test/modules/injection_points/meson.build @@ -45,6 +45,7 @@ injection_points_isolation = [ 'heap_lock_update', 'on_conflict_probe_window', 'multixact-aborted-updater', + 'notify_unordered', ] # wait_cleanup terminates another backend, whose FATAL message can be lost diff --git a/src/test/modules/injection_points/specs/notify_unordered.spec b/src/test/modules/injection_points/specs/notify_unordered.spec new file mode 100644 index 00000000000..e0e61efc6f2 --- /dev/null +++ b/src/test/modules/injection_points/specs/notify_unordered.spec @@ -0,0 +1,77 @@ +# Test LISTEN/NOTIFY with notifications sent without commit ordering, that +# is, with pg_notify(channel, payload, false). +# +# Session n1 sends a notification on channel ch_a and is then held in the +# middle of its commit, after its WAL record is flushed but before it is +# marked committed in CLOG, by the "commit-before-clog-update" injection +# point. Meanwhile session n2 sends a notification on channel ch_b. The +# listener listens only on ch_b. +# +# Ordered writers serialize on a lock that n1 holds until its commit is +# done, so with ordered notifications on both sides n2 has to wait for n1. +# If either side is unordered, n2 does not wait, and its entry lands in the +# queue after n1's uncommitted one. The listener is woken by n2 but stops +# reading at n1's entry, so it can't deliver n2's notification until n1 has +# committed. When n1 commits, it must wake the listener again, rather than +# just moving its queue position past n1's entries (which the listener is +# not interested in), or n2's notification would never be delivered. + +setup +{ + CREATE EXTENSION injection_points; + CREATE TABLE notify_unordered_tab (i int); +} + +teardown +{ + DROP TABLE notify_unordered_tab; + DROP EXTENSION injection_points; +} + +session listener +step l_listen { LISTEN ch_b; } +step l_check { SELECT 1 AS x; } +teardown { UNLISTEN *; } + +# n1 writes to a table so that its commit has to flush WAL, which is where +# the injection point is. +session n1 +setup +{ + SELECT injection_points_set_local(); + SELECT injection_points_attach('commit-before-clog-update', 'wait'); +} +step n1_unordered +{ + INSERT INTO notify_unordered_tab VALUES (1); + SELECT pg_notify('ch_a', 'from n1', false); +} +step n1_ordered +{ + INSERT INTO notify_unordered_tab VALUES (1); + NOTIFY ch_a, 'from n1'; +} +teardown +{ + SELECT injection_points_detach('commit-before-clog-update'); +} + +session n2 +step n2_unordered { SELECT pg_notify('ch_b', 'from n2', false); } +step n2_ordered { NOTIFY ch_b, 'from n2'; } + +session wakeup +step w_wakeup { SELECT injection_points_wakeup('commit-before-clog-update'); } + +# Both unordered: n2 doesn't wait for n1. Nothing can be delivered until n1 +# has committed; after that, n2's notification must arrive. +permutation l_listen n1_unordered n2_unordered l_check w_wakeup l_check + +# Both ordered: n2 waits for n1, as before. +permutation l_listen n1_ordered n2_ordered w_wakeup l_check + +# Unordered n2 doesn't wait for ordered n1. +permutation l_listen n1_ordered n2_unordered l_check w_wakeup l_check + +# Ordered n2 doesn't wait for unordered n1, which doesn't take the lock. +permutation l_listen n1_unordered n2_ordered l_check w_wakeup l_check diff --git a/src/test/regress/expected/async.out b/src/test/regress/expected/async.out index 20a30680ee5..3bfdd8936b8 100644 --- a/src/test/regress/expected/async.out +++ b/src/test/regress/expected/async.out @@ -27,6 +27,36 @@ SELECT pg_notify(NULL,'sample message1'); ERROR: channel name cannot be empty SELECT pg_notify('notify_async_channel_name_too_long______________________________','sample_message1'); ERROR: channel name too long +-- Should work. Notifications that don't need commit ordering +SELECT pg_notify('notify_async1', 'sample message1', false); + pg_notify +----------- + +(1 row) + +SELECT pg_notify('notify_async1', 'sample message1', true); + pg_notify +----------- + +(1 row) + +SELECT pg_notify('notify_async1', 'sample message1', NULL); + pg_notify +----------- + +(1 row) + +SELECT pg_notify(channel => 'notify_async1', payload => NULL, ordered => false); + pg_notify +----------- + +(1 row) + +-- Should fail. Same argument checks as the two-argument form +SELECT pg_notify('', 'sample message1', false); +ERROR: channel name cannot be empty +SELECT pg_notify(NULL, 'sample message1', false); +ERROR: channel name cannot be empty --Should work. Valid NOTIFY/LISTEN/UNLISTEN commands NOTIFY notify_async2; LISTEN notify_async2; diff --git a/src/test/regress/sql/async.sql b/src/test/regress/sql/async.sql index 3965fd594cc..9ac80f2af4b 100644 --- a/src/test/regress/sql/async.sql +++ b/src/test/regress/sql/async.sql @@ -12,6 +12,16 @@ SELECT pg_notify('','sample message1'); SELECT pg_notify(NULL,'sample message1'); SELECT pg_notify('notify_async_channel_name_too_long______________________________','sample_message1'); +-- Should work. Notifications that don't need commit ordering +SELECT pg_notify('notify_async1', 'sample message1', false); +SELECT pg_notify('notify_async1', 'sample message1', true); +SELECT pg_notify('notify_async1', 'sample message1', NULL); +SELECT pg_notify(channel => 'notify_async1', payload => NULL, ordered => false); + +-- Should fail. Same argument checks as the two-argument form +SELECT pg_notify('', 'sample message1', false); +SELECT pg_notify(NULL, 'sample message1', false); + --Should work. Valid NOTIFY/LISTEN/UNLISTEN commands NOTIFY notify_async2; LISTEN notify_async2; -- 2.54.0 (Apple Git-157)