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 1jd6oR-0005Ej-HO for pgsql-admin@arkaria.postgresql.org; Mon, 25 May 2020 06:42:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jd6oQ-00041b-8X for pgsql-admin@arkaria.postgresql.org; Mon, 25 May 2020 06:42:14 +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 1jd6oP-00041U-Py for pgsql-admin@lists.postgresql.org; Mon, 25 May 2020 06:42:14 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jd6oM-0003XH-VO for pgsql-admin@lists.postgresql.org; Mon, 25 May 2020 06:42:13 +0000 Received: by mail-ed1-x541.google.com with SMTP id l5so14103117edn.7 for ; Sun, 24 May 2020 23:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=6eD/lMsoyvnbynUSAuzIp8L7ZBiaeO51gzb5bVdN+zc=; b=NUFOf+5hqTGCKkzGsTT3PtO2TVYTmVkOtlc0V2lBJ78eWuwXvvePrE3+enMC4aBasi 7oYOSbYaYjZAWpuiET9HXB0+XCemP+6i6LCCBxjSXgRFIEXtAX2YaXd55Hg0mg0bv/fY 9E67n62yvUK2Y39d+O5cF8M8pHlsllVTQsj5jPI1HiRHtRTzNB8qR6Sbtc68d7VyJZRj bKgR7bjMuIjunB6aXGUHSTQ3wTLZsbwvYDGiDCxJ+pWDjJC1bXGUl9ny8qTC7V1Tae4g aW47pW9JbhgVnOY1DhJ3JP8A6H41fsIh1QXcEGH53Dkk5UkG2ER7xJKQiNWRYsV0fUMn Uhmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=6eD/lMsoyvnbynUSAuzIp8L7ZBiaeO51gzb5bVdN+zc=; b=NRyJIlshASOnzHplitPWSrtQoC7jlpZ4/CH/Kisvztb2xtDTm90MgvlyMIgxeh+yLG HslPjuqMucx13Px/YDFY6TrxeEsLb73VQsxv+/4bPcfFdeI1fLnhWxzc6N5CguOKFKdg XVUtgm3eAs1p4wIybQCHTqSfro8nb83mhplrDngJfk4ndGMV5txQ2JRaWQYG7N8Mr72i M7gd2/9L7zjdN1Lt34AsOnucexTLOMztObp3cGfpNNXVSWbcYtilhOeH87b8iN/Jo6Ob LZlC2cr+6hrHDcl1wJHCEVVufroQGGUEZpACeQ+5FWfh9QxKmeD0NZV2Vvmdk7ib4Ugg qTsA== X-Gm-Message-State: AOAM533KdM23XYVo2+kVJ14nj4w6ywQ9adyIAQOpKTltAKAZ4p0hIPG5 tCFHZpjFnewn1IpPPj/Je62G2A== X-Google-Smtp-Source: ABdhPJzfWnCoGprJypqjnK9VceqGEaOw2I0bVbnD2B17Dhx2x9yvT1j/HGIPgR30BnkdSm3nI1Hb/Q== X-Received: by 2002:a05:6402:169a:: with SMTP id a26mr13332245edv.321.1590388928988; Sun, 24 May 2020 23:42:08 -0700 (PDT) Received: from localhost.localdomain (217-149-175-226.nat.highway.telekom.at. [217.149.175.226]) by smtp.gmail.com with ESMTPSA id ci6sm14881859ejc.60.2020.05.24.23.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 23:42:08 -0700 (PDT) Message-ID: <34c00892d4434f4a02b9977c3e710361659d7e09.camel@cybertec.at> Subject: Re: Lag clarification with Sync Replication From: Laurenz Albe To: Rui DeSousa , Raj kumar Cc: Pgsql-admin Date: Mon, 25 May 2020 08:42:07 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 2020-05-22 at 12:48 -0400, Rui DeSousa wrote: > > On May 22, 2020, at 12:36 AM, Raj kumar wrote: > > > > . But, ideally for sync replication, lag should be always 0 right. > > Incorrect. Synchronous replication means that a commit will not return until it has been safely written to disk on the primary and the replica. That means the transaction is written to WAL file on > both primary and replica. On the primary, the transaction is also visible to transactions with a later xmin. On the replica, the transaction has been recorded in the WAL; it still needs to get > applied to the database for it to become visible to read transactions. If you set "synchronous_commit = remote_apply", the commit will only return when the change has been replayed on the synchronous standby server. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com