Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id DA8D713BD197 for ; Fri, 1 Jun 2012 10:48:09 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SaSD1-0003KL-HZ for pgsql-performance@postgresql.org; Fri, 01 Jun 2012 13:48:09 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q51DlrqU023955; Fri, 1 Jun 2012 09:47:53 -0400 (EDT) To: Chris Rimmer cc: pgsql-performance@postgresql.org Subject: Re: Select from sequence in slow query log In-reply-to: References: Comments: In-reply-to Chris Rimmer message dated "Fri, 01 Jun 2012 14:13:21 +0100" Date: Fri, 01 Jun 2012 09:47:53 -0400 Message-ID: <23954.1338558473@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/3 X-Sequence-Number: 47029 Chris Rimmer writes: > While investigating some performance issues I have been looking at slow > queries logged to the postgresql.log file. A strange thing that I have > seen is a series of apparently very slow queries that just select from a > sequence. It is as if access to a sequence is blocked for many sessions and > then released as I get log entries like this appearing: > LOG: duration: 23702.553 ms execute : /* dynamic native SQL > query */ select nextval ('my_sequence') as nextval > LOG: duration: 23673.068 ms execute : /* dynamic native SQL > query */ select nextval ('my_sequence') as nextval > LOG: duration: 23632.729 ms execute : /* dynamic native SQL > query */ select nextval ('my_sequence') as nextval > ....(Many similar lines).... That's pretty weird. What else is being done to that sequence? Is it only the sequence ops that are slow, or does this happen at times when everything else is slow too? Can you create a reproducible test case? regards, tom lane