From 45a9894674113bb14436db3cb73acf97e99c5115 Mon Sep 17 00:00:00 2001 From: Eric Radman Date: Fri, 12 Jul 2024 10:51:03 -0400 Subject: [PATCH] Repack all tables smallest to largest Free up space early to improve the overhead for repacking large tables. Preserve ordering by relname, schemaname for tests if MAKELEVEL is defined. --- bin/pg_repack.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 97335b5..2262960 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -874,8 +874,13 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) appendStringInfoString(&sql, ")"); } - /* Ensure the regression tests get a consistent ordering of tables */ - appendStringInfoString(&sql, " ORDER BY t.relname, t.schemaname"); + /* Ensure the regression tests get a consistent ordering of tables + * Otherwise repack small objects first to free space on disk + */ + if (getenv("MAKELEVEL")) + appendStringInfoString(&sql, " ORDER BY t.relname, t.schemaname"); + else + appendStringInfoString(&sql, " ORDER BY pg_relation_size(t.relid)"); /* double check the parameters array is sane */ if (iparam != num_params)