File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,6 +54,20 @@ async function checkAndVacuumToast(pool: Pool): Promise<void> {
5454 }
5555}
5656
57+ async function configureSessionTimeouts ( pool : Pool ) : Promise < void > {
58+ const client = await pool . connect ( )
59+ try {
60+ const dbName = process . env . DB_NAME || 'squid'
61+ await client . query ( `ALTER DATABASE "${ dbName } " SET idle_in_transaction_session_timeout = '2min'` )
62+ await client . query ( `ALTER DATABASE "${ dbName } " SET idle_session_timeout = '5min'` )
63+ console . log ( '[toast-vacuum] Configured database session timeouts (idle_in_transaction=2min, idle_session=5min)' )
64+ } catch ( err ) {
65+ console . error ( '[toast-vacuum] Error configuring session timeouts:' , err )
66+ } finally {
67+ client . release ( )
68+ }
69+ }
70+
5771export function startToastVacuumMonitor ( ) : void {
5872 const pool = new Pool ( {
5973 host : process . env . DB_HOST ,
@@ -67,8 +81,8 @@ export function startToastVacuumMonitor(): void {
6781 statement_timeout : 3600000 ,
6882 } )
6983
70- // Run immediately on launch
71- checkAndVacuumToast ( pool ) . then ( ( ) => {
84+ // Configure database-level session timeouts to prevent idle transactions from blocking VACUUM
85+ configureSessionTimeouts ( pool ) . then ( ( ) => checkAndVacuumToast ( pool ) ) . then ( ( ) => {
7286 // Then repeat every 30 minutes
7387 setInterval ( ( ) => {
7488 checkAndVacuumToast ( pool )
You can’t perform that action at this time.
0 commit comments