Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fT371-0003c4-Fr for pgsql-general@arkaria.postgresql.org; Wed, 13 Jun 2018 10:34:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fT36z-0003KS-MA for pgsql-general@arkaria.postgresql.org; Wed, 13 Jun 2018 10:34:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fT36z-0003KJ-AL for pgsql-general@lists.postgresql.org; Wed, 13 Jun 2018 10:34:45 +0000 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fT36q-0002iq-RI for pgsql-general@lists.postgresql.org; Wed, 13 Jun 2018 10:34:43 +0000 Received: by mail-lf0-x22d.google.com with SMTP id q11-v6so3133604lfc.7 for ; Wed, 13 Jun 2018 03:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=kMjE6VH9BEhsFqIS5IaV7yMTAickT4ktreGj4yd9Icc=; b=bprv/O5H/DoIri1cXGZjUtteUVTka4o545S1dinWsB+UV9bAgb/iShJYBeYM3lwaVU iGWsnWrVHPVsrwcdcWMocmerIV9trlhaBKNv/x0e2dtrwqFjvPpFVB2U6+wQ9zjJP9pk yIyqjC5bsuonHyNUlEgzkRp+lWuwrdUBRxuAGlBsdau89dl56MIy/3wnTh0hWD4Mz55H c2Pb7IgMVqjHGuS92q0G1zEOpHpfP9hwZfk1lKHvBPO8lTFvno4LFiKRWr73N80k3+Eq G/KgB5AaH/dxwe89VsQOQvCqxBJL85ztMcthWSSMu5BFij8Qo+PwA1ANapxeduGOdj0+ dRsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=kMjE6VH9BEhsFqIS5IaV7yMTAickT4ktreGj4yd9Icc=; b=YwTPRH4GCvxnMMZB7t4lxpMsuzEghlU2qbIiDcnL8ocmM/SsgsdMcgJ4b5wCSGGpVp z9mSo7zEM4ZBD6m51Q88CGykqzvyGmTFCs+UOrDX4TEovKKPEBYQzKlR18+UR3x8ig3W FzFpAvFWO7dF9IfY8CNsdVx3iDgof9fp7R/KQ9bjxkUQwooRXuFVOCzuNgjqWG+14+lt SLrWWsSiK+HI249RrkJ8jaQrIUErRkGa8m0UV90I0Ppuwu4WPTlwLHdvKdMGjddQRvW0 ueDMUvDPXlVJE/1Oc0zflyzsS07gj6kUeTNXj0U6OAfp1PbvlkzQo1lhMrgY4A7vBYy0 TihA== X-Gm-Message-State: APt69E0Iv8Sz0y+ScIy725EDzhSj2QJqyXC4K/UTK7QFW0Ef0dMMt+i4 ulH3Cj0TYu0vKwnzr9XPAn7nDfwK X-Google-Smtp-Source: ADUXVKLkKgiE+HSSrz+l06ds2TXmb9QirCqcw6kCW/U1DPouxFzaKyNtkVW5E2CiHLi/YIlG7FbWvg== X-Received: by 2002:a2e:8682:: with SMTP id l2-v6mr2876174lji.48.1528886074123; Wed, 13 Jun 2018 03:34:34 -0700 (PDT) Received: from [10.3.1.85] ([185.62.200.137]) by smtp.gmail.com with ESMTPSA id v79-v6sm478238lje.78.2018.06.13.03.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 03:34:33 -0700 (PDT) Subject: Re: First query on each connection is too slow To: Vadim Nevorotin , pgsql-general@lists.postgresql.org References: From: Maksim Milyutin Message-ID: <70a1988a-4ec0-09e2-b31c-4abf4c6d2e2f@gmail.com> Date: Wed, 13 Jun 2018 13:34:32 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4A8392D0BCBAA5C9CAF5AAE0" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------4A8392D0BCBAA5C9CAF5AAE0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 13.06.2018 12:55, Vadim Nevorotin wrote: > Nested Loop Left Join  (cost=0.82..26.41 rows=1 width=4) *(actual > time=49.290..49.297 rows=1 loops=1)* >    Join Filter: ((s_2.connamespace = n.oid) AND (s_2.conrelid = c.oid) > AND (a.attnum = ANY (s_2.conkey))) >    Buffers: shared hit=18 > ... > * Planning time: 2.589 ms >  Execution time: 49.467 ms* > > (45 rows) > > And there are two questions: why this problem occurs and how can I fix it? You could catch a performance profile of this issue using perf tools and iterative executing this query in new sessions via pgbench, for example. This would greatly facilitate the search for the cause of your problem. -- Regards, Maksim Milyutin --------------4A8392D0BCBAA5C9CAF5AAE0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 13.06.2018 12:55, Vadim Nevorotin wrote:

Nested Loop Left Join  (cost=0.82..26.41 rows=1 width=4) (actual time=49.290..49.297 rows=1 loops=1)
   Join Filter: ((s_2.connamespace = n.oid) AND (s_2.conrelid = c.oid) AND (a.attnum = ANY (s_2.conkey)))
   Buffers: shared hit=18
...
 Planning time: 2.589 ms
 Execution time: 49.467 ms


(45 rows)

And there are two questions: why this problem occurs and how can I fix it?

You could catch a performance profile of this issue using perf tools and iterative executing this query in new sessions via pgbench, for example. This would greatly facilitate the search for the cause of your problem.

-- 
Regards,
Maksim Milyutin
--------------4A8392D0BCBAA5C9CAF5AAE0--