pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedUrgent :: Postgresql streaming replication issue - sync mode
7+ messages / 4 participants
[nested] [flat]
* Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-02 18:28 Shital A <brightuser2019@gmail.com>
0 siblings, 2 replies; 7+ messages in thread
From: Shital A @ 2019-10-02 18:28 UTC (permalink / raw)
To: pgsql-general
Hello,
We are seeing a strange issue with postgresql streaming application in sync
mode.
We are using postgresql 9.6. Old version because of some specific
requirements. We have setup cluster with master-standby using pacemaker.
When we kill master using killall -9 postgres. The failed primary has few
records extra than standby node. We have done setup with synchronous_commit
= remote_apply and have set synchronous_standby_names=server_name.
As the failed primary is having more data, How is it possible that primary
is committing transaction before they were applied on standby with
synchronous_commit=remote_apply?
Please share if you have any thoughts. Are we missing any config ?
Thanks !
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-02 18:38 Ravi Krishna <srkrishna@vivaldi.net>
parent: Shital A <brightuser2019@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Ravi Krishna @ 2019-10-02 18:38 UTC (permalink / raw)
To: Shital A <brightuser2019@gmail.com>; +Cc: pgsql-general
>
> As the failed primary is having more data, How is it possible that primary is committing transaction before they were applied on standby with synchronous_commit=remote_apply?
If I am not mistaken remote_apply is only from ver 11.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-02 21:00 Shital A <brightuser2019@gmail.com>
parent: Ravi Krishna <srkrishna@vivaldi.net>
0 siblings, 1 reply; 7+ messages in thread
From: Shital A @ 2019-10-02 21:00 UTC (permalink / raw)
To: Ravi Krishna <srkrishna@vivaldi.net>; +Cc: pgsql-general
On Thu, 3 Oct 2019, 00:08 Ravi Krishna, <srkrishna@vivaldi.net> wrote:
> >
> > As the failed primary is having more data, How is it possible that
> primary is committing transaction before they were applied on standby with
> synchronous_commit=remote_apply?
>
> If I am not mistaken remote_apply is only from ver 11.
>
Hi Ravi,
Thanks for your reply.
This property/feature is available in 9.6.
https://www.postgresql.org/docs/9.6/runtime-config-wal.html
Thanks!
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-03 03:00 Shital A <brightuser2019@gmail.com>
parent: Shital A <brightuser2019@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Shital A @ 2019-10-03 03:00 UTC (permalink / raw)
To: Jason Wang <jasonwang.public@gmail.com>; pgsql-general
On Thu, 3 Oct 2019, 03:10 Jason Wang, <jasonwang.public@gmail.com> wrote:
> I think when you use kill -9 it wouldn't give any chance for postgres to
> do what it normally does. So in your case, the db was killed with no chance
> to apply to remote then it would be up to the recovery to decide how to
> handle the extra data at the master. I'm not sure what would happen but
> killall in general is a dangerous command.
>
> On Thu, 3 Oct 2019, 7:00 am Shital A, <brightuser2019@gmail.com> wrote:
>
>>
>>
>> On Thu, 3 Oct 2019, 00:08 Ravi Krishna, <srkrishna@vivaldi.net> wrote:
>>
>>> >
>>> > As the failed primary is having more data, How is it possible that
>>> primary is committing transaction before they were applied on standby with
>>> synchronous_commit=remote_apply?
>>>
>>> If I am not mistaken remote_apply is only from ver 11.
>>>
>>
>> Hi Ravi,
>>
>> Thanks for your reply.
>>
>> This property/feature is available in 9.6.
>> https://www.postgresql.org/docs/9.6/runtime-config-wal.html
>>
>>
>> Thanks!
>>
>
Thanks Jason.
Using killall -9 we are trying to simulate the situation where primary is
stopped unexpectedly/crashed.
So in this case there is data loss because when the broken primary later
comes in sync with new primary it copies data from new primary and the data
records that were extra in old primary are lost. Can this data loss be
prevented in anyway in postgres 9.6 ? Please suggest.
Thanks!
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-03 11:41 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Shital A <brightuser2019@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Laurenz Albe @ 2019-10-03 11:41 UTC (permalink / raw)
To: Shital A <brightuser2019@gmail.com>; pgsql-general
On Wed, 2019-10-02 at 23:58 +0530, Shital A wrote:
> We are seeing a strange issue with postgresql streaming application
> in sync mode.
>
> We are using postgresql 9.6. Old version because of some specific
> requirements. We have setup cluster with master-standby using
> pacemaker.
>
> When we kill master using killall -9 postgres. The failed primary has
> few records extra than standby node. We have done setup with
> synchronous_commit = remote_apply and have set
> synchronous_standby_names=server_name.
>
> As the failed primary is having more data, How is it possible that
> primary is committing transaction before they were applied on standby
> with synchronous_commit=remote_apply?
>
>
> Please share if you have any thoughts. Are we missing any config ?
This is to be expected.
The transaction will be committed on the primary, then on the standby,
and COMMIT will only return once the standby reports success.
But the transacaction still has to be committed on the primary first.
If the standby sis promoted while COMMIT is waiting for the standby,
you can end up with the transaction committed on the primary,
but not yet committed on the standby.
You should use "pg_rewind" on the failed primary if you want to use
it as new standby for the promoted server.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-03 14:34 Jason Wang <jasonwang.public@gmail.com>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 7+ messages in thread
From: Jason Wang @ 2019-10-03 14:34 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; Shital A <brightuser2019@gmail.com>; +Cc: pgsql-general
I read this
https://www.2ndquadrant.com/en/blog/evolution-fault-tolerance-postgresql-synchronous-commit/
But don't see why your primary would have more records than the standby?
If killall was issued before commit returned, that means the transaction
wasn't completed so yes you would lose records after last commit but that's
expected; if commit was returned both primary and standby should have the
transaction.
Are you sure in your case you end up with primary and standby with
different records from a single transaction?
On Thu, 3 Oct 2019, 9:41 pm Laurenz Albe, <laurenz.albe@cybertec.at> wrote:
> On Wed, 2019-10-02 at 23:58 +0530, Shital A wrote:
> > We are seeing a strange issue with postgresql streaming application
> > in sync mode.
> >
> > We are using postgresql 9.6. Old version because of some specific
> > requirements. We have setup cluster with master-standby using
> > pacemaker.
> >
> > When we kill master using killall -9 postgres. The failed primary has
> > few records extra than standby node. We have done setup with
> > synchronous_commit = remote_apply and have set
> > synchronous_standby_names=server_name.
> >
> > As the failed primary is having more data, How is it possible that
> > primary is committing transaction before they were applied on standby
> > with synchronous_commit=remote_apply?
> >
> >
> > Please share if you have any thoughts. Are we missing any config ?
>
> This is to be expected.
>
> The transaction will be committed on the primary, then on the standby,
> and COMMIT will only return once the standby reports success.
>
> But the transacaction still has to be committed on the primary first.
>
> If the standby sis promoted while COMMIT is waiting for the standby,
> you can end up with the transaction committed on the primary,
> but not yet committed on the standby.
>
> You should use "pg_rewind" on the failed primary if you want to use
> it as new standby for the promoted server.
>
> Yours,
> Laurenz Albe
> --
> Cybertec | https://www.cybertec-postgresql.com
>
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Urgent :: Postgresql streaming replication issue - sync mode
@ 2019-10-03 15:34 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Jason Wang <jasonwang.public@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Laurenz Albe @ 2019-10-03 15:34 UTC (permalink / raw)
To: Jason Wang <jasonwang.public@gmail.com>; Shital A <brightuser2019@gmail.com>; +Cc: pgsql-general
On Fri, 2019-10-04 at 00:34 +1000, Jason Wang wrote:
> I read this
> https://www.2ndquadrant.com/en/blog/evolution-fault-tolerance-postgresql-synchronous-commit/
>
> But don't see why your primary would have more records than the
> standby?
>
> If killall was issued before commit returned, that means the
> transaction wasn't completed so yes you would lose records after last
> commit but that's expected; if commit was returned both primary and
> standby should have the transaction.
>
> Are you sure in your case you end up with primary and standby with
> different records from a single transaction?
PostgreSQL synchronous streaming replicatoin doesn't use anything like
two-phase commit.
1. It commits the transaction locally first, which generates WAL.
2. The WAL gets replicated.
3. As soon as the standby reports success, COMMIT returns.
If there is a failure after the first step completed, the
transaction will be committed locally, but not on the standby.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2019-10-03 15:34 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 18:28 Urgent :: Postgresql streaming replication issue - sync mode Shital A <brightuser2019@gmail.com>
2019-10-02 18:38 ` Ravi Krishna <srkrishna@vivaldi.net>
2019-10-02 21:00 ` Shital A <brightuser2019@gmail.com>
2019-10-03 03:00 ` Shital A <brightuser2019@gmail.com>
2019-10-03 11:41 ` Laurenz Albe <laurenz.albe@cybertec.at>
2019-10-03 14:34 ` Jason Wang <jasonwang.public@gmail.com>
2019-10-03 15:34 ` Laurenz Albe <laurenz.albe@cybertec.at>
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