diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c index 46fc60115a8..3779b43fa1a 100644 --- a/src/backend/access/gin/ginfast.c +++ b/src/backend/access/gin/ginfast.c @@ -895,8 +895,6 @@ ginInsertCleanup(GinState *ginstate, bool must_empty_list, */ processPendingPage(&accum, &datums, page, FirstOffsetNumber); - vacuum_delay_point(false); - /* * Is it time to flush memory to disk? Flush if we are at the end of * the pending list, or if we have a full row and memory is getting @@ -1002,10 +1000,12 @@ ginInsertCleanup(GinState *ginstate, bool must_empty_list, UnlockReleaseBuffer(buffer); } + /* call vacuum_delay_point while not holding any buffer lock */ + vacuum_delay_point(false); + /* * Read next page in pending list */ - vacuum_delay_point(false); buffer = ReadBuffer(index, blkno); LockBuffer(buffer, GIN_SHARE); page = BufferGetPage(buffer); diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index b2e34d2d45e..63846c10840 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -562,6 +562,9 @@ bucket_loop: Page page; bool split_cleanup = false; + /* call vacuum_delay_point while not holding any buffer lock */ + vacuum_delay_point(false); + /* Get address of bucket's start page */ bucket_blkno = BUCKET_TO_BLKNO(cachedmetap, cur_bucket); @@ -799,8 +802,6 @@ hashbucketcleanup(Relation rel, Bucket cur_bucket, Buffer bucket_buf, bool retain_pin = false; bool clear_dead_marking = false; - vacuum_delay_point(false); - page = BufferGetPage(buf); opaque = HashPageGetOpaque(page); diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index a08172d2314..e7f664e4f89 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -1340,8 +1340,6 @@ acquire_sample_rows(Relation onerel, int elevel, /* Outer loop over blocks to sample */ while (table_scan_analyze_next_block(scan, stream)) { - vacuum_delay_point(true); - while (table_scan_analyze_next_tuple(scan, &liverows, &deadrows, slot)) { /* @@ -1389,6 +1387,7 @@ acquire_sample_rows(Relation onerel, int elevel, pgstat_progress_update_param(PROGRESS_ANALYZE_BLOCKS_DONE, ++blksdone); + vacuum_delay_point(true); } read_stream_end(stream); diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c17aecce7ad..168e68d80e2 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -2439,6 +2439,14 @@ vacuum_delay_point(bool is_analyze) { double msec = 0; + /* + * If we're holding locks or holding interrupts for some other reason, + * don't sleep, because we don't want to hold locks any longer than + * necessary. + */ + if (!INTERRUPTS_CAN_BE_PROCESSED()) + return; + /* Always check for interrupts */ CHECK_FOR_INTERRUPTS();