Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edn8w-0002MQ-9V for pgsql-general@arkaria.postgresql.org; Tue, 23 Jan 2018 01:12:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edn8v-0003nU-1k for pgsql-general@arkaria.postgresql.org; Tue, 23 Jan 2018 01:12:53 +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 1edn8u-0003nK-4F for pgsql-general@lists.postgresql.org; Tue, 23 Jan 2018 01:12:52 +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.89) (envelope-from ) id 1edn8k-0006XR-TL for pgsql-general@postgresql.org; Tue, 23 Jan 2018 01:12:50 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 90100208B1; Mon, 22 Jan 2018 20:12:40 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Mon, 22 Jan 2018 20:12:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=fe0RUQ0u6zM7woO9kdFVXlPr2Kf2j /u7YnInszW34KA=; b=mSP5ReFqiVkXXi58EJPqopnpoKTiFjaYQBfB/I1ckE4ik 3xDrpAcUW+YcZMYckfKoLjzGxevcjyahPIHazNDph8Dz1wkLTtFvP26e83P7ckkE t/bkBbJ3Q+3rsCfJjR32gSA2bv9fLk6+T/4eDprPk2QL68+NWYPRpnrIEkjSBgE5 Wvw9HtxvVz6Ws7yvd7jDo7T1nPboNinuNFySf41Y7vWqAWFdSm28Enk0g/uKaCuF jRScaR3xuD/lLHNgHHiUROxjm2BBAcOH4cVoT2Xvcg5s3thVYhNTTTQbm64kOtgw /Ic92urj5jTtiqkG7cr1LCU/6wpH9cbI312IJoMhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=fe0RUQ 0u6zM7woO9kdFVXlPr2Kf2j/u7YnInszW34KA=; b=GcDsuc+VXJGRCjskn1LzJY KO5QyFQt0Pmc5XO39Yjuk1rfZ1otDXQ1Shq8XH157cVAaOOb4Vi1PW47ZRhjSHUt eYnSJZdxtgWFIk8mEkt5ifgGj3x/0Basq1qANUv6/4LjFT7lHwT5UToXPdbGTiOd OSRzYmW4WDksojvP9mOkcKVahNhe21KdguaTMD45tMXgaWfJqK5IRoV1ySUuKsHr pu+D7vyUItHKmhsKzamjrj7TRWBXUwKiwLv3sVNu/KY4AgnTHrnTr0IuXLAMRGk/ /SP8ImzCkjvICfIJTybCa61T0iGX2Swa1rikxGTPm9iI7SAeCLk8L8ddKDYXPmlQ == X-ME-Sender: Received: from ranger.suse (unknown [67.40.177.89]) by mail.messagingengine.com (Postfix) with ESMTPA id 10161240F8; Mon, 22 Jan 2018 20:12:39 -0500 (EST) Subject: Re: Slow alter sequence with PG10.1 To: =?UTF-8?Q?Michael_Kr=c3=bcger?= Cc: pgsql-general@postgresql.org References: <2ab64bf6-b3e3-3ae9-8c69-0eb58ebca3c1@aklaver.com> From: Adrian Klaver Message-ID: <56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com> Date: Mon, 22 Jan 2018 17:12:39 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/22/2018 02:47 PM, Michael Krüger wrote: > Hello all, > > after changing the function to this: > > CREATE OR REPLACE FUNCTION multi_nextval( > use_seqname text, > use_increment integer) >     RETURNS bigint >     LANGUAGE 'plpgsql' >     COST 100 >     VOLATILE > AS $BODY$ > DECLARE >     reply int8; >     lock_id int4; >     seq_idx int8; > BEGIN >     SELECT oid::int4 INTO lock_id FROM pg_class WHERE relname = > split_part(use_seqname, '.', 2); >     perform pg_advisory_lock(lock_id); > >     seq_idx :=nextval(use_seqname); >     perform setval(use_seqname, seq_idx + use_increment - 1, 't'); > >     perform pg_advisory_unlock(lock_id); >     return seq_idx; > END; > $BODY$; > > I do get a total execution time of Time: 5922,428 ms (00:05,922) - much > better than before. > > Is there any drawback to use setval compared to the ALTER SEQUENCE which > I have used before? If not, then this could be the work around to go > with as it has a similar performance to the original function. > > I guess - the reason I'm a bit disappointed from the new behavior is > that we have used Postgresql for more than 10 years and it has never let > us down. We have been able to improve our product with every new release Well the nature of major version releases is that they can break backwards compatibility. This is one of the reasons there is 5 year community support on versions, time to develop a migration plan. I have been caught by changes, before e.g. the 8.3 change in casting rules, a later change that made plpythonu use Python rules for truthfulness instead of SQL, etc. You seem to have had a run of good luck. Going forward I would assume a major release will contain breaking changes and test thoroughly. > of Postgres. This is the first time for me that a new release of > Postgres caused some severe headaches among our customers. > If you all agree that this changed function should be equivalent to the > original one, then its at least an easy fix. > > Thank you all for your fast responses. > > Regards, > Michael > -- Adrian Klaver adrian.klaver@aklaver.com