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 1u3KjI-00ED5Q-Kg for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Apr 2025 20:12:00 +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 1u3KjG-00DpMe-7Z for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Apr 2025 20:11:58 +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 1u3KjF-00DpMW-PR for pgsql-hackers@lists.postgresql.org; Fri, 11 Apr 2025 20:11:58 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u3KjE-004Lh3-0v for pgsql-hackers@lists.postgresql.org; Fri, 11 Apr 2025 20:11:57 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-6ef60e500d7so21689137b3.0 for ; Fri, 11 Apr 2025 13:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744402315; x=1745007115; 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=4qb5yFAIbCmO+G3POOOiczw0yyja/jsitu/7peEtIZ8=; b=MER14qPYVyVt35KMK8s8qNSQavuo7dG6dFR/VQ/Gw7OuG0lr3KTG3VJFTdpS7CYi7T ctBIxOKWys8XmkT9mXqfvnaONH9DP2TNg6giu6Py8TLZlZH0hWnuRSGzmiiVGHp3LIPJ 0+avwhphKR0bLdljNn4b7m+lGm9RG/ocXXQQkOsUnd4td+od4IAz5N3zE424Ni3XJRqG vHQ67XuXs2RIgD7A58ryEhDR5zgqBdooBrHi3xw7g8OcyJIlDkoMJLhMo+b1TLi47dY3 cH9qDJV+2mXsyIh7gVZklN+o/6A0h2uUwFek5zaJVBJHD5uX37/rQpEO07HJcM4aKD7R f3NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744402315; x=1745007115; 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=4qb5yFAIbCmO+G3POOOiczw0yyja/jsitu/7peEtIZ8=; b=LoFIyUB6p8QchRS3qIPZMwUzCmRGJg9i6p0XSFAPF1FWddJ8Tj5VP6rSsZ1qywin7K ULiB5aSExgp54h2P70mtU8SfFT+aRnyXRBjZBqS0sZKcRxDTGRDZXpWZJy5vE0GqTz+3 jeP0TX8tGpUyfaCyCD2XCItT+B3LhvIlyPu8g8RiW7e5zrBRYi2+wUU3cTuSEc/aIetF s1nupK3ly+qomezOlerbjNUGqWKdbg64UTCcK0o+2iwYCZNEL5gc4XymKgXAKzAlVRSj AavK+JO55aQkuR9OYeWs1BiCvR/3PJYu8FjusM//JdwncvHSuT5J7ExOwJZ21I5xQX+Q OZZQ== X-Forwarded-Encrypted: i=1; AJvYcCWLkbfzfr7JXK1FewAonjS3FygIbobZjIussiuM3qPaoytWd8eDs8QoLAXQ7vkHDL19VY2wgjMPiUiktisG@lists.postgresql.org X-Gm-Message-State: AOJu0YwLn55NkQLaH7vjjPo3hKd9mrH7wc9RVBlY8stfYkInbwKNKg5G jJ+xR5yVNYch60o2s41C266lYTIfkOXiUX9UNae9h3oYbbVSy/Ac X-Gm-Gg: ASbGncvXmeujN0/UsQU04UN463JT4UbC2wkEy6Poca5Jiz485LxPunmkebePS5jHCFJ A4JXIqmg3kB+Xd3ukPtjJ16kBcLy7wCLQBHHbvvvav7YzEC4EnIRqv5LgAT/c/+z/AgQn7mf4/0 InY086AEu4n2wOexvMMYC9u2m/T3ZGi6lmq2oREMZqFH+NkrTi9XWoQX2f6iG3LgUA60kf0Eejr Z0lQH5yIYSboW/NLGPgOIv4tBNafw7JLIwpJRWfGYnfUApkT6G+k0YBvdg7cTW1w/Zu/Dz8sovS oVUwxgImN+iOcsB/9wEEXHqIg3h0p7ohCSQlvJeQitjCRKsiX7OnB+Y7otOMS7zJbfcR69Pn9FP i5/Wd8JdefA3WFeo+4Ulz0CQF8sDcjBA= X-Google-Smtp-Source: AGHT+IHhQ/r3F7t4dUIYQo3mnXFcCHBPlUbo1QjN1yaCwAL5FkSVdsgtofhfXMX7f2QTcdSwQRaZ4g== X-Received: by 2002:a05:690c:6481:b0:6fb:8461:e828 with SMTP id 00721157ae682-70559a65932mr69659777b3.30.1744402315257; Fri, 11 Apr 2025 13:11:55 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7053e0e844fsm16611067b3.23.2025.04.11.13.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Apr 2025 13:11:54 -0700 (PDT) Date: Fri, 11 Apr 2025 15:11:53 -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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 08, 2025 at 12:22:00PM -0500, Nathan Bossart wrote: > 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. > > I was thinking of actually reverting commit 12a53c7 for upgrades from v16, > which AFAICT is the last release where any relevant storage formats changed > (aclitem changed in v16). But if COPY gets us pretty close to that and is > less likely to be disrupted by future changes, it could be a better > long-term approach. > >> 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. I did some more research here. For many large objects without ACLs to dump, I noticed that the vast majority of time is going to restoring the ALTER OWNER commands. For 1 million such large objects, restoring took ~73 seconds on my machine. If I instead invented an lo_create_with_owner() function and created 100 per SELECT command, the same restore takes ~7 seconds. Copying the relevant pg_shdepend rows out and back in takes ~2.5 seconds. I imagine using COPY for pg_largeobject_metadata would also take a couple of seconds in this case. For upgrading, I don't think there's any huge benefit to optimizing the restore commands versus using COPY. It might make future catalog changes for large object stuff easier, but I'd expect those to be rare. However, the optimized restore commands could be nice for non-pg_upgrade use-cases. -- nathan