Skip to content

Fix 'too many LWLocks taken' error when scanning hypertables#167

Merged
tjgreen42 merged 3 commits intorelease/0.4.1from
fix-scan-lwlock-0.4.1
Jan 23, 2026
Merged

Fix 'too many LWLocks taken' error when scanning hypertables#167
tjgreen42 merged 3 commits intorelease/0.4.1from
fix-scan-lwlock-0.4.1

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

@tjgreen42 tjgreen42 commented Jan 22, 2026

Summary

Fixes "too many LWLocks taken" error when querying BM25 indexes on hypertables with many chunks.

Problem

When scanning a hypertable with many chunks (e.g., 587), each chunk's BM25 index scan acquires a per-index LWLock but never releases it until transaction end, exceeding Postgres's ~200 lock limit.

Solution

Release the lock immediately after tp_memtable_search() returns, since we've already extracted all CTIDs into memory.

This is the scan-path equivalent of the build-path fix in b7f6539.

Testing

  • Tested with 587-chunk hypertable (2.2M rows) - queries now succeed

Release the per-index LWLock after tp_memtable_search() completes in
tp_execute_scoring_query(). The lock was being acquired but never
released, causing locks to accumulate when querying hypertables with
many chunks (e.g., 587 chunks). This is the scan-path equivalent of
the build-path fix in b7f6539.
The lock upgrade warning no longer occurs because we release the
per-index lock after tp_memtable_search() completes.
Copy link
Copy Markdown
Collaborator Author

@tjgreen42 tjgreen42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial change to trigger CI

Signed-off-by: Todd J. Green <tj@timescale.com>
@tjgreen42 tjgreen42 merged commit 3733948 into release/0.4.1 Jan 23, 2026
11 checks passed
@tjgreen42 tjgreen42 deleted the fix-scan-lwlock-0.4.1 branch January 23, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant