pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Don't sleep with vacuum_delay_point() while holding locks 7+ messages / 1 participants [nested] [flat]
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/96c99955b62994b2cb47380d84f463456cf16ee5 Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/analyze.c | 3 +-- src/backend/commands/vacuum.c | 8 ++++++++ src/backend/utils/activity/pgstat.c | 2 -- 5 files changed, 15 insertions(+), 9 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e7d7e047b228e9f4d61e4a3db0fe6fca21b12554 Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/analyze.c | 3 +-- src/backend/commands/vacuum.c | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5f671c4312bb5addac4de4f329907a4681e81276 Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/analyze.c | 3 +-- src/backend/commands/vacuum.c | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/71d1ace33c77914bcf0ee591f8fc57fd186cb18a Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/analyze.c | 3 +-- src/backend/commands/vacuum.c | 8 ++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/226e86cdad0cddebdba06c7749958ca53fab27dd Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/vacuum.c | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d405460329924d94281481f78543d99068526c9a Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/vacuum.c | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Don't sleep with vacuum_delay_point() while holding locks @ 2026-10-05 10:18 Heikki Linnakangas <heikki.linnakangas@iki.fi> 0 siblings, 0 replies; 7+ messages in thread From: Heikki Linnakangas @ 2026-10-05 10:18 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't sleep with vacuum_delay_point() while holding locks It's a bad idea to sleep while holding locks, because you might block another process that wants to acquire the same lock. Furthermore, it's not safe to call ProcessConfigFile() in a critical section or while holding locks. So avoid calling vacuum_delay_point() while holding locks, and also make vacuum_delay_point() return quickly without sleeping if it's called while interrupts cannot be processed. To find the vacuum_delay_point() calls that were made while holding locks, I added "Assert(INTERRUPTS_CAN_BE_PROCESSED())" in vacuum_delay_point() and ran the regression tests. I didn't include that Assert in this commit, because there might be more places that do that that are not covered by the regression tests, including extensions. In ginInsertCleanup(), there was already another vacuum_delay_point() call later in the loop, while not holding any locks, so just remove the other call that was made while holding the lock. In hashbucketcleanup(), move the vacuum_delay_point() call up the stack to its caller. The call in hashbucketcleanup() was not able to handle interrupts because it held a lock, and because there were no vacuum_delay_point() or CHECK_FOR_INTERRUPTS() calls in the caller's loop, the whole hash index vacuuming phase was uninterruptible by pending shutdown or query cancel. Now it can be interrupted between buckets. Unfortunately, hashbucketcleanup() has to process all the bucket's pages in one go without pausing; fixing that would require changing how hashbucketcleanup()'s lock chaining works. In acquire_sample_rows(), move the vacuum_delay_point() call in the loop to between pages, to a time where we're not holding the buffer lock. In master, also remove a misleading CHECK_FOR_INTERRUPTS() call from pgstat_write_statsfile(). It was a no-op because we're always holding a lock on the current dshash partition at that point. A call that does nothing is harmless, but it makes you think that the loop is interruptible when in reality it's not. Author: Kevin Rocker <me@kevinrocker.com> Author: Andrey Borodin <amborodin@acm.org> Author: Mostafa <mostafa.nabil.nafie@gmail.com> Reported-by: Greg Burd <greg@burd.me> Reported-by: Sergei Kornilov <sk@zsrv.org> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Neil Chen <carpenter.nail.cz@gmail.com> Tested-by: Greg Burd <greg@burd.me> Discussion: https://postgr.es/m/19628-c2b17d358181a1ea@postgresql.org Discussion: https://postgr.es/m/492c6247-43d3-477b-8981-fb0c56767b38%40app.fastmail.com Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4a7778ef8751c3307584ca2a30d7e3f0fb3b3662 Modified Files -------------- src/backend/access/gin/ginfast.c | 6 +++--- src/backend/access/hash/hash.c | 5 +++-- src/backend/commands/vacuum.c | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-10-05 10:18 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi> 2026-10-05 10:18 pgsql: Don't sleep with vacuum_delay_point() while holding locks Heikki Linnakangas <heikki.linnakangas@iki.fi>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox