Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJuCG-00048M-LJ for pgsql-performance@arkaria.postgresql.org; Wed, 10 Mar 2021 08:28:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lJuCF-0004XR-IR for pgsql-performance@arkaria.postgresql.org; Wed, 10 Mar 2021 08:27:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJuCF-0004XJ-7Y for pgsql-performance@lists.postgresql.org; Wed, 10 Mar 2021 08:27:59 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lJuCD-0003C3-C2 for pgsql-performance@lists.postgresql.org; Wed, 10 Mar 2021 08:27:58 +0000 Received: by mail-io1-xd35.google.com with SMTP id u20so16994985iot.9 for ; Wed, 10 Mar 2021 00:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to:user-agent; bh=WQYusOhZmVrZJntCtraXBP8UihcysdpCyG4BRRskeVM=; b=xMDjGM/8F/HpRhMy/5OXvC8Uvi8uH+cLjUIb6wSId6O10JgD30LNMoQK4pNXGDyV4l uwR3jkkqc8VF4D6mXZ+NTZD1fDpzzWvDcAUGMS5V70uYlloRdtxhwmRqIsl8LSM7/0wJ +KuCQl4dCIj6G5a/tUFgM+qDcQvKcf2dQVZLqUcb+gYdI3La2Jx33z6ax3RzfLPyc5dH Ozik/hgmmTmb9IXQDDqcOLVyqa3FbsDgjNWU4hLzUvegm28hDwzSVQH6VsY5NPp+r3Jw RZFsHVNFaoXG0f7C55GuCELah1hi+PSx+D08QjGTwQLkeKMoxqEHG0ULiuGCUKkz+1MD 0gkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=WQYusOhZmVrZJntCtraXBP8UihcysdpCyG4BRRskeVM=; b=LxZeZdRDzlhmObMJ9p7gx/4PpwfQ7aWqJAYS6wt0/bgPr6b7HtfHg3PyGBFDG+/QLi fPvb5ZZ+iQKdb3BID0bx4sJssVsOt3HdAgMTTpoKun3pJ1oqIKwiYotTPil8ePI/gSfh 5Cf6P5ZR2pXGCNxJnzpmTyIX+/6iuftNw/BFoUN4CPdlOv0kTYHDcLwb8jhR69rl3Dax tm3PVnOnSjFurKJRbqC+ogwstrjujizWGxGnWVVn/TKXLywku0Jl1zbrKQHnbO1IG1KP uMRQnr1Jor9bTWEPcjGSyP2bNWHZalx5cSGM+VWyPibPtE979QlZNB1I0pL8rEe6LkXm z06g== X-Gm-Message-State: AOAM532ERd00xfymJEbDibC9koz1/jmi91NPkx6Xi1GcHc3U9rce97BR 8jA4KFoo2EQ8wCiazcnTW6glvA== X-Google-Smtp-Source: ABdhPJyEzYsvg0ixAVSMssfOIIx1vyT3VB2l7N8Eptn0Ux3seWriBabJ2RdPngMnDwfMWNouExzIUQ== X-Received: by 2002:a05:6638:3293:: with SMTP id f19mr2145782jav.0.1615364875399; Wed, 10 Mar 2021 00:27:55 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v17sm1095464ios.46.2021.03.10.00.27.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Mar 2021 00:27:54 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 701FD800A3A; Wed, 10 Mar 2021 02:27:53 -0600 (CST) Date: Wed, 10 Mar 2021 02:27:53 -0600 From: Justin Pryzby To: Francesco De Angelis Cc: pgsql-performance@lists.postgresql.org, Michael Lewis , Tom Lane , Julien Rouhaud , Michel SALAIS Subject: Re: Fwd: different execution time for the same query (and same DB status) Message-ID: <20210310082753.GR2021@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Mar 06, 2021 at 10:40:00PM +0100, Francesco De Angelis wrote: > The problem is the following: the query can take between 20 seconds and 4 > minutes to complete. Most of times, when I run the query for the first time > after the server initialisation, it takes 20 seconds; but if I re-run it > again (without changing anything) right after the first execution, the > probability to take more than 4 minutes is very high. On Tue, Mar 09, 2021 at 11:58:05PM +0100, Francesco De Angelis wrote: > With such a value, I noticed also the following phenomenon: in addition to > variable execution times (as previusly stated, the range is between 20 > seconds and 4 minutes), You said it takes between 20s and 4min (240s), but both the explain analyze show ~1300s. explain analyze can be slower than the query, due to timing overhead. Is that what's happening here? You could try explain(analyze,timing off,buffers). You should send a result for the "20sec" result, and one for the "4min" result, to compare. I assume the crash is a result of OOM - you could find the result in dmesg output ("Out of memory: Killed process") or the postgres logfile will say "terminated by signal 9: Killed". It's important to avoid setting work_mem so high that the process is killed and has to go into recovery mode. -- Justin