| From: | John Naylor <johncnaylorls(at)gmail(dot)com> |
|---|---|
| To: | David Rowley <dgrowleyml(at)gmail(dot)com> |
| Cc: | PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Should we skip foreign key checks in binary upgrade mode? |
| Date: | 2026-11-25 03:35:46 |
| Message-ID: | CANWCAZaFq0dL0zrXp3Kb4Dos80NUFHg0cnsMq-vU6kYLK+XAvw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, Nov 25, 2026 at 5:11 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> I've been investigating some internally reported pg_upgrade slowness.
> The schema I was given (attached) creates a few highly partitioned
> tables and foreign keys that reference some partitioned tables.
I've recently seen a real-world case that took more than 24 hours, but
haven't thought about how to address that in the near-term, so thanks
for this. (To toot my own horn, in-place upgrade should take less than
10 seconds for the same case, but that's a ways off and by no means
guaranteed...)
In my preliminary investigation with FKs declared on the parent table
with M list partitions on the referencing side and N list partitions
on the referenced side, I found the runtime is O(M x N^2) for the FK
check.
> What I'm wondering now is if we should just skip the foreign key
> checks when IsBinaryUpgrade == true. We expect all tables to be empty
> in that case, so I'm not sure there's any point in doing the checks.
> One problem might be that, in theory, someone could run postgres
> directly without using pg_ctl and pass the -b flag to run in binary
> upgrade mode and create a valid foreign key with violations.
More realistically, a possible magnet for LLM-generated bug reports,
but I would hope the comment in the patch would fend that off.
> So the patch knocks about 35% off the runtime of restoring the schema.
-- Largest 1.52M-pg_class tier (Table 3.3 Row 7, ~8.1h unpatched ->
~1.1h patched):
This case from the .sql file seems even more encouraging for my above case.
> If we did decide to do this, then likely there's more that could be
> done along these lines. I've not looked in any detail, but in theory
> there's probably not much reason to create relation files during
> CREATE TABLE when pg_upgrade is going to copy in the old one.
That may be difficult. For example, I would think the CREATE INDEX
statements on leaf partitions need the heaps to exist. With the patch,
it might be good to see where the rest of the run time is going.
--
John Naylor
Amazon Web Services
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manu | 2026-11-25 03:41:34 | Re: Dropping a composite attribute causes data integrity violations |
| Previous Message | Manu | 2026-11-25 03:02:49 | Re: Make COPY format extendable: Extract COPY TO format implementations |