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 1olpTc-0002Fa-NE for pgsql-performance@arkaria.postgresql.org; Fri, 21 Oct 2022 10:42:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olpTb-00075S-HB for pgsql-performance@arkaria.postgresql.org; Fri, 21 Oct 2022 10:42:07 +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 1olpTb-00075J-5F for pgsql-performance@lists.postgresql.org; Fri, 21 Oct 2022 10:42:07 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1olpTX-0001yk-OA for pgsql-performance@lists.postgresql.org; Fri, 21 Oct 2022 10:42:06 +0000 Received: by mail-pl1-x630.google.com with SMTP id 10so2030376pli.0 for ; Fri, 21 Oct 2022 03:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TksiwfoI6RxTfDm8x0MYqNjQP0VYe+d9EB1iZir2B9I=; b=Z/JP2ohS7aEaKUYTYulegp2wun+M7fKXdyHx7VE8/IE83uWokm/nlmwZq0WocjXkVn S4IHS7YNrG0SlL1vaELe1iimw7pDyX+e0cqPa9BfHIjaKr/J/NwqXifijRIoxJ9DlxrH 4fLZeArcYXDwJQgEy7BqDyXNsYnu12JXb642Xnqee2Vtw6q+6zmGeQuKdOOVNn+1R4Uh fVlus5zyiV8OJS/YfAH9PYkhsTvDIHOSbHoIQq9FuZa0atN5HGGxkjQesdu1jHT/gTXO LQkMArLxjkrxLVAgj4g/b3oXcE8N+7sh7MUvzpJ9M+5sV7r70/JlYX9lOrt6ZqYydeon 14gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TksiwfoI6RxTfDm8x0MYqNjQP0VYe+d9EB1iZir2B9I=; b=bIiEQVj1A/m8Qtsu8x3wj1FMybunb3TW1VrfQOBagFbHE7iEHduDy1LtXhFsdVM7q3 V1TD8CoO+X/DE6wKlmLd8wWGnakwTJt9eCjSwEgSOdt2iVufyStP6KieBzJBkFLPG9mk 5f2uq+7BVWpLzOiZV6RJ87MclmFOap5A31OzLwSQ7JoNwlK1+8uZHR11xn+/ykGnmHNC Vl8jUYO/kdDu99SSO431D7uQdy4+QF92+vH2LTYqeboQOk8sYU06b8AP8xak/O34AC9h 7LSF9Y0Oqvf7WH5b1zWecJelLz30HyoyTSvZjJ1x1BXezSxwpdB8MoJsx2S6bQNPaAfE Co/Q== X-Gm-Message-State: ACrzQf0yu62fP6AYmOf5GFD1ZvpDPJ1+8vLN7GzLXhWMpe4aJVAeNS9+ LrHB47Bve6Lw8Wx1Qq4EEeQSa2aq2Ow= X-Google-Smtp-Source: AMsMyM5099ahIyVPe5bOvbf0pZI2hLC8Qutdl021/Hp2E/CJg4LG6QrRjgZcRqWPEjAxGcOzsugh9w== X-Received: by 2002:a17:902:ce88:b0:186:7e98:86d6 with SMTP id f8-20020a170902ce8800b001867e9886d6mr1521223plg.123.1666348922421; Fri, 21 Oct 2022 03:42:02 -0700 (PDT) Received: from jrouhaud (2001-b011-1006-ff24-2900-8bec-fd6b-4206.dynamic-ip6.hinet.net. [2001:b011:1006:ff24:2900:8bec:fd6b:4206]) by smtp.gmail.com with ESMTPSA id q135-20020a632a8d000000b004277f43b736sm12836244pgq.92.2022.10.21.03.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 03:42:02 -0700 (PDT) Date: Fri, 21 Oct 2022 18:41:59 +0800 From: Julien Rouhaud To: Lars Aksel Opsahl Cc: "pgsql-performance@lists.postgresql.org" Subject: Re: ogr2ogr slow sql when checking system tables for column info and so on. Message-ID: <20221021104159.ijdnpknv52fweaxk@jrouhaud> References: <20221021094848.5gbp42wttkjzn3le@jrouhaud> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Oct 21, 2022 at 10:30:27AM +0000, Lars Aksel Opsahl wrote: > > > > >In both case you have a sequential scan over the pg_attribute table, but for > >pg_catalog it takes 17 seconds to retrieve the 1.4M rows, and in the new table > >it takes 156 ms. > > > >It looks like you catalog is heavily bloated, which is the cause of the > >slowdown. > > > >You could do a VACUUM FULL of the tables in pg_catalog but it would only be a > >short term fix as it's likely that your catalog will get bloated again. Do you > >rely a lot on temporary tables? If yes it can easily lead to this kind of side > >effect, and you should modify you code to perform manual vacuum of catalogs > >tables very often, or add a dedicated high frequency task for running similar > >vacuum and keep the bloat under control. > > Yes we use a lot of temp tables sometimes . What do you mean by sometimes? If you only have non frequent or specialized jobs the creates a lot of temp tables, you just need to modify them to issue some VACUUM (not VACUUM FULL) at the end, or regularly if you creates millions of tables in a single job. > With "VACUUM FULL ANALYZE " we got the same time as from the created tables > https://explain.depesz.com/s/Yxy9 so that works. > > OK then we start up by trigger a 'VACUUM FULL ANALYZE ' for all the tables in > th pg_catalog because this seems to be only thing that is working for now. Just to be clear the VACUUM FULL is only needed to shrink the tables which were likely multiple GB each. If you do simple VACUUM frequently enough, you won't have too much bloat in the first place and everything will just work as intended. You could setup some monitoring on the size of the catalog tables to make sure that you run those maintenance as frequently as necessary. > I assume that adding more indexes on the tables in pg_catalog to avoid tables > scans are not that easy. Indeed, that's not a supported operation.