Re: Should we add timing output to pg_upgrade?

From: Chao Li <li(dot)evan(dot)chao(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 add timing output to pg_upgrade?
Date: 2026-12-01 05:51:18
Message-ID: 13D1B5F9-C17A-4D6F-8CFF-A989C65D3DD2@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Dec 1, 2026, at 09:56, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> I've been doing some work on making pg_upgrade go faster, and I found
> it annoying that we don't include the timing output for each phase. I
> think we should have this as seeing a high number there is more likely
> going to lead to someone investigating, or if we receive pg_upgrade
> output with "this is too slow" type complaints, it'll be easier to get
> to the bottom of why.
>
> I prompted an LLM to write a patch for this, coaxing it into using
> this time format. I left the actual implementation up to it. It went
> with a global variable to store the start time. I think that's likely
> a better option than having the prep_status functions return the start
> time, as that would require a much more invasive patch. Having an
> extra global in pg_upgrade seems fine to me. I'd more strongly be
> considering alternative ways for backend code.
>
> The format I asked it to output was to list all units with a
> single-char suffix, only omitting units that are zero when all other
> higher-order units are also zero.
>
> Sample:
>
> Setting next multixact ID and offset for new cluster ok (0.030s)
> ...
> Restoring database schemas in the new cluster ok (2m 0.274s)
>
> I considered alternative ways of showing the time, but on looking for
> inspiration, nothing I found seemed to suit better. e.g. make check
> (or meson test --suite regress) shows the number of milliseconds.
> What's being timed there is much more constrained in how long it's
> likely to run. pg_upgrades can take a long time and I don't think
> showing millions of milliseconds is readable.
>
> I also considered the interval output. i.e. "1 day 01:56:40.1234" or
> "01:56:40.1234", but I think that makes it much less clear what's
> being displayed, especially so for durations less than 1 day. Looks
> more like it's displaying the time of day.
>
> Human reviewed and lightly edited, but LLM-generated patch is
> attached. Also, a file with sample output.
>
> Does it look ok? Or better ideas for time formats? Or objections?
>
> David
> <pg_upgrade_timing.patch><patched_pg_upgrade.out>

+1 for reporting the duration of each step. The time formats look good to me.

I don’t see where pg_initialize_timing() is called. Its header comment says it must be called:
```
/*
* Initialize timing infrastructure
*
* This must be called at least once before using INSTR_TIME_SET_CURRENT*
* macros.
*
* If you want to use the TSC clock source in a client program,
* pg_set_timing_clock_source() needs to also be called.
*/
extern void pg_initialize_timing(void);
```

Also, by searching for where check_ok() is called, I found this in check_for_unicode_update():
```
if (report.file)
{
fclose(report.file);
report_status(PG_WARNING, "warning");
pg_log(PG_WARNING, "Your installation contains relations that might be affected by a new version of Unicode.\n"
"A list of potentially-affected relations is in the file:\n"
" %s", report.path);
}
else
check_ok();
```

So, when the status is "warning", no duration is reported. I think we should report the duration for non-ok statuses as well.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Henson Choi 2026-12-01 06:05:03 Speed up tuplestore_seek() by starting from the nearest known position
Previous Message shveta malik 2026-12-01 05:49:55 Re: Preserve conflict log table during upgrade