Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBx1O-00049W-S5 for pgsql-general@arkaria.postgresql.org; Tue, 16 Feb 2021 09:51:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBx1N-0005Zd-Qs for pgsql-general@arkaria.postgresql.org; Tue, 16 Feb 2021 09:51:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBx1N-0005Yf-Gj for pgsql-general@lists.postgresql.org; Tue, 16 Feb 2021 09:51:53 +0000 Received: from mail1.dalibo.net ([212.83.143.11] helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBx1J-0007MH-4N for pgsql-general@postgresql.org; Tue, 16 Feb 2021 09:51:52 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 1CADA1FA38; Tue, 16 Feb 2021 10:51:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1613469106; bh=70EkP1quhvfZIPx2mgTP5w9S9w3L5y6uOv09CeEXoqI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hZKohXskldHR8L47x0cAchxAXx+cyDb5gtyiep4r4KAjZ+LZXSIBImUIXC4spRfor K8N66EXfr3tG5oFLP+DJo0j4jP4jDBZhaWmp+pjsQfqN2DAR5n6O6GdrnZf6MR5Bcz 1GkM/Ct/7rRVy1kkyG9B0RvBvtNO3ywDjQ94pkpo= Date: Tue, 16 Feb 2021 10:51:45 +0100 From: Jehan-Guillaume de Rorthais To: Paolo Saudin Cc: PostgreSQL Subject: Re: Replication sequence Message-ID: <20210216105145.03b5943b@firost> In-Reply-To: References: Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 15 Feb 2021 18:55:14 +0100 Paolo Saudin 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=f672df5fdd22dac14c98d0a0bf5bbaa6ab17f8a5#n52 https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/sequence.c?id=f672df5fdd22dac14c98d0a0bf5bbaa6ab17f8a5#n661 I'm not sure if this is documented somewhere... ?