pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Michael Krüger <michael@kruegers.email>
Cc: pgsql-general@postgresql.org
Subject: Re: Slow alter sequence with PG10.1
Date: Mon, 22 Jan 2018 17:12:39 -0800
Message-ID: <56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com> (raw)
In-Reply-To: <CACSnzzWG5P7f1pYYzN9exa9H3QQuATLHTFBfKYxYPDSoF0JFFg@mail.gmail.com>
References: <CACSnzzXZw+QyvRMJ5s9PjFkYDPwWVswb_FtQLY4FVOp0R02Hpg@mail.gmail.com>
	<2ab64bf6-b3e3-3ae9-8c69-0eb58ebca3c1@aklaver.com>
	<CACSnzzVubWh4V7Xf5KynUC9L6LUB9Pqd6GBZRbw0SP2sR13ZiQ@mail.gmail.com>
	<CACSnzzWG5P7f1pYYzN9exa9H3QQuATLHTFBfKYxYPDSoF0JFFg@mail.gmail.com>

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




view thread (13+ messages)  latest in thread

Message-ID: <56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com>
Permalink:  ../56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com/
Also on:    postgresql.org/message-id/56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, michael@kruegers.email
  Subject: Re: Slow alter sequence with PG10.1
  In-Reply-To: <56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com>
  References: <CACSnzzXZw+QyvRMJ5s9PjFkYDPwWVswb_FtQLY4FVOp0R02Hpg@mail.gmail.com> <2ab64bf6-b3e3-3ae9-8c69-0eb58ebca3c1@aklaver.com> <CACSnzzVubWh4V7Xf5KynUC9L6LUB9Pqd6GBZRbw0SP2sR13ZiQ@mail.gmail.com> <CACSnzzWG5P7f1pYYzN9exa9H3QQuATLHTFBfKYxYPDSoF0JFFg@mail.gmail.com> <56803c7c-e43d-c342-6358-b56a2531c5fd@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox