Re: Disallow cancellation of waiting for synchronous replication

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Maksim Milyutin <milyutinma(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Disallow cancellation of waiting for synchronous replication
Date: 2020-01-12 11:18:38
Message-ID: AD990A67-A7B1-469C-8190-62986E3E957E@yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 11 янв. 2020 г., в 7:34, Bruce Momjian <bruce(at)momjian(dot)us> написал(а):
>
> Actually, it might be worse than that. In my reading of
> RecordTransactionCommit(), we do this:
>
> write to WAL
> flush WAL (durable)
> make visible to other backends
> replicate
> communicate to the client
>
> I think this means we make the transaction commit visible to all
> backends _before_ we replicate it, and potentially wait until we get a
> replication reply to return SUCCESS to the client.
No. Data is not visible to other backend when we await sync rep. It's easy to check.
in one psql you can start waiting for sync rep:
postgres=# \d+ x
Table "public.x"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
key | integer | | not null | | plain | |
data | text | | | | extended | |
Indexes:
"x_pkey" PRIMARY KEY, btree (key)
Access method: heap

postgres=# alter system set synchronous_standby_names to 'nonexistent';
ALTER SYSTEM
postgres=# select pg_reload_conf();
2020-01-12 16:09:58.167 +05 [45677] LOG: received SIGHUP, reloading configuration files
pg_reload_conf
----------------
t
(1 row)

postgres=# insert into x values (7, '7');

In other try to see inserted (already locally committed data)

postgres=# select * from x where key = 7;
key | data
-----+------
(0 rows)

try to insert same data and backend will hand on locks

postgres=# insert into x values (7,'7') on conflict do nothing;

ProcessQuery (in postgres) + 189 [0x1014b05bd]
standard_ExecutorRun (in postgres) + 301 [0x101339fcd]
ExecModifyTable (in postgres) + 1106 [0x101362b62]
ExecInsert (in postgres) + 494 [0x10136344e]
ExecCheckIndexConstraints (in postgres) + 570 [0x10133910a]
check_exclusion_or_unique_constraint (in postgres) + 977 [0x101338db1]
XactLockTableWait (in postgres) + 176 [0x101492770]
LockAcquireExtended (in postgres) + 1274 [0x101493aaa]

Thanks!

Best regards, Andrey Borodin.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2020-01-12 14:56:11 Re: [Logical Replication] TRAP: FailedAssertion("rel->rd_rel->relreplident == REPLICA_IDENTITY_DEFAULT || rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL || rel->rd_rel->relreplident == REPLICA_IDENTITY_INDEX"
Previous Message Tom Lane 2020-01-12 04:20:56 Re: logical decoding : exceeded maxAllocatedDescs for .spill files