Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0gmi-0000iT-33 for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 04:32:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0gmh-0004O8-MB for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Oct 2017 04:32:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0glz-00037m-5W for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 04:31:35 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0glw-0000CF-Os for pgsql-bugs@postgresql.org; Sat, 07 Oct 2017 04:31:34 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2090620E1D; Sat, 7 Oct 2017 00:31:32 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Sat, 07 Oct 2017 00:31:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=BD9VYFJlM3obeEdonO eaKyG3Gn1yUzH0Xl16IeIOek4=; b=H0U95a93qNCL3+tGDAakB27q/raUXNvzl1 xnIJeR6evpWUaQfstcYZ6Niy7Ll+agkQL6B1lKFSVUO2cQ6gV7U+mmV1b4FOBYNK ULnaAvyPJrGg3JpvKFJb/lPOS4J1Bg1+MlvFpR/+P3u0ZPg2XqLjrV16T1rDqYkX a9V3NgGFL3f5qod8JkQGgDw7wrX4cbs8f01CwqmvpPKAabA5psFB9muDUgemTXAY goB/J34Y3m3WPlaice2KztH1WhefQehztgg2eTNMBxTliGSASjTYoU0PvjcBBQXd e8nj8epnlN6Hn/Mgo0rq64JzLJSrqgO4tWr4VB1R6I/nYGtQryHQ== X-ME-Sender: X-Sasl-enc: Q62rax9QzocYOCNNGWIFO8yMjqFFBDf4BPo0cQp2xND/ 1507350691 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id D151C7E3E0; Sat, 7 Oct 2017 00:31:31 -0400 (EDT) Date: Fri, 6 Oct 2017 21:31:30 -0700 From: Andres Freund To: Ben Chobot Cc: pgsql-bugs@postgresql.org Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql Message-ID: <20171007043130.zronedebya6iwtum@alap3.anarazel.de> References: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hi, On 2017-10-04 13:59:20 -0700, Ben Chobot wrote: > postgres=# CREATE OR REPLACE FUNCTION logical_replication_slot_lsn_delta(slot text) RETURNS pg_lsn AS > postgres-# $$ > postgres$# BEGIN > postgres$# return location from pg_logical_slot_peek_changes(slot,null,1) limit 1; > postgres$# END > postgres$# $$ language plpgsql; As the issue is fixed now, I just want to mention that looking at logical decoding output via the SQL interface, especially when doing it in very small increments as you're suggesting here, is way much more expensive than continually streaming changes via the replication protocol. In a lot of cases it'll be orders of magnitude more expensive. So if you can change your usecase to use that, you'll benefit. It also avoids having to change between peek/get, because you can just send back messages specifying up to where you've processed changes safely. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs