I have the following simple Postgres stored procedure created that just sleeps a number of minutes as passed in to call:
create procedure sleep_test(delay_minutes numeric)
language plpgsql
as
$$
BEGIN
RAISE NOTICE 'Starting procedure. Sleeping for % minutes...', delay_minutes;
PERFORM pg_sleep(delay_minutes * 60); -- Function call is in seconds
RAISE NOTICE 'Finished sleeping.';
END;
$$;
Running the procedure for four minutes:
call sleep_test(4)
If I run the the procedure for four minutes in a worksheet, all works fine. The procedure runs (has state=='active' in pg_stat_activity) for 4 minutes and returns back to the calling worksheet:
Running the procedure for five minutes:
call sleep_test(5)
If I run it for 5 minutes or more, though, the process runs for 5 minutes (has state=='active' in pg_stat_activity), but after five minutes it goes into an "idle" state in pg_stat_activity and does not return back to the calling worksheet. From the worksheet's perspective it thinks the procedure is still running (indefinitely).
DB Settings (in case they are useful):
server_version == 12.22
statement_timeout == 0
idle_in_transaction_session_timeout==1d
Clients used to test - same issue with both:
Datagrip 2025.1 Query Console
Python 3.9 script using psycopg2 2.9.9
Database server config:
It is an AWS Postgres RDS database. Sorry... I am not familiar with where to exactly find OS and version in AWS.