From cac2340ada73a4aaf535f946036219ae57e858cf 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 44caeb0..9032f4f 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -871,8 +871,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)