Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cP9E2-0002EH-GT for pgsql-performance@arkaria.postgresql.org; Thu, 05 Jan 2017 14:41:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cP9E1-0004cT-UZ for pgsql-performance@arkaria.postgresql.org; Thu, 05 Jan 2017 14:41:05 +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 1cP9E0-0004bi-QB for pgsql-performance@postgresql.org; Thu, 05 Jan 2017 14:41:05 +0000 Received: from mail-qk0-x232.google.com ([2607:f8b0:400d:c09::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cP9Dx-0005aD-I6 for pgsql-performance@postgresql.org; Thu, 05 Jan 2017 14:41:03 +0000 Received: by mail-qk0-x232.google.com with SMTP id a20so45251011qkc.1 for ; Thu, 05 Jan 2017 06:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=aPA1Y5iTikRfqUrIqz1IJKpBtrtw0dB6uQvPFqM1JfY=; b=Wdx455J7TGzj6Y3YMeWVv6cW00Tv2Q73BuSkg3l8DN6cyMPcXRkjiHirwH8l0y9gNU Gpxgx5Kvun5hUjE762lWS7UP9oswKyzJtFh4hJgeBdt5akYVnGVaHV1bHS0wkttlb/N4 2vIrYpw6V1d5Z/pnD7ewPTnU7r0ApsRFDQFqri7cZhKVu8maDfH5QO8y6m9PYcb71CQM bUzo4b78ztToTuB0s91lgep6W0zBq+JGQwewQAUT5Hk0SjNjb0UcSXJd13B038FPN7Ti kW+oYDac/t1qlVbfUoFQGR2y7FeSVu3WjPtEMwwd6adVnU6cnGYDppwe+Eg8EFO8E6Vk ptXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=aPA1Y5iTikRfqUrIqz1IJKpBtrtw0dB6uQvPFqM1JfY=; b=E524gS/dZKlFUdCAJnYysdnajGIfZEaHxV5I+9LMUi1EZQW1kPab4xd3u4oRauPrBi fd6vRsCDhzH5DH0g4Lq0xTM4E1v7Jxe9D37enpEPg3//zhG0fqcYPGP17nPa830av7Zx 7qxf5GKYaGggtoztCcKdYi8XBgmY7KHvG3XTPQ7S0oxWPc8WJ/ikls019GP109RRIsxY pKHiQnjr6pLKC543D8RqpHZsefuffIlb9w6U70IC3pmU9NVjmPLnHffi7WTYGhNHBdN7 49uzdJR0FkCKB+e9GC6uens8werLR5j9R4YsMm07uJP9zWNquqQD4Qcv+ko1JvlPH7Yt /m2Q== X-Gm-Message-State: AIkVDXJkhbrrx3L1dKdX7GNyn3e3JDUm3LQ+6/IhHHc4hQhwda9um5DUykWFXyWLMz5peDWBmKj5eLwQIetOKg== X-Received: by 10.55.15.234 with SMTP id 103mr78100190qkp.282.1483627260236; Thu, 05 Jan 2017 06:41:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.169.2 with HTTP; Thu, 5 Jan 2017 06:40:59 -0800 (PST) In-Reply-To: References: From: Merlin Moncure Date: Thu, 5 Jan 2017 08:40:59 -0600 Message-ID: Subject: Re: Slow query after 9.3 to 9.6 migration To: =?UTF-8?Q?Fl=C3=A1vio_Henrique?= Cc: postgres performance list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Tue, Dec 27, 2016 at 5:50 PM, Fl=C3=A1vio Henrique = wrote: > Hi there, fellow experts! > > I need an advice with query that became slower after 9.3 to 9.6 migration. > > First of all, I'm from the dev team. > > Before migration, we (programmers) made some modifications on query bring > it's average time from 8s to 2-3s. > > As this query is the most executed on our system (it builds the user panel > to work), every bit that we can squeeze from it will be nice. > > Now, after server migration to 9.6 we're experiencing bad times with this > query again. > > Unfortunately, I don't have the old query plain (9.3 version) to show you, > but in the actual version (9.6) I can see some buffers written that tells= me > that something is wrong. > > Our server has 250GB of memory available, but the database team says that > they can't do nothing to make this query better. I'm not sure, as some > buffers are written on disk. > > Any tip/help will be much appreciated (even from the query side). > > Thank you! > > The query plan: https://explain.depesz.com/s/5KMn > > Note: I tried to add index on kilo_victor table already, but Postgresql > still thinks that is better to do a seq scan. Hard to provide more without the query or the 'old' plan. Here are some things you can try: *) Set effective_io_concurrency high. You have some heap scanning going on and this can sometimes help (but it should be marginal). *) See if you can get any juice out of parallel query *) try playing with enable_nestloop and enable_seqscan. these are hail mary passes but worth a shot. Run the query back to back with same arguments in the same database session. Does performance improve? Big gains (if any) are likely due to indexing strategy. I do see some suspicious casting, for example: Join Filter: ((four_charlie.delta_tango)::integer =3D (six_quebec.golf_bravo)::integer) Are you casting in the query or joining through dissimilar data types? I suspect your database team might be incorrect. merlin --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance