> 11 янв. 2020 г., в 7:34, Bruce Momjian <br...@momjian.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.

Reply via email to