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 1mevIh-0005FY-LD for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Oct 2021 08:25:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mevIg-0002Oa-Aw for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Oct 2021 08:25:46 +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 1mevIg-0002OQ-13 for pgsql-hackers@lists.postgresql.org; Mon, 25 Oct 2021 08:25:46 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mevIZ-0006CQ-AI for pgsql-hackers@lists.postgresql.org; Mon, 25 Oct 2021 08:25:44 +0000 Received: by mail-wr1-x434.google.com with SMTP id d10so7225270wrb.1 for ; Mon, 25 Oct 2021 01:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; h=from:to:cc:subject:date:message-id:organization:in-reply-to :references:mime-version:content-transfer-encoding; bh=sBORrt8rsaejT4uPYaA4doY5/Om4h3t/8/e7oibnkoM=; b=j1BMuQ9fHVXTVYdhkYZoPl3f81nDJ/yJbwx7RN77Wma+HmOe4xPxNAYJqq06IE23Cc JYZZE7H9gFT7Uvs+BOr43P0gPjXC72giTxNwPXv6JCe1bUhiGH609Zqf/2HJqsGVKyI2 EmifExLWXu6IbirSV/RUll/IwhGRLnQva6qls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :in-reply-to:references:mime-version:content-transfer-encoding; bh=sBORrt8rsaejT4uPYaA4doY5/Om4h3t/8/e7oibnkoM=; b=EfqijbuobPkcBwtipKYh8tK5nbjzaaEqof999mDUyMPHk1On64DFEzLEi+GTBdG0QZ /zcgwrO2+Nm+sow3UzS1/AI6+O6bAHhAwdGGY707v0KRvuFRvVC3yOZk7uiF3iTMvLYW XPSdUv15Xje2H841BCOVi0s4S4O1xawFaPKYw3CS/S9sIBXxIvSJ84WaKVsy8QznQ9Np u+41NCvQdQVUywLzx5dN1dlrWrItC8mkWw1o6pSs9/q+G2JcRqS0eEt5DLy5NVzUSfkE fH5bEBLT8zJipamv5Uo8PWZiUI/WaKnK+hWfR8F5NOEdSGdPjfu2Odmte/KFJ0d2/5o6 2xAA== X-Gm-Message-State: AOAM531qgcAhZ9kP2Tqft5Vd6pnHMu6hyQTcL3IlUkpHbeSK24Eou8pd Xrc/B4wna0cwKCuM8CGXYtBvcw== X-Google-Smtp-Source: ABdhPJx3L+yqtvRbFdT/xJitsE0LEdrGkdJxVR+IK9HKYkG4njX/xu3Fk6wC+cXhWWIx2Z+WScMbbQ== X-Received: by 2002:a05:6000:2c9:: with SMTP id o9mr2120734wry.92.1635150337272; Mon, 25 Oct 2021 01:25:37 -0700 (PDT) Received: from aivenronan.localnet (static-176-158-121-96.ftth.abo.bbox.fr. [176.158.121.96]) by smtp.gmail.com with ESMTPSA id w14sm5808518wmi.37.2021.10.25.01.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:25:36 -0700 (PDT) From: Ronan Dunklau To: Michael Paquier Cc: pgsql-hackers@lists.postgresql.org, Bharath Rupireddy , Kyotaro Horiguchi , Masahiko Sawada Subject: Re: pg_receivewal starting position Date: Mon, 25 Oct 2021 10:24:46 +0200 Message-ID: <21259852.EfDdHjke4D@aivenronan> Organization: aiven In-Reply-To: References: <3162614.44csPzL39Z@aivenronan> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le lundi 25 octobre 2021, 10:10:13 CEST Michael Paquier a =E9crit : > On Mon, Oct 25, 2021 at 09:50:01AM +0200, Ronan Dunklau wrote: > > Le lundi 25 octobre 2021, 09:40:10 CEST Michael Paquier a =E9crit : > >> On Mon, Oct 25, 2021 at 09:15:32AM +0200, Ronan Dunklau wrote: > >>> Does it make sense though ? The NULL slot_name case handling is pretty > >>> straight forward has it will be handled by string formatting, but in = the > >>> case of a null restart_lsn, we have no way of knowing if the command = was > >>> issued at all. > >>=20 > >> If I am following your point, I don't think that it matters much here, > >> and it seems useful to me to be able to pass NULL for both of them, so > >> as one can check if the slot exists or not with an API designed this > >> way. > >=20 > > You're right, but I'm afraid we would have to check the server version > > twice in any case different from the basic pg_receivewal on (once in the > > function itself, and one before calling it if we want a meaningful > > result). Maybe we should move the version check outside the > > GetSlotInformation function to avoid this, and let it fail with a syntax > > error when the server doesn't support it ? > With the approach taken by the patch, we fall down silently to the > previous behavior if we connect to a server <=3D 14, and rely on the new > behavior with a server >=3D 15, ensuring compatibility. Why would you > want to make sure that the command is executed when we should just > enforce that the old behavior is what happens when there is a slot > defined and a backend <=3D 14? Sorry I haven't been clear. For the use case of this patch, the current=20 approach is perfect (and we supply the restart_lsn). However, if we want to support the case of "just check if the slot exists",= we=20 need to make sure the command is actually executed, and check the version=20 before calling the function, which would make the check executed twice. What I'm proposing is just that we let the responsibility of checking=20 PQServerVersion() to the caller, and remove it from GetSlotInformation, ie: =2D if (replication_slot !=3D NULL) + if (replication_slot !=3D NULL && PQserverVersion(conn) >= =3D=20 150000) { if (!GetSlotInformation(conn, replication_slot,=20 &stream.startpos, &st= ream.timeline)) That way, if we introduce a caller wanting to use this function as an API t= o=20 check a slot exists, the usage of checking the server version beforehand wi= ll=20 be consistent. =2D-=20 Ronan Dunklau