pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16498: The master inserts data successfully when the standby stopped in synchronous stream replication
2+ messages / 2 participants
[nested] [flat]

* BUG #16498: The master inserts data successfully when the standby stopped in synchronous stream replication
@ 2020-06-18 03:20  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2020-06-18 03:20 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: abcxiaod@126.com

The following bug has been logged on the website:

Bug reference:      16498
Logged by:          yi Ding
Email address:      abcxiaod@126.com
PostgreSQL version: 10.12
Operating system:   linux
Description:        

Master PGserver:
1、Table test_1 currently has no data
postgres=# select * from test_1;
 a
---
(0 rows)

2、Synchronous streaming replication
postgres=# show synchronous_standby_names ;
 synchronous_standby_names
---------------------------
 sb2019abcd514
(1 row)

3、Stop the standby PGserver

4、Insert data

postgres=# begin;
BEGIN
postgres=# insert into test_1 values(2);
INSERT 0 1
postgres=# insert into test_1 values(3);
INSERT 0 1
postgres=# commit;

commit stuck

5、Restart the database

6、Check table test_1, data is still committed

postgres=# select * from test_1;
 a
---
2
3
(0 rows)

7、Code structure
CommitTransaction->RecordTransactionCommit::
    if ((wrote_xlog && markXidCommitted && synchronous_commit >
SYNCHRONOUS_COMMIT_OFF) || forceSyncCommit || nrels > 0){
         XLogFlush(XactLastRecEnd);
         /*
          * Now we may update the CLOG, if we wrote a COMMIT record above
          */
        if (markXidCommitted)
            TransactionIdCommitTree(xid, nchildren, children);
    }else{
        XLogSetAsyncXactLSN(XactLastRecEnd);
        if (markXidCommitted)
            TransactionIdAsyncCommitTree(xid, nchildren, children,
XactLastRecEnd);
    }
    ...
    if (wrote_xlog && markXidCommitted)
        SyncRepWaitForLSN(XactLastRecEnd, true);
	  	if (!SyncRepRequested())
	      	return;
	  	for(;;){
	     	  
	    }
    ...
#define SyncRepRequested() \
	(max_wal_senders > 0 && synchronous_commit >
SYNCHRONOUS_COMMIT_LOCAL_FLUSH)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #16498: The master inserts data successfully when the standby stopped in synchronous stream replication
@ 2020-06-18 15:40  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2020-06-18 15:40 UTC (permalink / raw)
  To: abcxiaod@126.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> [ $subject ]

I don't think this is a bug; you are just misunderstanding the guarantee
that synchronous replication offers.  In syncrep mode, the primary server
commits and then waits for some number of standbys to acknowledge having
replicated that commit action before it tells the client the commit is
complete.  Killing the primary during that wait does not, and cannot,
cause the commit not to have happened.

What I think you are looking for is two-phase commit, which is a whole
different animal that is far more complex and expensive than syncrep.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-06-18 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 03:20 BUG #16498: The master inserts data successfully when the standby stopped in synchronous stream replication PG Bug reporting form <noreply@postgresql.org>
2020-06-18 15:40 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox