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 1nQkqn-0000yv-13 for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Mar 2022 06:58:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nQkqE-0007WK-UI for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Mar 2022 06:58:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nQkqE-0007WB-J0 for pgsql-hackers@lists.postgresql.org; Sun, 06 Mar 2022 06:58:06 +0000 Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nQkqC-0003bQ-Vl for pgsql-hackers@lists.postgresql.org; Sun, 06 Mar 2022 06:58:06 +0000 Received: by mail-ua1-x934.google.com with SMTP id j7so5270118uap.5 for ; Sat, 05 Mar 2022 22:58:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ddygG7xHmchSXIlXh5nPli11Zbx/ZPHdJxIAlJTRQ1o=; b=qsdcuT5UfDyFPPgg5PQ8SEHXIqgwh/ZaOejWM2t8HTfwxhLTjDtIelaVZsIwMjrQiD uAR2UV49d+i/7TCEVRhGcCu4y+8o9zl1kBvBg8dXkUK23SZZ/yZePTpxNrfLR9LWuI8y LdQWWzh95y/OtCv96Fnqs28H1Pf+nDUi/8JAGDInYk88df271AXhMdekc5h0MuhwyWSf Xl8VzXqT7fev9IouziSmK3IktP5VMqnWS2x6n0xOuZfV6Q5aP4CnWI6g3QQ2gn5967f0 oY60onFPcjVdklyZDl6xbG34Z5gM3SrHgdYsW9M42Sr58m+prFkuiYtGcxo0v8df6vPS uxeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ddygG7xHmchSXIlXh5nPli11Zbx/ZPHdJxIAlJTRQ1o=; b=t/ZG3M4TcV2XoyJF9PyajiEjVZagjWLylH6hat+bDUMa0g2KHed+GTD6DXQqcqlDqz fRkrNRDYhBFGY+tjMMSZgWDtBSwVlUIfalHzkoYZJb/upnCoW3JhzGPpUHkNH0tMy2OT 57haoCXGZhChIcj9ftb3HfN6Q2Ni/RTlP9J95c0L5YGDagbeYpe5+bL2zl8lj7mmOYBX Cok3vJcgttGTaN7iFXAxBWtZBbfVt5tO2tcYrmpqF/yGxERxXOWC9A4oZoARzpyL/Q5S NDIMXhL/pRh8ApjMqAFDEhrx3xIKxfW+xT2sigEcCIZA4fws7rFwdUtdblOej7g5Q7RG cDHA== X-Gm-Message-State: AOAM5339aE9S0gjULWq8dtbHjsDr/286d5GH/FtYyH9I6YpNSFBsARkx b/pAFTsb3AvMsZMHLAva1GirLnWQF26aJTPpB1Q= X-Google-Smtp-Source: ABdhPJzYE1H9qNq7maoDIEejVZN9nt5NU9uPgxmNEz5gG5d2uf1cFpC+8r4HBUqYzHznZEI5BRa39RQevrHnN6q3O70= X-Received: by 2002:ab0:6f4f:0:b0:342:3ccf:e981 with SMTP id r15-20020ab06f4f000000b003423ccfe981mr1918149uat.115.1646549882813; Sat, 05 Mar 2022 22:58:02 -0800 (PST) MIME-Version: 1.0 References: <20220228185732.GB944837@nathanxps13> <20220301060528.GA1026683@nathanxps13> <20220301.163431.1826638724406024793.horikyota.ntt@gmail.com> <20220301170537.GA1031413@nathanxps13> <20220301212700.GB1033258@nathanxps13> <20220304195602.GA1184024@nathanxps13> <20220305202752.4oll4hgztlgdfykl@alap3.anarazel.de> In-Reply-To: <20220305202752.4oll4hgztlgdfykl@alap3.anarazel.de> From: Bharath Rupireddy Date: Sun, 6 Mar 2022 12:27:52 +0530 Message-ID: Subject: Re: Allow async standbys wait for sync replication To: Andres Freund Cc: Nathan Bossart , Kyotaro Horiguchi , SATYANARAYANA NARLAPURAM , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 6, 2022 at 1:57 AM Andres Freund wrote: > > Hi, > > On 2022-03-05 14:14:54 +0530, Bharath Rupireddy wrote: > > I understand. Even if we use the SyncRepWaitForLSN approach, the async > > walsenders will have to do nothing in WalSndLoop() until the sync > > walsender wakes them up via SyncRepWakeQueue. > > I still think we should flat out reject this approach. The proper way to > implement this feature is to change the protocol so that WAL can be sent to > replicas with an additional LSN informing them up to where WAL can be > flushed. That way WAL is already sent when the sync replicas have acknowledged > receipt and just an updated "flush/apply up to here" LSN has to be sent. I was having this thought back of my mind. Please help me understand these: 1) How will the async standbys ignore the WAL received but not-yet-flushed by them in case the sync standbys don't acknowledge flush LSN back to the primary for whatever reasons? 2) When we say the async standbys will receive the WAL, will they just keep the received WAL in the shared memory but not apply or will they just write but not apply the WAL and flush the WAL to the pg_wal directory on the disk or will they write to some other temp wal directory until they receive go-ahead LSN from the primary? 3) Won't the network transfer cost be wasted in case the sync standbys don't acknowledge flush LSN back to the primary for whatever reasons? The proposed idea in this thread (async standbys waiting for flush LSN from sync standbys before sending the WAL), although it makes async standby slower in receiving the WAL, it doesn't have the above problems and is simpler to implement IMO. Since this feature is going to be optional with a GUC, users can enable it based on the needs. Regards, Bharath Rupireddy.