Skip to content

Commit ef4dc5a

Browse files
committed
Tweak apply_log() loop so that we don't wait until getting
all the way down to 0 rows processed before performing the table swap step.
1 parent 8f61e44 commit ef4dc5a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bin/pg_repack.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ const char *PROGRAM_VERSION = "unknown";
4848
*/
4949
#define APPLY_COUNT 1000
5050

51+
/* Once we get down to seeing fewer than this many tuples in the
52+
* log table, we'll say that we're ready to perform the switch.
53+
*/
54+
#define MIN_TUPLES_BEFORE_SWITCH 20
55+
5156
/* poll() or select() timeout, in seconds */
5257
#define POLL_TIMEOUT 3
5358

@@ -1305,7 +1310,16 @@ repack_one_table(repack_table *table, const char *orderby)
13051310
for (;;)
13061311
{
13071312
num = apply_log(connection, table, APPLY_COUNT);
1308-
if (num > 0)
1313+
1314+
/* We'll keep applying tuples from the log table in batches
1315+
* of APPLY_COUNT, until applying a batch of tuples
1316+
* (via LIMIT) results in our having applied
1317+
* MIN_TUPLES_BEFORE_SWITCH or fewer tuples. We don't want to
1318+
* get stuck repetitively applying some small number of tuples
1319+
* from the log table as inserts/updates/deletes may be
1320+
* constantly coming into the original table.
1321+
*/
1322+
if (num > MIN_TUPLES_BEFORE_SWITCH)
13091323
continue; /* there might be still some tuples, repeat. */
13101324

13111325
/* old transactions still alive ? */

0 commit comments

Comments
 (0)