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 1nH7WD-0004GS-HL for pgsql-performance@arkaria.postgresql.org; Mon, 07 Feb 2022 17:09:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nH7WB-0000RS-EZ for pgsql-performance@arkaria.postgresql.org; Mon, 07 Feb 2022 17:09:35 +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 1nH7WB-0000QZ-19 for pgsql-performance@lists.postgresql.org; Mon, 07 Feb 2022 17:09:35 +0000 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nH7W7-0007RQ-OR for pgsql-performance@lists.postgresql.org; Mon, 07 Feb 2022 17:09:34 +0000 Received: by mail-qv1-xf32.google.com with SMTP id o5so4253469qvm.3 for ; Mon, 07 Feb 2022 09:09:31 -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=g3JyNrhyqDt14TlDnedci17mJXiAjnlo1xgniD3VZJo=; b=Rt8xLleNveahxpOXLa1d1sd0KNNuoihXEX0dMXsplAZABz0ajMqmCc1Bn+NIrJm9S7 ILwYx04wVo5gf2XSSBJDzv5GaqS8qCXvL1hT9v3P8DDQIrF2w9Do5QXWCQpgSEfQCuwt k1Av+JxUwMByM1/PRF0eBKzU1fQr5Mtmn4UndR/GfhphyEr/Vtc8s0mYdXThfhr/WqEb rqWDJmZmH2BlF94oz8neE3/SkVJLTYYMKo9Yo4QRzQBTz5x4WFn0IBb8PA5NuPdWy9Dn B+5tWfcBowfNx1ZUIHfU6zKKsBZNLX9A6khkA6MRcjyToAgqS0aBDsjMQ+B6nCltnuMl yDqg== 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=g3JyNrhyqDt14TlDnedci17mJXiAjnlo1xgniD3VZJo=; b=CR6Q8FPO7mUDQMC4AH/kZVN2Pdnp346G134fP1JgOJL9SyFxCf2OJRvwLA0w6ozMSE yDtIYhJe4a4g9o7VDCKcd52AZeAWCnIm0wOhgl/b7mYdVq1QrRtGChJfy5sJLKzbeOww /AI3FsZBlVL50j0S48i10/X2fMWOJrAb+8krnSdmCw+RrX1d6Ig0JHVsvxWq8EQaJbl2 3wDYwffzrh4xGBx+hi80wSSve2BL6izfOz6LqBpnLWBJD3tduzK+1bpXOH75hOi4w/N1 0Lqmsf/mhsiMyfM3q+8i/ch7/50YNfGcR5xSXh/InJA9hZU37y5hDoDWwuLGzYwnE+I1 3utQ== X-Gm-Message-State: AOAM532kPsQ48jYopqHzQlV2slg7WP31SXTjDmesVioyfQA56WGrW7jv cnYl1bF3eAw7ONJQvGvHBh11xvq8xULAqQ== X-Google-Smtp-Source: ABdhPJyoj5RSBjDF8+J47RtxYiUbDJo+lkQ1kLBE5xyXAPeI4xaKdRKKXwEII2xZ9Vrb4puNfY4ZGw== X-Received: by 2002:a05:6214:c4d:: with SMTP id r13mr348021qvj.94.1644253769224; Mon, 07 Feb 2022 09:09:29 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id w10sm6369227qtj.73.2022.02.07.09.09.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Feb 2022 09:09:28 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id A4DD3800C5C; Mon, 7 Feb 2022 11:09:27 -0600 (CST) Date: Mon, 7 Feb 2022 11:09:27 -0600 From: Justin Pryzby To: Lars Aksel Opsahl Cc: pgsql-performance@lists.postgresql.org Subject: Re: slow "select count(*) from information_schema.tables;" in some cases Message-ID: <20220207170927.GF31460@telsasoft.com> References: 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 Mon, Feb 07, 2022 at 04:56:35PM +0000, Lars Aksel Opsahl wrote: > Sometimes simple sql's like this takes a very long time "select count(*) from information_schema.tables;" > > Other sql's not including system tables may work ok but login also takes a very long time. > > The CPU load on the server is around 25%. There is no iowait. > > This happens typically when we are running many functions in parallel creating many temp tables and unlogged tables I think. > > Here is a slow one: > https://explain.depesz.com/s/tUt5 > > and here is fast one : > https://explain.depesz.com/s/yYG4 The only difference is that this is sometimes many times slower. Finalize Aggregate (cost=42021.15..42021.16 rows=1 width=8) (actual time=50602.755..117201.768 rows=1 loops=1) -> Gather (cost=42020.94..42021.15 rows=2 width=8) (actual time=130.527..117201.754 rows=3 loops=1) Workers Planned: 2 Workers Launched: 2 > Here are my settings (the server has around 256 GB og memory) : What version of postgres ? What OS/version ? https://wiki.postgresql.org/wiki/Slow_Query_Questions Are there any server logs around that time ? Or session logs for the slow query ? Is it because the table creation is locking (rows of) various system catalogs ? I'm not sure if it'd be a single, long delay that you could see easily with log_lock_waits, or a large number of small delays, maybe depending on whether your table creation is done within a transaction. -- Justin