pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedReplication sequence
7+ messages / 3 participants
[nested] [flat]
* Replication sequence
@ 2021-02-15 17:55 Paolo Saudin <paolosaudin@gmail.com>
0 siblings, 2 replies; 7+ messages in thread
From: Paolo Saudin @ 2021-02-15 17:55 UTC (permalink / raw)
To: pgsql-general
Hi all,
I have two servers, a primary and a secondary one with a streaming replica
setup.
Today I noticed that some sequences are not lined-up, the replica ones are
well ahead, while the records number is the same. How is it possible?
Thanks,
Paolo
--
-- primary server
--
postgres@db-srv1:~$ psql
psql (9.5.19)
cf-db-srv1:5432 postgres@rete_llpp=# SELECT last_value FROM
bobo.menu_pages_mp_id_seq;
┌────────────┐
│ last_value │
├────────────┤
│ 74 │
└────────────┘
cf-db-srv1:5432 postgres@rete_llpp=# select count(*) from bobo.menu_pages;
┌───────┐
│ count │
├───────┤
│ 74 │
└───────┘
--
-- replica server
--
postgres@db-srv2:~$ psql
psql (9.5.24)
cf-db-srv2:5433 postgres@rete_llpp=# SELECT last_value FROM
bobo.menu_pages_mp_id_seq;
┌────────────┐
│ last_value │
├────────────┤
│ 105 │
└────────────┘
cf-db-srv2:5433 postgres@rete_llpp=# select count(*) from bobo.menu_pages;
┌───────┐
│ count │
├───────┤
│ 74 │
└───────┘
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-15 19:40 Loles <lolesft@gmail.com>
parent: Paolo Saudin <paolosaudin@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Loles @ 2021-02-15 19:40 UTC (permalink / raw)
To: Paolo Saudin <paolosaudin@gmail.com>; +Cc: pgsql-general
One thing is the number of records in the table and another is the current
value of the sequence.
Execute:
select max (field) from bobo.menu_pages;
In both master and slave server.
What give you back?
"field" is the data that belongs to the sequence.
El lun., 15 feb. 2021 18:55, Paolo Saudin <paolosaudin@gmail.com> escribió:
> Hi all,
> I have two servers, a primary and a secondary one with a streaming replica
> setup.
> Today I noticed that some sequences are not lined-up, the replica ones are
> well ahead, while the records number is the same. How is it possible?
>
> Thanks,
> Paolo
>
> --
> -- primary server
> --
> postgres@db-srv1:~$ psql
> psql (9.5.19)
> cf-db-srv1:5432 postgres@rete_llpp=# SELECT last_value FROM
> bobo.menu_pages_mp_id_seq;
> ┌────────────┐
> │ last_value │
> ├────────────┤
> │ 74 │
> └────────────┘
> cf-db-srv1:5432 postgres@rete_llpp=# select count(*) from
> bobo.menu_pages;
> ┌───────┐
> │ count │
> ├───────┤
> │ 74 │
> └───────┘
>
> --
> -- replica server
> --
> postgres@db-srv2:~$ psql
> psql (9.5.24)
> cf-db-srv2:5433 postgres@rete_llpp=# SELECT last_value FROM
> bobo.menu_pages_mp_id_seq;
> ┌────────────┐
> │ last_value │
> ├────────────┤
> │ 105 │
> └────────────┘
> cf-db-srv2:5433 postgres@rete_llpp=# select count(*) from bobo.menu_pages;
> ┌───────┐
> │ count │
> ├───────┤
> │ 74 │
> └───────┘
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-16 06:27 Paolo Saudin <paolosaudin@gmail.com>
parent: Loles <lolesft@gmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Saudin @ 2021-02-16 06:27 UTC (permalink / raw)
To: Loles <lolesft@gmail.com>; +Cc: pgsql-general
Il giorno lun 15 feb 2021 alle ore 20:40 Loles <lolesft@gmail.com> ha
scritto:
> One thing is the number of records in the table and another is the current
> value of the sequence.
>
> Execute:
>
> select max (field) from bobo.menu_pages;
>
> In both master and slave server.
>
> What give you back?
>
> "field" is the data that belongs to the sequence.
>
>
>
> El lun., 15 feb. 2021 18:55, Paolo Saudin <paolosaudin@gmail.com>
> escribió:
>
>> Hi all,
>> I have two servers, a primary and a secondary one with a streaming
>> replica setup.
>> Today I noticed that some sequences are not lined-up, the replica ones
>> are well ahead, while the records number is the same. How is it possible?
>>
>> Thanks,
>> Paolo
>>
>> --
>> -- primary server
>> --
>> postgres@db-srv1:~$ psql
>> psql (9.5.19)
>> cf-db-srv1:5432 postgres@rete_llpp=# SELECT last_value FROM
>> bobo.menu_pages_mp_id_seq;
>> ┌────────────┐
>> │ last_value │
>> ├────────────┤
>> │ 74 │
>> └────────────┘
>> cf-db-srv1:5432 postgres@rete_llpp=# select count(*) from
>> bobo.menu_pages;
>> ┌───────┐
>> │ count │
>> ├───────┤
>> │ 74 │
>> └───────┘
>>
>> --
>> -- replica server
>> --
>> postgres@db-srv2:~$ psql
>> psql (9.5.24)
>> cf-db-srv2:5433 postgres@rete_llpp=# SELECT last_value FROM
>> bobo.menu_pages_mp_id_seq;
>> ┌────────────┐
>> │ last_value │
>> ├────────────┤
>> │ 105 │
>> └────────────┘
>> cf-db-srv2:5433 postgres@rete_llpp=# select count(*) from
>> bobo.menu_pages;
>> ┌───────┐
>> │ count │
>> ├───────┤
>> │ 74 │
>> └───────┘
>>
>>
Hi, I checked and the number of records are identical,
cf-db-srv1:5432 postgres@rete_llpp=# select max(mp_id) from bobo.menu_pages;
┌─────┐
│ max │
├─────┤
│ 74 │
└─────┘
cf-db-srv2:5433 postgres@rete_llpp=# select max(mp_id) from bobo.menu_pages;
┌─────┐
│ max │
├─────┤
│ 74 │
└─────┘
Thank you,
Paolo
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-16 09:51 Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
parent: Paolo Saudin <paolosaudin@gmail.com>
1 sibling, 1 reply; 7+ messages in thread
From: Jehan-Guillaume de Rorthais @ 2021-02-16 09:51 UTC (permalink / raw)
To: Paolo Saudin <paolosaudin@gmail.com>; +Cc: pgsql-general
On Mon, 15 Feb 2021 18:55:14 +0100
Paolo Saudin <paolosaudin@gmail.com> wrote:
> Hi all,
> I have two servers, a primary and a secondary one with a streaming replica
> setup.
> Today I noticed that some sequences are not lined-up, the replica ones are
> well ahead, while the records number is the same. How is it possible?
This is because sequences are not WAL logged on every nextval() call, but by
batch of sequence cache+32 values. As standbys are fed with WAL stream from
primary, their sequences appears jump, then stall, then jump, etc.
See:
https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/sequence.c?id=f672df5fdd22d...
https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/sequence.c?id=f672df5fdd22d...
I'm not sure if this is documented somewhere... ?
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-16 12:10 Paolo Saudin <paolosaudin@gmail.com>
parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
0 siblings, 1 reply; 7+ messages in thread
From: Paolo Saudin @ 2021-02-16 12:10 UTC (permalink / raw)
To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; +Cc: pgsql-general
Il giorno mar 16 feb 2021 alle ore 10:51 Jehan-Guillaume de Rorthais <
jgdr@dalibo.com> ha scritto:
> On Mon, 15 Feb 2021 18:55:14 +0100
> Paolo Saudin <paolosaudin@gmail.com> wrote:
>
> > Hi all,
> > I have two servers, a primary and a secondary one with a streaming
> replica
> > setup.
> > Today I noticed that some sequences are not lined-up, the replica ones
> are
> > well ahead, while the records number is the same. How is it possible?
>
> This is because sequences are not WAL logged on every nextval() call, but
> by
> batch of sequence cache+32 values. As standbys are fed with WAL stream from
> primary, their sequences appears jump, then stall, then jump, etc.
>
> See:
>
> https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/sequence.c?id=f672df5fdd22d...
>
>
> https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/sequence.c?id=f672df5fdd22d...
>
> I'm not sure if this is documented somewhere... ?
>
Thank you very much!
So in case the primary server crashes, and the backup one gets live, it
will eventually have different sequences. I suppose there is no way to
avoid this, isnt'it?
Paolo
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-16 12:38 Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
parent: Paolo Saudin <paolosaudin@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Jehan-Guillaume de Rorthais @ 2021-02-16 12:38 UTC (permalink / raw)
To: Paolo Saudin <paolosaudin@gmail.com>; +Cc: pgsql-general
On Tue, 16 Feb 2021 13:10:54 +0100
Paolo Saudin <paolosaudin@gmail.com> wrote:
> Il giorno mar 16 feb 2021 alle ore 10:51 Jehan-Guillaume de Rorthais <
> [...]
>
> [...]
> [...]
> [...]
> [...]
> [...]
> [...]
> [...]
>
> Thank you very much!
> So in case the primary server crashes, and the backup one gets live, it
> will eventually have different sequences.
No. You will just have a gap in the sequence, on both side.
And if you decided to promote your standby to production, you'll have to resync
the old primary anyway.
> I suppose there is no way to
> avoid this, isnt'it?
You can't avoid gap.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Replication sequence
@ 2021-02-16 14:28 Paolo Saudin <paolosaudin@gmail.com>
parent: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Saudin @ 2021-02-16 14:28 UTC (permalink / raw)
To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>; +Cc: pgsql-general
Thank you!
Il giorno mar 16 feb 2021 alle ore 13:38 Jehan-Guillaume de Rorthais <
jgdr@dalibo.com> ha scritto:
> On Tue, 16 Feb 2021 13:10:54 +0100
> Paolo Saudin <paolosaudin@gmail.com> wrote:
>
> > Il giorno mar 16 feb 2021 alle ore 10:51 Jehan-Guillaume de Rorthais <
> > [...]
> >
> > [...]
> > [...]
> > [...]
> > [...]
> > [...]
> > [...]
> > [...]
> >
> > Thank you very much!
> > So in case the primary server crashes, and the backup one gets live, it
> > will eventually have different sequences.
>
> No. You will just have a gap in the sequence, on both side.
>
> And if you decided to promote your standby to production, you'll have to
> resync
> the old primary anyway.
>
> > I suppose there is no way to
> > avoid this, isnt'it?
>
> You can't avoid gap.
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2021-02-16 14:28 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 17:55 Replication sequence Paolo Saudin <paolosaudin@gmail.com>
2021-02-15 19:40 ` Loles <lolesft@gmail.com>
2021-02-16 06:27 ` Paolo Saudin <paolosaudin@gmail.com>
2021-02-16 09:51 ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2021-02-16 12:10 ` Paolo Saudin <paolosaudin@gmail.com>
2021-02-16 12:38 ` Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
2021-02-16 14:28 ` Paolo Saudin <paolosaudin@gmail.com>
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