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 1mhHSc-0006w6-6o for pgsql-general@arkaria.postgresql.org; Sun, 31 Oct 2021 20:29:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mhHSZ-00085R-D2 for pgsql-general@arkaria.postgresql.org; Sun, 31 Oct 2021 20:29:43 +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 1mhHSZ-00085H-3Z for pgsql-general@lists.postgresql.org; Sun, 31 Oct 2021 20:29:43 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mhHSR-0002Lo-C0 for pgsql-general@lists.postgresql.org; Sun, 31 Oct 2021 20:29:41 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 28F7C5974; Sun, 31 Oct 2021 21:29:33 +0100 (CET) Date: Sun, 31 Oct 2021 21:29:33 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Question: Is it possible to get the new xlog position after query execution? Message-ID: Mail-Followup-To: pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="id+RoIf3ktbtRxDJ" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --id+RoIf3ktbtRxDJ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-10-29 13:22:56 -0400, Oleg Serov wrote: > We are using a master/slave replication system where we perform writes on > master and use replication to offload reads. >=20 > However, sometimes we have a replication lag of a few seconds and as a re= sult, > after the update, the change is not yet available on the replica.=A0 >=20 > Is there a way to get XLOG position to which specific update query will be > written? That way we can check if our replica caught up with changes and = it is > safe to read it from. Can it be done using SQL functions? Can I get that > information from query protocol? I think I would prefer a more direct approach: If you know what you've written, can't you just check whether the replica has the new value(s)? If not, an alternative could be a table which contains a simple counter or timestamp: begin; (lots of updates ...) commit; begin; update counter set c =3D c + 1 returning c; -- save this as c_current commit; Select c from counter on the replica in a loop until c >=3D c_current. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --id+RoIf3ktbtRxDJ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmF+/KgACgkQ8g5IURL+ KF1Lyw/9EnNZnGZlTZEkfSDuitjpxhNFu0LRf61/rpEFDidvOEzDRRuw+2G5CyFi D3KPa0LgTKivU+HdIaNsmBrtZMS38BuLjPZmWo7bJQ+WmbTQsmYnuRjGsMvbuivf XwbTGtnmvboGQHQ321iAzirLwQkk0K379Exmpl7A8TOLhOZTTzFXW3XbrLM2rk/K x+068tQ/TOvVg5rsqpiuEwBjdth+9ocJh5+wn7wg7Zjv/9TFGIsjaJ/pNAoWL3ai VB9fhNhCDW3gK6TfM86z0e70Tqt+xax8V19WDwuBJj68+ewGzVple9DVqmvqrESN XeJwYkjLzalU9GaABgYZ6DUTjIpeTzBgtj8VAN8nYb4VRXSIl4zQGWiSoBo8emf/ JOtyjzSJIkHlzH0FxXRf3j2GuhePahGmx9lbb0W8uYtJXyTqRrTakv5TnLh7GyDv KEj7v8DfWK2KhfD5vRc+Y8lt+2Sm4GfHEnU8Gxw0ArCgUVVpsJmWJkCGJJ0NudY/ 0atAU0njpjeYCPYqaAXDTWrLrvdESWC39rwJSdLMMa/ia4QxggxHH5f0/I2zEunV 7z/EcFz9jX2DD/JDo+zgnOUdtwUdKerYdXNa8g5Da10uyzbeg6UaQaBZLUbkwLFJ /hPZ0gctKEBeSYutUJCyMAtOTWyFZupAid9oJHW+TaB0BolG4rI= =Tr9U -----END PGP SIGNATURE----- --id+RoIf3ktbtRxDJ--