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 1mnaBo-0007SJ-MN for pgsql-performance@arkaria.postgresql.org; Thu, 18 Nov 2021 05:42:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mnaBn-00013U-AI for pgsql-performance@arkaria.postgresql.org; Thu, 18 Nov 2021 05:42:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnaBn-00013L-0r for pgsql-performance@lists.postgresql.org; Thu, 18 Nov 2021 05:42:27 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mnaBk-0002Qa-CV for pgsql-performance@lists.postgresql.org; Thu, 18 Nov 2021 05:42:26 +0000 Received: by mail-io1-xd35.google.com with SMTP id x10so6496014ioj.9 for ; Wed, 17 Nov 2021 21:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QtoYK4Tu7dVRjpWMv/BKJ70wh55R249Av5mmrXbvLzI=; b=xGcA2xKFmXwUDQksQLFoba6FoSWA8XRwwnU4I6ILYmlwCcUKeqUdzLWv9Si6UYJelx zWjsti2qdYCbCNp4rIESKpnn3hk2eoQHou8xi3Hx+tX9JQ7gl5Oydg2vHL/fhKOTVOIO Q0h2LcyJcywhslP9WgRsHtxeRm3HWoIJuzGC835luhqwKARHOy6jVMa7KiK2SSXILuig veLGr2g1k1vBj7XM3LTb7zVKe82w+0Lmw9TrxQCByqx/pr2sPhen0mD4y7ioXPkwpUdR lpfHYcezZwgkiN9XF7dCcooQjDFA5MXiSPnDtOmhDSQRT3vcahx5ogGg+rA5NsuGsl7w mRIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QtoYK4Tu7dVRjpWMv/BKJ70wh55R249Av5mmrXbvLzI=; b=I4jPTJnmQ1qK3JV2Ni3E3C3oxX/Wyqa7Ct/cQz7IgIM2bWmWbGMe/YGuCuXNA1fhNg exnJObfSVPqytXMkGfw3vcmmnjqxWedP2m8H3ph261mg68/OgjONd6DvYP6cHEP5InLr es1or7QsnnPUdhsSocgrYOraKT5cFnL00nSJqeT3D+g1uhKnl7OcJ5dJXke1G2uNCPpR zKkzHYxzt/mquWMEAV/j+V5L9Z/SAZYBhwkwt5QmSL35mIQp0oD252zmMM9vUswHCCW7 XxOdG+iyGI4Qabej9liHztU/5ltqW0FqKwDXLnRaqGSWO5nLccRfDQEo7wqmTjeWBiQ0 rbNg== X-Gm-Message-State: AOAM532nhOU8nkboBofHBXs6PTas/P3NttEjPg6kwT9ehe6CqxZkJfYX 8sTS+04yncbITkfUC1iTtaFz9w== X-Google-Smtp-Source: ABdhPJyJvRdq97H7ia3ZtLFp0SCaN7S2u6h9vQnIbRhb0khonMEa1jAZGbmYrs/zEKIrpgneFQamqw== X-Received: by 2002:a05:6638:2590:: with SMTP id s16mr18532644jat.93.1637214143441; Wed, 17 Nov 2021 21:42:23 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id c2sm1276060ilr.70.2021.11.17.21.42.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 21:42:22 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id CA7A1800E9A; Wed, 17 Nov 2021 23:42:21 -0600 (CST) Date: Wed, 17 Nov 2021 23:42:21 -0600 From: Justin Pryzby To: Thomas Munro Cc: Robert Creager , Tom Lane , pgsql-performance@lists.postgresql.org Subject: Re: Need help identifying a periodic performance issue. Message-ID: <20211118054221.GJ17618@telsasoft.com> References: <3A76761B-3DDD-4A3C-B791-E73107AFC9A2@spectralogic.com> <0C3B1B2B-6571-477D-A89C-6FA7B6259840@spectralogic.com> <20211117190038.GB17618@telsasoft.com> <2736634.1637177330@sss.pgh.pa.us> <5BAA534E-AECC-4533-951A-0B6D88A070F3@spectralogic.com> <20211117231815.GF17618@telsasoft.com> <1ADFE43B-5A43-40DA-B039-2D7E5FD82B6C@spectralogic.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 Thu, Nov 18, 2021 at 04:39:42PM +1300, Thomas Munro wrote: > On Thu, Nov 18, 2021 at 1:18 PM Robert Creager wrote: > > So, how do I go about capturing more information for the big brains (you guys) to help figure this out? I have all our resources at mine (and hence your) disposal. > > As a workaround, does it help if you issue DISCARD PLANS before your > COPY jobs, or alternatively start with a fresh connection? I'm > guessing that something like this is happening. > > -- set up the auto_explain extension to show the internal foreign key check queries' plans > load 'auto_explain'; > set auto_explain.log_nested_statements = true; > set auto_explain.log_min_duration = 0; > set auto_explain.log_analyze = true; ..and SET client_min_messages=debug; > drop table if exists r, s cascade; > create table r (i int primary key); > create table s (i int references r(i)); > > -- collect stats showing r as empty > analyze r; > > -- execute RI query 6 times to lock the plan (inserts fail, log shows seq scan) > insert into s values (42); > insert into s values (42); > insert into s values (42); > insert into s values (42); > insert into s values (42); > insert into s values (42); > > insert into r select generate_series(1, 1000000); > > -- once more, we still get a seq scan, which is by now a bad idea > insert into s values (42); > > discard plans; > > -- once more, now we get an index scan > insert into s values (42); It also seems to work if one does SET plan_cache_mode=force_custom_plan; Robert might try that, either in postresql.conf, or SET in the client that's doing COPY. Robert is using jdbc, which (as I recall) has this problem more often than other clients. But, in this case, I think JDBC isn't causing the problem. -- Justin