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 1urIk3-003rKD-SD for pgsql-general@arkaria.postgresql.org; Wed, 27 Aug 2025 16:11:21 +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 1urIk3-00GXkF-A8 for pgsql-general@arkaria.postgresql.org; Wed, 27 Aug 2025 16:11:19 +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 1urIk2-00GXk7-Rn for pgsql-general@lists.postgresql.org; Wed, 27 Aug 2025 16:11:19 +0000 Received: from mout.gmx.net ([212.227.17.22]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1urIk0-002Ady-26 for pgsql-general@lists.postgresql.org; Wed, 27 Aug 2025 16:11:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1756311073; x=1756915873; i=jimis@gmx.net; bh=V7KD4sZY6aKSYzZSvKYuZjkEEQkExJxRqNgHuxdtR/A=; h=X-UI-Sender-Class:Date:From:To:cc:Subject:In-Reply-To:Message-ID: References:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=XMYgepYR0B9NK2DZoeWk+mNP1Eu0ntawM8E1F1LD27bp3pGIki+G0xnfF1eyOu3R qqid25QS8gKQGBL7+V8+2Vy6pOM43sETER10gQAWTf6CjMm+SMzZcIBPb1fFb3EDe 71azP3iECd/z9WDJTPglIs55wWhSHfsAdXN4F/lhRIyE8Un9I060owHy7smpKraAx +xbEhp8nR6UboGF0H/l7HQvSi2uoiZT0qFBn+GDzXk+5Kr6JsGxsXKQyOP5IQ6Rpz r59+rJFg7ZvB3nw7wxcorSg3N0nXt027oYViCX+3D559EDxRe4y+9gdqtPRuGNg4f X3fIRT5myRkdVka6Gw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.9.70.59] ([185.55.106.54]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MnJhU-1u8Is908Qu-00dDpJ; Wed, 27 Aug 2025 18:11:13 +0200 Date: Wed, 27 Aug 2025 18:10:58 +0200 (CEST) From: Dimitrios Apostolou To: Adrian Klaver cc: pgsql-general@lists.postgresql.org Subject: Re: In-order pg_dump (or in-order COPY TO) In-Reply-To: Message-ID: <4ss66r31-558o-qq24-332q-no351p7n5osr@tzk.arg> References: <3541781s-75o7-26pp-46pp-qs54o4406192@tzk.arg> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1727961628-1756311073=:1535142" X-Provags-ID: V03:K1:51urFle6XsnIi9+tA9ItvXZ99VSt2VJhM2ESI42B/LviVkHkYN1 iFUDaKaV2Yu4qHEhfnxXwvGl59vcSYCAPjRlwx3mu/FkRqSZCGPx+MHDGxaqVNBFXoJAb4e ucb8QuCU9FzBiYEoowyi1yXMkHDBkaEqNRVz9qNGyWe6NoCMmpDIAAnOx7zYdB1g1CEl+Is XYJxWpvwTGxLu2rq1Kn4Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:YExK8kCMPM4=;379AORNeOo8SraD5jDh39rpXLe6 kLDSUQmyE2BhivMtwa+aRnJSyAnrwKe5uKkgf+KKWW4pVay9IfM8QSvYfHz+TnwJ6j/j+nroN tJBnnEA2F456ujE8UrEcl5SR35jT/zsHlDKRhYc7RGC/iFnNVD/O13B4sNJalw0MlNeOHiVM/ WtB3p0YPzco7OlWv2eTz18GwjuV7mxpzPxcvqOBLoSp/HLTsz5B3O/58NH5CPrAcVk+K3vp+X fXzr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q XVJR9ckCefkaYCYx9+XSS7/LYDdiABLqpXJGMJNCHDf7L7xFWgNEarD65y+jpDzLBgvpk8lPO vuBNF8at4Jvf8FM2nJzgV6XGv3spwb2+8ELEAksah1iQK1b7yynkAgd6WW2kU2oxxB1dLLC7l N7N/X+Gh1uR2rjklD+I74w/mfN2YTAuOZfH/rDZRjg9ZDt2Prd0Ato3pVdmjjl8O5qy99E3po fV3Rpr0TgJRadkAR+2MxCxTawiC3O2G8d1Q3CsFyM01XSatJVG9IyxjKYRCy4pUh7Q5x/IyT7 lVuHPMKwV533w7lhmfr List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1727961628-1756311073=:1535142 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On Wednesday 2025-08-27 17:25, Adrian Klaver wrote: > Comments in line below. > >> Dump is from PostgreSQL 16, it's pg_dump writing to stdout: >> >> pg_dump -v --format=3Dcustom --compress=3Dnone --no-toast-compression = =2D- >> serializable-deferrable db_name=C2=A0 |=C2=A0 borg create ... >> >> >> As you can see the backup (and deduplicating) program is borgbackup. > > Ok, I use BorgBackup and it is fairly forgiving of normal changes. > > FYI, if you ever want to use compression check out gzip --rsyncable, I h= ave=20 > found it plays well with Borg. For more information see: > > https://beeznest.wordpress.com/2005/02/03/rsyncable-gzip/ Yes, zstd has also --rsyncable. In this case I let borg do per-chunk=20 compression after deduplication, it has worked well so far. >> Restore is in PostgreSQL 17: >> >> I first create the empty tables by running the DDL commands in version >> control to setup the database. And then I do pg_restore --data-only: >> >> pg_restore -vvvv -j 8 -U db_owner -d db_name --schema=3Dpublic -- >> section=3Ddata=C2=A0 dump_file > > If you are using only the --data section why not --data-only in the pg_d= ump? I want the dump to be as complete as possible. Didn't think it would=20 create issues. > > Or is the pg_dump output used for other purposes? It has happened that I have selectively restored user schemas from that=20 dump. >> Worth noting is that the above pg_restore goes through the WAL, i.e. a= ll >> writes are done by walwriter, not the backend directly. > > Please explain the above further. The COPY FROM data is going through the WAL, as usual INSERTS do. The=20 writes to disk happen by the walwriter process. OTOH, If you have configured the server with wal_level=3Dminimal and=20 BEGIN a transaction, CREATE or TRUNCATE a table, and then COPY FROM into= =20 that table, then the backend process writes directly to the table=20 without logging to the WAL. This can be much faster, but most importantly it avoids situations of=20 WAL overflow that are very difficult to predict and can mess your server= =20 up completely. [1] [1] https://www.postgresql.org/message-id/flat/076464ad-3d70-dd25-9e8f-e84= f27decfba%40gmx.net My patches are for activating that codepath in pg_restore, but they were= =20 not used on purpose and I took notice that the writes went via WAL. > > The problem occurs when you do the pg_dump after this restore, correct? Correct. The first pg_dump from the restored pg17 is not deduplicated at= =20 all. Most of the tables have not changed (logically at least; apparently= =20 they have changed physically). > > Is it the same pg_dump command as you show above? Yes. > >> >> Postgres is standard open source running on own server. It has a coupl= e of >> custom patches that shouldn't matter in this codepath. > > For completeness and just in case they may affect the output what do the= =20 > patches do? Two patches for speeding up scanning an archive without TOC, like the=20 one I'm having (because it is piped into borg, instead of written to=20 file). These were activated, but shouldn't matter. They only build the=20 TOC in pg_restore's memory. https://commitfest.postgresql.org/patch/5809/ https://commitfest.postgresql.org/patch/5817/ And two patches for speeding up pg_restore like mentioned above, under=20 specific arguments that I didn't provide. (one speedup needs --clean,=20 and the other needs --freeze). https://commitfest.postgresql.org/patch/5821/ https://commitfest.postgresql.org/patch/5826/ IIRC I did not activate them (via --clean) because TRUNCATE fails when=20 foreign keys exist. See the discussion threads. Dimitris --0-1727961628-1756311073=:1535142--