@@ -256,6 +256,7 @@ static unsigned int temp_obj_num = 0; /* temporary objects counter */
256256static bool no_kill_backend = false; /* abandon when timed-out */
257257static bool no_superuser_check = false;
258258static SimpleStringList exclude_extension_list = {NULL , NULL }; /* don't repack tables of these extensions */
259+ static int lock_wait_max = 1 ; /* Max lock statement timeout, in seconds */
259260
260261/* buffer should have at least 11 bytes */
261262static char *
@@ -285,6 +286,7 @@ static pgut_option options[] =
285286 { 'b' , 'D' , "no-kill-backend" , & no_kill_backend },
286287 { 'b' , 'k' , "no-superuser-check" , & no_superuser_check },
287288 { 'l' , 'C' , "exclude-extension" , & exclude_extension_list },
289+ { 'i' , 'L' , "lock-wait-max" , & lock_wait_max },
288290 { 0 },
289291};
290292
@@ -308,6 +310,12 @@ main(int argc, char *argv[])
308310 if (dryrun )
309311 elog (INFO , "Dry run enabled, not executing repack" );
310312
313+ if (wait_timeout < lock_wait_max )
314+ {
315+ ereport (ERROR , (errcode (EINVAL ),
316+ errmsg ("wait-timeout needs to be >= lock-wait-max" )));
317+ }
318+
311319 if (r_index .head || only_indexes )
312320 {
313321 if (r_index .head && table_list .head )
@@ -1789,7 +1797,7 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
17891797 break ;
17901798
17911799 /* wait for a while to lock the table. */
1792- wait_msec = Min (1000 , i * 100 );
1800+ wait_msec = Min (lock_wait_max * 1000 , Max ( lock_wait_max * 1000 * i / 10 , 100 ) );
17931801 printfStringInfo (& sql , "SET LOCAL statement_timeout = %d" , wait_msec );
17941802 pgut_command (conn , sql .data , 0 , NULL );
17951803
@@ -1930,7 +1938,7 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
19301938 }
19311939
19321940 /* wait for a while to lock the table. */
1933- wait_msec = Min (1000 , i * 100 );
1941+ wait_msec = Min (lock_wait_max * 1000 , Max ( lock_wait_max * 1000 * i / 10 , 100 ) );
19341942 snprintf (sql , lengthof (sql ), "SET LOCAL statement_timeout = %d" , wait_msec );
19351943 pgut_command (conn , sql , 0 , NULL );
19361944
@@ -2351,6 +2359,7 @@ pgut_help(bool details)
23512359 printf (" -i, --index=INDEX move only the specified index\n" );
23522360 printf (" -x, --only-indexes move only indexes of the specified table\n" );
23532361 printf (" -T, --wait-timeout=SECS timeout to cancel other backends on conflict\n" );
2362+ printf (" -L, --lock-wait-max=SECS lock statement max wait time\n" );
23542363 printf (" -D, --no-kill-backend don't kill other backends when timed out\n" );
23552364 printf (" -Z, --no-analyze don't analyze at end\n" );
23562365 printf (" -k, --no-superuser-check skip superuser checks in client\n" );
0 commit comments