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 1uC1PX-009Wkj-UK for pgsql-hackers@arkaria.postgresql.org; Mon, 05 May 2025 19:23:32 +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 1uC1PW-005EqU-Vg for pgsql-hackers@arkaria.postgresql.org; Mon, 05 May 2025 19:23:30 +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 1uC1PW-005EqM-I3 for pgsql-hackers@lists.postgresql.org; Mon, 05 May 2025 19:23:30 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uC1PT-000JDh-2N for pgsql-hackers@lists.postgresql.org; Mon, 05 May 2025 19:23:29 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3cfce97a3d9so24474175ab.2 for ; Mon, 05 May 2025 12:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746473008; x=1747077808; 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=JHQoPobbYWw1+Inxxgh+sB2rk00U9MReMyqc7EC5Ts8=; b=LW5bpvLpgBuSLXTWm5tJCQehKQcNFL8cCDHPBuDw6Zg6y4cMq3gjaCIM2mDJEtR5sz NnjHZVhj3cpiAkI8pmQIx2zbKESmLczwtrHe+zd5StHiwym7Zj4ID8VvzaWqDjWZ56Xx tJ6bnUDvHyRJTqlTx+pEWuBOi1pSRfVtKOcLrijmiobQLhXItszZd/GZvqPpkoiht1qr 9SHOsKiAJo8dSMYxsD6QCH1YkGMmHF54piPVIV3OU/3EQ8Na1GhUxIOQw4/LUi3zjHqx jN7xRXb6oSacMJHfNUJ/gqjhpvr45cx/ZVfeBkszK17upXc4mvTDQIGYFB+iRY0uT71c lmcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746473008; x=1747077808; 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=JHQoPobbYWw1+Inxxgh+sB2rk00U9MReMyqc7EC5Ts8=; b=HcjvVgBBLF8L+MUv+IZJEtLmF91xZQJNzzcutsWuDbKi8cgp0vfr/UHCW1ZF7aXshG oXPWBb6BTX9QBMkIARUuWwrJDWr7V7d7w4mLD7ub1pSv3ifYJ8s0xiisEyyUZ8mEXtsE luU216/Ed2zL+CYqYUq4/hlOA8iMXqkMUNxPma2kYT1mVSqUg+g9ClwfnWWWLaCrTsHv YHxrFu8i1OMeg24was001thgmXtMvMQm9DkPVuUwWaVCo5MTyLbpOjrJQLO/ak7c+BC2 F5pPB1Eq7GXlRL0h7Sq4pFfRwb8AzmlkrHBrxgSLH/LN/MAEy70ssz42o1VSIqGxOfrj bAAA== X-Forwarded-Encrypted: i=1; AJvYcCXhdFzwhbMlLWqE3S3akmE3cWzAe1RZLqwtcJwx13xqsYyAOt3Wz7D9SqHCStQBfmA15RgfYEMPLLv5WbJt@lists.postgresql.org X-Gm-Message-State: AOJu0Yw0BqDOHUsQpGq1ETrVIjKTWdVtzX45AWQvrfZdv54gkoTDxmTk 5mM0XilcTZx3tisxWjwWwgOGZ2uo7WAeGuCOMJ47KWLFZ8YAdbPY X-Gm-Gg: ASbGncuww1cHsERfwqJ03nG9ZgcLMfZP8FsR4ofdjor/g3iP/sOxqwdiqKe7wLDlpon cbBhxHN8wm3/eGQ6f3eIRhX9HhGAp02sGJiOQdYNJPrMOU/QXRiTrX97w5hXqzwjkzq7jVJNYez hq8JxXs9dJlmicBRXZDEuT17PGK5aXx8ritxLKp1O09Jq1Hz3z6bFCBc2WcxLbZaVSgv9mdK16t ryQeS/de51YqH9mVKU3nt3nySma7TD9FUtEbXj487wNrTFUrY/qKKLm0lDycMgeLRbKH40QvVc+ mH4rLa5Xcjj3aCxz8pnNXo6s3/0Zis/HTPNgmEoU2VR79rqVT5ggQ/Z67CR/wZ9sOuby0vE75x5 4eO+4jQ97wKDyRJx4uBzdS80fad7EdPLmlUJY X-Google-Smtp-Source: AGHT+IFsLkrme73Vq9XLGpq6kTMwTRABq/9POINPTkmHyD+29mGCeZO2Uwa/ANODw6NibvLskUguww== X-Received: by 2002:a05:6e02:1a26:b0:3d6:d162:be12 with SMTP id e9e14a558f8ab-3da5b3437e9mr90169395ab.21.1746473007606; Mon, 05 May 2025 12:23:27 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4f88aa8d6b7sm1908946173.118.2025.05.05.12.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 May 2025 12:23:26 -0700 (PDT) Date: Mon, 5 May 2025 14:23:25 -0500 From: Nathan Bossart To: Tom Lane Cc: Hannu Krosing , PostgreSQL Hackers Subject: Re: Horribly slow pg_upgrade performance with many Large Objects Message-ID: References: <4044567.1744128814@sss.pgh.pa.us> <4047312.1744130263@sss.pgh.pa.us> <4050387.1744132029@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1L9BvNMT6l66k1TO" Content-Disposition: inline In-Reply-To: <4050387.1744132029@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1L9BvNMT6l66k1TO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Apr 08, 2025 at 01:07:09PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> I do think it's worth considering going back to copying >> pg_largobject_metadata's files for upgrades from v16 and newer. > > (If we do this) I don't see why we'd need to stop at v16. I'm > envisioning that we'd use COPY, which will be dealing in the > text representation of aclitems, and I don't think that's changed > in a long time. The sort of thing that would break it is changes > in the set of available/default privilege bits for large objects. > > That is, where the dump currently contains something like > > SELECT pg_catalog.lo_create('2121'); > ALTER LARGE OBJECT 2121 OWNER TO postgres; > GRANT ALL ON LARGE OBJECT 2121 TO joe; > > we'd have > > COPY pg_largeobject_metadata FROM STDIN; > ... > 2121 10 {postgres=rw/postgres,joe=rw/postgres} > ... > > and some appropriate COPY data for pg_shdepend too. Attached is a proof-of-concept grade patch for using COPY for pg_largeobject_metadata and the relevant pg_shdepend entries. On my laptop, pg_upgrade with 10M LOs (each with a non-bootstrap-superuser owner and another role with SELECT rights) goes from ~8.5 minutes to ~1 minute with this patch. I originally set out to invent a new lo_create_with_owner() function and teach pg_dump to batch those together in large groups, but as I started the required pg_dump surgery, I was quickly scared away by the complexity. Next, I gave COPY a try. The improvements from using COPY will likely be limited to the pg_upgrade case, but that's the only case I regularly hear complaints about for zillions of large objects, so maybe it's good enough for now. For the COPY approach, I modified pg_dump to dump the contents of pg_largeobject_metadata. This is easy enough, but I ran into problems with the dependent comments and security labels. It turns out that even before v12, we run all the lo_create() commands just so that creating the comments and security labels works (AFAICT). So I suspect upgrading with many large objects has always been slow. The comment/security label dependency issue can be fixed (at least well enough for the tests) by moving PRIO_LARGE_OBJECT below PRIO_TABLE_DATA. There might be an existing issue here, because dbObjectTypePriorities has the following comment: * NOTE: object-type priorities must match the section assignments made in * pg_dump.c; that is, PRE_DATA objects must sort before DO_PRE_DATA_BOUNDARY, * POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects * must sort between them. But dumpLO() puts large objects in SECTION_DATA, and PRIO_LARGE_OBJECT is before PRIO_PRE_DATA_BOUNDARY. I admittedly haven't spent too much time investigating this, though. In any case, it might be a good idea to also make sure we explicitly mark the large objects and their comments/seclabels as dependent on the pg_largeobject_metadata data. That leaves pg_shdepend. For now, I've just instructed pg_upgrade to COPY the relevant pg_shdepend rows as an independent step, but perhaps there's a reasonably straightforward way to put that in pg_dump, too. -- nathan --1L9BvNMT6l66k1TO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-pg_upgrade-Use-COPY-for-large-object-metadata.patch