From de0a115728d91f1e0beff6bb658ca252fad768b2 Mon Sep 17 00:00:00 2001 From: Alex Richman Date: Fri, 12 Apr 2024 16:21:51 +0100 Subject: [PATCH 1/3] Add apply-count parameter --- bin/pg_repack.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 6feae8d..b7ed997 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -43,10 +43,10 @@ const char *PROGRAM_VERSION = "unknown"; /* - * APPLY_COUNT: Number of applied logs per transaction. Larger values + * APPLY_COUNT_DEFAULT: Number of applied logs per transaction. Larger values * could be faster, but will be long transactions in the REDO phase. */ -#define APPLY_COUNT 1000 +#define APPLY_COUNT_DEFAULT 1000 /* Once we get down to seeing fewer than this many tuples in the * log table, we'll say that we're ready to perform the switch. @@ -258,6 +258,7 @@ static bool no_kill_backend = false; /* abandon when timed-out */ static bool no_superuser_check = false; static SimpleStringList exclude_extension_list = {NULL, NULL}; /* don't repack tables of these extensions */ static bool error_on_invalid_index = false; /* don't repack when invalid index is found */ +static int apply_count = APPLY_COUNT_DEFAULT; static int switch_threshold = SWITCH_THRESHOLD_DEFAULT; /* buffer should have at least 11 bytes */ @@ -288,7 +289,8 @@ static pgut_option options[] = { 'b', 'D', "no-kill-backend", &no_kill_backend }, { 'b', 'k', "no-superuser-check", &no_superuser_check }, { 'l', 'C', "exclude-extension", &exclude_extension_list }, - { 'b', 2, "error-on-invalid-index", &error_on_invalid_index }, + { 'b', 3, "error-on-invalid-index", &error_on_invalid_index }, + { 'i', 2, "apply-count", &apply_count }, { 'i', 1, "switch-threshold", &switch_threshold }, { 0 }, }; @@ -308,6 +310,10 @@ main(int argc, char *argv[]) (errcode(EINVAL), errmsg("too many arguments"))); + if(switch_threshold >= apply_count) + ereport(ERROR, (errcode(EINVAL), + errmsg("switch_threshold must be less than apply_count"))); + check_tablespace(); if (dryrun) @@ -1547,10 +1553,10 @@ repack_one_table(repack_table *table, const char *orderby) */ for (;;) { - num = apply_log(connection, table, APPLY_COUNT); + num = apply_log(connection, table, apply_count); /* We'll keep applying tuples from the log table in batches - * of APPLY_COUNT, until applying a batch of tuples + * of apply_count, until applying a batch of tuples * (via LIMIT) results in our having applied * switch_threshold or fewer tuples. We don't want to * get stuck repetitively applying some small number of tuples @@ -2377,5 +2383,6 @@ pgut_help(bool details) printf(" -k, --no-superuser-check skip superuser checks in client\n"); printf(" -C, --exclude-extension don't repack tables which belong to specific extension\n"); printf(" --error-on-invalid-index don't repack tables which belong to specific extension\n"); - printf(" --switch-threshold switch tables when that many tuples are left to catchup\n"); + printf(" --apply-count number of tuples to apply in one transaction during replay\n"); + printf(" --switch-threshold switch tables when that many tuples are left to catchup\n"); } From c99c0248f652d84165d86223d1b676ac8d71b67c Mon Sep 17 00:00:00 2001 From: Alex Richman Date: Fri, 12 Apr 2024 16:29:11 +0100 Subject: [PATCH 2/3] Fxup: Tabs instead of spaces --- bin/pg_repack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index b7ed997..62c2a5b 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -310,9 +310,9 @@ main(int argc, char *argv[]) (errcode(EINVAL), errmsg("too many arguments"))); - if(switch_threshold >= apply_count) - ereport(ERROR, (errcode(EINVAL), - errmsg("switch_threshold must be less than apply_count"))); + if(switch_threshold >= apply_count) + ereport(ERROR, (errcode(EINVAL), + errmsg("switch_threshold must be less than apply_count"))); check_tablespace(); From 2fbe4beaee23450d6b94c117931ec9745386460e Mon Sep 17 00:00:00 2001 From: Alex Richman Date: Mon, 15 Apr 2024 12:55:38 +0100 Subject: [PATCH 3/3] Add docs and test cases --- doc/pg_repack.rst | 1 + regress/expected/repack-check.out | 5 +++++ regress/sql/repack-check.sql | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index f4b1ab9..824e1c2 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -126,6 +126,7 @@ Options: -k, --no-superuser-check skip superuser checks in client -C, --exclude-extension don't repack tables which belong to specific extension --error-on-invalid-index don't repack when invalid index is found + --apply-count number of tuples to apply in one trasaction during replay --switch-threshold switch tables when that many tuples are left to catchup Connection options: diff --git a/regress/expected/repack-check.out b/regress/expected/repack-check.out index 5ab9eca..a2c0970 100644 --- a/regress/expected/repack-check.out +++ b/regress/expected/repack-check.out @@ -341,6 +341,11 @@ INFO: repacking index "public.child_b_2_pkey" INFO: repacking indexes of "public.parent_b" INFO: repacking index "public.parent_b_pkey" -- +-- Apply count +-- +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --apply-count 1234 +INFO: repacking table "public.tbl_cluster" +-- -- Switch threshold -- \! pg_repack --dbname=contrib_regression --table=tbl_cluster --switch-threshold 200 diff --git a/regress/sql/repack-check.sql b/regress/sql/repack-check.sql index 34018b0..189bd83 100644 --- a/regress/sql/repack-check.sql +++ b/regress/sql/repack-check.sql @@ -170,6 +170,10 @@ CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b); -- => OK \! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes +-- +-- Apply count +-- +\! pg_repack --dbname=contrib_regression --table=tbl_cluster --apply-count 1234 -- -- Switch threshold --