Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqGG0-0022AX-HU for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 18:47:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tqGFy-004JHe-Aq for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Mar 2025 18:47:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqGFy-004JH4-0q for pgsql-hackers@lists.postgresql.org; Thu, 06 Mar 2025 18:47:42 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tqGFw-001LsX-0x for pgsql-hackers@lists.postgresql.org; Thu, 06 Mar 2025 18:47:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 526IlY80714296; Thu, 6 Mar 2025 13:47:34 -0500 From: Tom Lane To: Andres Freund cc: Corey Huinker , Robert Haas , Nathan Bossart , Jeff Davis , Michael Paquier , jian he , Bruce Momjian , Matthias van de Meent , Magnus Hagander , Stephen Frost , Ashutosh Bapat , Peter Smith , PostgreSQL Hackers , alvherre@alvh.no-ip.org Subject: Re: Statistics Import and Export In-reply-to: References: <6rpmhyrtci4epuzay7y5xvd2cwdwb6zmtt6ofxrvakyawxhm7s@6grajbpr4kij> Comments: In-reply-to Andres Freund message dated "Thu, 06 Mar 2025 13:04:55 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <714294.1741286854.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 06 Mar 2025 13:47:34 -0500 Message-ID: <714295.1741286854@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > And in contrast to analyzing the database in parallel, the pg_dump/re= store > work to restore stats afaict happens single-threaded for each databas= e. In principle we should be able to do stats dump/restore parallelized just as we do for data. There are some stumbling blocks in the way of that: 1. pg_upgrade has made a policy judgement to apply parallelism across databases not within a database, ie it will launch concurrent dump/ restore tasks in different DBs but not authorize any one of them to eat multiple CPUs. That needs to be re-thought probably, as I think that decision dates to before we had useful parallelism in pg_dump and pg_restore. I wonder if we could just rip out pg_upgrade's support for DB-level parallelism, which is not terribly pretty anyway, and simply pass the -j switch straight to pg_dump and pg_restore. 2. pg_restore should already be able to perform stats restores in parallel (if authorized to use multiple threads), but I'm less clear on whether that works right now for pg_dump. 3. Also, parallel restore depends critically on the TOC entries' dependencies being sane, and right now I do not think they are. I looked at "pg_restore -l -v" output for the regression DB, and it seems like it's not taking care to ensure that table/MV data is loaded before the table/MV's stats. (Maybe that accounts for some of the complaints we've seen about stats getting mangled??) > I think the stats need to be handled much more like we handle the actual= table > data, which are obviously *not* stored in memory for the whole run of pg= _dump. +1 regards, tom lane