diff options
author | Thomas Munro <tmunro@postgresql.org> | 2019-04-02 09:08:15 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2019-04-02 09:29:49 +1300 |
commit | 4fd05bb55b40a3c9dde2b19942f275fc31b5225a (patch) | |
tree | e8700cb27e39c63b4cb1f35da1434cfca722bb3d | |
parent | 12d46ac392d00fa0d103f445aa4997f97029e007 (diff) | |
download | postgresql-4fd05bb55b40a3c9dde2b19942f275fc31b5225a.tar.gz postgresql-4fd05bb55b40a3c9dde2b19942f275fc31b5225a.zip |
Fix deadlock in heap_compute_xid_horizon_for_tuples().
We can't call code that uses syscache while we hold buffer locks
on a catalog relation. If passed such a relation, just fall back
to the general effective_io_concurrency GUC rather than trying to
look up the containing tablespace's IO concurrency setting.
We might find a better way to control prefetching in follow-up
work, but for now this is enough to avoid the deadlock introduced
by commit 558a9165e0.
Reviewed-by: Andres Freund
Diagnosed-by: Peter Geoghegan
Discussion: https://postgr.es/m/CA%2BhUKGLCwPF0S4Mk7S8qw%2BDK0Bq65LueN9rofAA3HHSYikW-Zw%40mail.gmail.com
Discussion: https://postgr.es/m/962831d8-c18d-180d-75fb-8b842e3a2742%40chrullrich.net
-rw-r--r-- | src/backend/access/heap/heapam.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index de5bb9194e3..05ceb6550d5 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -6976,8 +6976,15 @@ heap_compute_xid_horizon_for_tuples(Relation rel, * more prefetching in this case, too. It may be that this formula is too * simplistic, but at the moment there is no evidence of that or any idea * about what would work better. + * + * Since the caller holds a buffer lock somewhere in rel, we'd better make + * sure that isn't a catalog relation before we call code that does + * syscache lookups, to avoid risk of deadlock. */ - io_concurrency = get_tablespace_io_concurrency(rel->rd_rel->reltablespace); + if (IsCatalogRelation(rel)) + io_concurrency = effective_io_concurrency; + else + io_concurrency = get_tablespace_io_concurrency(rel->rd_rel->reltablespace); prefetch_distance = Min((io_concurrency) + 10, MAX_IO_CONCURRENCY); /* Start prefetching. */ |