@@ -255,6 +255,7 @@ static unsigned int temp_obj_num = 0; /* temporary objects counter */
255
255
static bool no_kill_backend = false; /* abandon when timed-out */
256
256
static bool no_superuser_check = false;
257
257
static SimpleStringList exclude_extension_list = {NULL , NULL }; /* don't repack tables of these extensions */
258
+ static int lock_wait_max = 1 ; /* Max lock statement timeout, in seconds */
258
259
259
260
/* buffer should have at least 11 bytes */
260
261
static char *
@@ -284,6 +285,7 @@ static pgut_option options[] =
284
285
{ 'b' , 'D' , "no-kill-backend" , & no_kill_backend },
285
286
{ 'b' , 'k' , "no-superuser-check" , & no_superuser_check },
286
287
{ 'l' , 'C' , "exclude-extension" , & exclude_extension_list },
288
+ { 'i' , 'L' , "lock-wait-max" , & lock_wait_max },
287
289
{ 0 },
288
290
};
289
291
@@ -307,6 +309,12 @@ main(int argc, char *argv[])
307
309
if (dryrun )
308
310
elog (INFO , "Dry run enabled, not executing repack" );
309
311
312
+ if (wait_timeout < lock_wait_max )
313
+ {
314
+ ereport (ERROR , (errcode (EINVAL ),
315
+ errmsg ("wait-timeout needs to be >= lock-wait-max" )));
316
+ }
317
+
310
318
if (r_index .head || only_indexes )
311
319
{
312
320
if (r_index .head && table_list .head )
@@ -1673,7 +1681,7 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name)
1673
1681
break ;
1674
1682
1675
1683
/* wait for a while to lock the table. */
1676
- wait_msec = Min (1000 , i * 100 );
1684
+ wait_msec = Min (lock_wait_max , Max ( lock_wait_max / 10 * i , 100 ) );
1677
1685
printfStringInfo (& sql , "SET LOCAL statement_timeout = %d" , wait_msec );
1678
1686
pgut_command (conn , sql .data , 0 , NULL );
1679
1687
@@ -1814,7 +1822,7 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
1814
1822
}
1815
1823
1816
1824
/* wait for a while to lock the table. */
1817
- wait_msec = Min (1000 , i * 100 );
1825
+ wait_msec = Min (lock_wait_max , Max ( lock_wait_max / 10 * i , 100 ) );
1818
1826
snprintf (sql , lengthof (sql ), "SET LOCAL statement_timeout = %d" , wait_msec );
1819
1827
pgut_command (conn , sql , 0 , NULL );
1820
1828
@@ -2240,4 +2248,5 @@ pgut_help(bool details)
2240
2248
printf (" -Z, --no-analyze don't analyze at end\n" );
2241
2249
printf (" -k, --no-superuser-check skip superuser checks in client\n" );
2242
2250
printf (" -C, --exclude-extension don't repack tables which belong to specific extension\n" );
2251
+ printf (" -L, --lock-wait-max=SECS lock statement max wait time\n" );
2243
2252
}
0 commit comments