@@ -249,6 +249,7 @@ static bool moveidx = false;
249249static SimpleStringList r_index = {NULL , NULL };
250250static bool only_indexes = false;
251251static int wait_timeout = 60 ; /* in seconds */
252+ static int max_lock_timeout_msec = 1000 ;
252253static int jobs = 0 ; /* number of concurrent worker conns. */
253254static bool dryrun = false;
254255static unsigned int temp_obj_num = 0 ; /* temporary objects counter */
@@ -279,6 +280,7 @@ static pgut_option options[] =
279280 { 'l' , 'i' , "index" , & r_index },
280281 { 'b' , 'x' , "only-indexes" , & only_indexes },
281282 { 'i' , 'T' , "wait-timeout" , & wait_timeout },
283+ { 'i' , 'm' , "max-lock-timeout" , & max_lock_timeout_msec },
282284 { 'B' , 'Z' , "no-analyze" , & analyze },
283285 { 'i' , 'j' , "jobs" , & jobs },
284286 { 'b' , 'D' , "no-kill-backend" , & no_kill_backend },
@@ -1767,6 +1769,7 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
17671769 char sql [1024 ];
17681770 PGresult * res ;
17691771 int wait_msec ;
1772+ int timeout_msec ;
17701773
17711774 if (start_xact )
17721775 pgut_command (conn , "BEGIN ISOLATION LEVEL READ COMMITTED" , 0 , NULL );
@@ -1815,7 +1818,8 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
18151818
18161819 /* wait for a while to lock the table. */
18171820 wait_msec = Min (1000 , i * 100 );
1818- snprintf (sql , lengthof (sql ), "SET LOCAL statement_timeout = %d" , wait_msec );
1821+ timeout_msec = Min (wait_msec , max_lock_timeout_msec )
1822+ snprintf (sql , lengthof (sql ), "SET LOCAL statement_timeout = %d" , timeout_msec );
18191823 pgut_command (conn , sql , 0 , NULL );
18201824
18211825 res = pgut_execute_elevel (conn , lock_query , 0 , NULL , DEBUG2 );
@@ -1832,6 +1836,8 @@ lock_exclusive(PGconn *conn, const char *relid, const char *lock_query, bool sta
18321836 pgut_rollback (conn );
18331837 else
18341838 pgut_command (conn , "ROLLBACK TO SAVEPOINT repack_sp1" , 0 , NULL );
1839+ if (timeout_msec < wait_msec )
1840+ usleep (1000 * (wait_msec - timeout_msec ));
18351841 continue ;
18361842 }
18371843 else
@@ -2232,6 +2238,7 @@ pgut_help(bool details)
22322238 printf (" -i, --index=INDEX move only the specified index\n" );
22332239 printf (" -x, --only-indexes move only indexes of the specified table\n" );
22342240 printf (" -T, --wait-timeout=SECS timeout to cancel other backends on conflict\n" );
2241+ printf (" -m, --max-lock-timeout=MS max millisecond timeout for a strong lock attempt\n" );
22352242 printf (" -D, --no-kill-backend don't kill other backends when timed out\n" );
22362243 printf (" -Z, --no-analyze don't analyze at end\n" );
22372244 printf (" -k, --no-superuser-check skip superuser checks in client\n" );
0 commit comments