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 1qiMAs-006CC1-M0 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Sep 2023 21:52:58 +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 1qiMAp-003qu5-Ia for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Sep 2023 21:52:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiMAp-003qtt-7n for pgsql-hackers@lists.postgresql.org; Mon, 18 Sep 2023 21:52:55 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qiMAl-005ydL-Sm for pgsql-hackers@lists.postgresql.org; Mon, 18 Sep 2023 21:52:54 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3add37de892so908352b6e.1 for ; Mon, 18 Sep 2023 14:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695073970; x=1695678770; darn=lists.postgresql.org; 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=AfmlfCw+V7I0Vh/opBe4h0eih2m+Wtad5BP+Pok0tf8=; b=MqqO3ylJtf9OH/AXUzzlH9aQCAW8+dt/62MSfdqcALEqs97QQCldujAK6vbPpyERcD eQm2iPPYtAke4nuLvzb8r5j0nSRgyxD5MawlxjYmj8wcY3Tttpi8R7GHqv24HfMIzBSn 4Rdc1FdvhNnERLXeMnbGo/B6GaRsPKrKBkDb7xI7UyF6TZgHYGjnaOPY/U9eLBhuxBGX iqc4QRJnPvtk6K/IBXKr65yESnmFjFZkTc3ROcVO9Df4grgpJDMB9oFT8N0CUDvTuTEE rY0ceCb+wC4YTL78nVwvx6is0jqE0LSSmLKC4J7iyx7azJ5xQxXkOGzc/veR9tY2h/WF d0WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695073970; x=1695678770; 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=AfmlfCw+V7I0Vh/opBe4h0eih2m+Wtad5BP+Pok0tf8=; b=cuPLkMx2T6uKGT51UTVPqw35DMmsJB/jTR9gYbC6TE+9MMnqzvHMAJTMsLxEd8/Qzg shJlRJxa09y5+tsJqx2xIhgTyOAFbepBF7dFVtlfNvfBjFJz+w+F4zuCqN1xL9GjdHtX gpJcHy2jg0mULerx4SKI/r82LNVYn83mg79hLUjjH0i/l96m5r7UDZJ3Anqmy1thzmiW izqo3yI1Iso4dFCoM5+jErXYaApIq2Qqfj/j/ejOQRolzYm2tMxIfNk/CVag/Dhp3Q/W xN+V9xtHo628a4jhPc6ZQ6JGDIUejPC82Or4NRqXAYt3OUteqiwV8PrVhsJ3/xWniGge abtg== X-Gm-Message-State: AOJu0YxbwGtjXKrn0smAeslq2FfPlxsuMMK2ghJkcygBcZkHGK6hC62t 3nimdFrs0ucsfla3+bv+srmQan+xZBI= X-Google-Smtp-Source: AGHT+IGz2HCbKO6pGODG6Tv5Fsf1cfvRXPN8Nq7ZbfgbEnIDVXd0zPBqSUUWhzxxfDeLomIP31O7/Q== X-Received: by 2002:a05:6808:90b:b0:3a7:390c:4c43 with SMTP id w11-20020a056808090b00b003a7390c4c43mr9932230oih.50.1695073969949; Mon, 18 Sep 2023 14:52:49 -0700 (PDT) Received: from nathanxps13 ([2600:1700:48f8:340f:d13d:716d:771a:5b2c]) by smtp.gmail.com with ESMTPSA id e27-20020a05680809bb00b003a37372e6b2sm4403113oig.21.2023.09.18.14.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 14:52:49 -0700 (PDT) Date: Mon, 18 Sep 2023 14:52:47 -0700 From: Nathan Bossart To: Pierre Ducroquet Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Improvements in pg_dump/pg_restore toc format and performances Message-ID: <20230918215247.GA2661288@nathanxps13> References: <2656000.KRxA6XjA2N@peanuts2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2656000.KRxA6XjA2N@peanuts2> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 27, 2023 at 10:51:11AM +0200, Pierre Ducroquet wrote: > I ended up writing several patches that shaved some time for pg_restore -l, > and reduced the toc.dat size. I've only just started taking a look at these patches, and I intend to do a more thorough review in the hopefully-not-too-distant future. > First patch is "finishing" the job of removing has oids support. When this > support was removed, instead of dropping the field from the dumps and > increasing the dump versions, the field was kept as is. This field stores a > boolean as a string, "true" or "false". This is not free, and requires 10 > bytes per toc entry. This sounds reasonable to me. I wonder why this wasn't done when WITH OIDS was removed in v12. > The second patch removes calls to sscanf and replaces them with strtoul. This > was the biggest speedup for pg_restore -l. Nice. > The third patch changes the dump format further to remove these strtoul calls > and store the integers as is instead. Do we need to worry about endianness here? > The fourth patch is dirtier and does more changes to the dump format. Instead > of storing the owner, tablespace, table access method and schema of each > object as a string, pg_dump builds an array of these, stores them at the > beginning of the file and replaces the strings with integer fields in the dump. > This reduces the file size further, and removes a lot of calls to ReadStr, thus > saving quite some time. This sounds promising. > Patch Toc size Dump -s duration pg_restore -l duration > HEAD 214M 23.1s 1.27s > #1 (has oid) 210M 22.9s 1.26s > #2 (scanf) 210M 22.9s 1.07s > #3 (no strtoul) 202M 22.8s 0.94s > #4 (string list) 181M 23.1s 0.87s At a glance, the size improvements in 0004 look the most interesting to me. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com