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.96) (envelope-from ) id 1vnjBG-00Apbd-1e for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 20:08:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnjBF-00DJwD-12 for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 20:08:53 +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.96) (envelope-from ) id 1vnjBE-00DJw3-2c for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 20:08:52 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnjBC-00000000Zi7-3BwF for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 20:08:51 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-409440b98b5so135713fac.2 for ; Wed, 04 Feb 2026 12:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770235730; x=1770840530; 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=CsMNIbgWqK/lcL10sichVVZ27M8exXtKoEIW+ddDBpU=; b=kYqpPk5novK9/XfckHjtiZKXLN71bhNt8/vgEyn4M+tRPH9/wspUx8hTzQwEAG5+D/ drQZi21lYgPHDZ1vlnaBN7jas4wqwWmzmGLbVxwWsEFRHC7kearqhyY64QT+F9HJui6l BaBPWd0qqgxvf6KtGJDrqhtTUbhFh1R7TmKRZYfe+qR4JaDJJN7CvksdP10GLh+pe6hh l+9FpjROkAniXXSK0wCFGG2AS6NAldb4NYR66enqC3semZcxSzUK6H9EaxV16t9epD4M pcN0hRjIE632FuwHrSNaVJ9C8U8Le0RvjMwaMf3y7tcTkdREAyJNJZ5mArUwiXIyXk1X o9+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770235730; x=1770840530; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CsMNIbgWqK/lcL10sichVVZ27M8exXtKoEIW+ddDBpU=; b=pPOBFJn7nCopNG3EI5ISeWjp4im2UjkF4eVNpic9qpvu3O02GOKpmXRQy0wVbG3KdL q+zjHOIYxomitEtnx9F1JJzNFxEnRAcBC70ZnU4XMlyCc574PAvouef6VEVWvl0xU4Fa jRUICv/xxKAX+tohN2DIOixex6/V2fbylyoBY+Fgs79Bn3ZqExIZJ6czlb8mCJsw+i8Y B9kemHKnzvNo+c9WiatUlWtGcAHjirxzarhUXFgQAq/viq/PGomiHc+G/bTKdtNt7ztS QvirlKnXkT2DmFPrWqz3aSrtqcDnTKWDlmL8ykiWtArdDcyvll4L/L0mL4C9xUoiaWrB Xlog== X-Forwarded-Encrypted: i=1; AJvYcCU5e9yio+K2ewrb/HdiTGRoCoY/RLcXAH3B0IVFHwLevcvROGP/tq0RB2mhpqA8F/A5eZd5l5+hq6QhRbOp@lists.postgresql.org X-Gm-Message-State: AOJu0Yy450GrEgy/gwh+H7DPuPi8CoqlxnqVBgoAGIb3eaB5zvxxYU8Z a4ORkUOA5aqDswsfQbmZ5dFq/hh5CxKseRHtn/+FhAz2VjMlBtR1q8VN X-Gm-Gg: AZuq6aKLI9LGsdmGFBch32JsPe37fVtuz+hFXGqRVIUsJWQFIGJZmmRR+3L53P1mRP1 Dw7LChvhqp8ZpGLs/kTWQR6RJhdZhlCNi8fpgRbmWgxO0cfR3rd0VKW75knuFGXpgMzZCVHTf/8 9No69DZW9K6sNY0jZOTpxIinuE0FEP6dLH6iw1Z0sQWitV1Qx7J/CgCITRl+fdPMTARj9X3a832 xyYdZLTO4dkrC78JanKs9YYw58To2pX8bt+9ZOiJWk8TuxeDjarBLMJDSSo2TKQRUMFvUrvp2UM gzgBz/zd+0WljOfBoJMd1SW9KZv6vLAbtF2FtVKy1bFcy47z+5DdXbXnP7Ao3hNifT9Blxoy7RR rBZ4IJrbaMuaykp4SRx61K19S84iocuw1RzYx2+aJxXAvwLCYwDhBS7z5R/Mctf+paorIz7Fnif p2iAtumgWf0ok+ZCk/AXfSAYgRG7F77+BLz1XAik4q6EKS1GcVOPofISb8Hm1RKt/Yhy9gyMOs5 K8D X-Received: by 2002:a05:6820:162c:b0:663:547:3e98 with SMTP id 006d021491bc7-66a20e5a329mr2131079eaf.21.1770235729896; Wed, 04 Feb 2026 12:08:49 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-66a60d8f190sm1648635eaf.7.2026.02.04.12.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 12:08:49 -0800 (PST) Date: Wed, 4 Feb 2026 14:08:47 -0600 From: Nathan Bossart To: Andres Freund Cc: Michael Paquier , Tom Lane , Nitin Motiani , Hannu Krosing , PostgreSQL Hackers Subject: Re: pg_upgrade: transfer pg_largeobject_metadata's files when possible Message-ID: References: <3yd2ss6n7xywo6pmhd7jjh3bqwgvx35bflzgv3ag4cnzfkik7m@hiyadppqxx6w> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b49++7dxSxUMQ6ai" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --b49++7dxSxUMQ6ai Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 04, 2026 at 10:06:29AM -0600, Nathan Bossart wrote: > IIUC your critique is that this doesn't explain the overwriting behavior > like the older comment does. I'll work on adding that. > > [...] > > I'm considering a couple of options here, but it seems like the easiest > thing to do is to move the TRUNCATE commands to the end of the dump file. > At least, that seems to be sufficient for our existing tests. If that > seems okay to you, I can work on putting together a patch. Here is a rough first draft of a patch that does this. -- nathan --b49++7dxSxUMQ6ai Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-fix-pg_largeobject_metadata-file-transfer.patch From c911f5b16132514a461f72b550ee8cd86dfadc1d Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 4 Feb 2026 14:04:18 -0600 Subject: [PATCH v1 1/1] fix pg_largeobject_metadata file transfer --- src/bin/pg_dump/pg_dump.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2bebefd0ba2..3ba57492fa6 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -379,6 +379,7 @@ static const char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts) static void getLOs(Archive *fout); static void dumpLO(Archive *fout, const LoInfo *loinfo); static int dumpLOs(Archive *fout, const void *arg); +static void dumpLOTruncation(Archive *fout); static void dumpPolicy(Archive *fout, const PolicyInfo *polinfo); static void dumpPublication(Archive *fout, const PublicationInfo *pubinfo); static void dumpPublicationTable(Archive *fout, const PublicationRelInfo *pubrinfo); @@ -1157,7 +1158,10 @@ main(int argc, char **argv) * subsequent COMMENT and SECURITY LABEL commands work. pg_upgrade * can't copy/link the files from older versions because aclitem * (needed by pg_largeobject_metadata.lomacl) changed its storage - * format in v16. + * format in v16. At the end of the dump, we'll generate a TRUNCATE + * command for pg_largeobject_metadata so that it's contents are + * cleared in preparation for the subsequent file transfer by + * pg_upgrade. */ if (fout->remoteVersion >= 160000) lo_metadata->dataObj->filtercond = "WHERE oid IN " @@ -1243,6 +1247,13 @@ main(int argc, char **argv) for (i = 0; i < numObjs; i++) dumpDumpableObject(fout, dobjs[i]); + /* + * For binary upgrades, set relfrozenxids, relminmxids, and relfilenodes + * of pg_largeobject and maybe pg_largeobject_metadata, and remove all + * their files. We will transfer them from the old cluster as needed. + */ + dumpLOTruncation(fout); + /* * Set up options info to ensure we dump what we want. */ @@ -3671,6 +3682,20 @@ dumpDatabase(Archive *fout) .dropStmt = delQry->data, .deps = &dbDumpId)); + PQclear(res); + + free(qdatname); + destroyPQExpBuffer(dbQry); + destroyPQExpBuffer(delQry); + destroyPQExpBuffer(creaQry); + destroyPQExpBuffer(labelq); +} + +static void +dumpLOTruncation(Archive *fout) +{ + DumpOptions *dopt = fout->dopt; + /* * pg_largeobject comes from the old system intact, so set its * relfrozenxids, relminmxids and relfilenode. @@ -3769,14 +3794,14 @@ dumpDatabase(Archive *fout) ArchiveEntry(fout, nilCatalogId, createDumpId(), ARCHIVE_OPTS(.tag = "pg_largeobject", .description = "pg_largeobject", - .section = SECTION_PRE_DATA, + .section = SECTION_POST_DATA, .createStmt = loOutQry->data)); if (fout->remoteVersion >= 160000) ArchiveEntry(fout, nilCatalogId, createDumpId(), ARCHIVE_OPTS(.tag = "pg_largeobject_metadata", .description = "pg_largeobject_metadata", - .section = SECTION_PRE_DATA, + .section = SECTION_POST_DATA, .createStmt = lomOutQry->data)); PQclear(lo_res); @@ -3787,14 +3812,6 @@ dumpDatabase(Archive *fout) destroyPQExpBuffer(loOutQry); destroyPQExpBuffer(lomOutQry); } - - PQclear(res); - - free(qdatname); - destroyPQExpBuffer(dbQry); - destroyPQExpBuffer(delQry); - destroyPQExpBuffer(creaQry); - destroyPQExpBuffer(labelq); } /* -- 2.50.1 (Apple Git-155) --b49++7dxSxUMQ6ai--