Skip to content

Limit batch_max to queue_capacity - #124

Merged
serprex merged 1 commit into
mainfrom
limit-batch-reserve
Aug 30, 2026
Merged

Limit batch_max to queue_capacity#124
serprex merged 1 commit into
mainfrom
limit-batch-reserve

Conversation

@serprex

@serprex serprex commented Aug 30, 2026

Copy link
Copy Markdown
Member

This avoids wasting memory when reserving vector

Also update docs with new defaults

@serprex
serprex requested review from JoshDreamland and amogiska and a lite review from Copilot August 30, 2026 03:31
@mintlify

mintlify Bot commented Aug 30, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
pg_stat_ch 🟢 Ready View Preview Aug 30, 2026, 3:31 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens the bgworker export batching logic by clamping pg_stat_ch.batch_max to the shared-memory queue’s capacity, and reduces unnecessary memory reservation when building the dequeue vector. It also updates defaults and documentation to match the new behavior.

Changes:

  • Add PschEffectiveBatchMax() (batch_max clamped to queue capacity) and use it in the bgworker drain loop and exporter.
  • Add PschQueueDepth() and use it as a sizing hint to avoid reserving an oversized std::vector when the queue is mostly empty.
  • Update GUC defaults and documentation (README + reference docs) for new defaults and clamping behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/worker/bgworker.c Uses effective (clamped) batch max in the drain-loop “partial batch” termination check.
src/queue/shmem.h Exposes new queue sizing/clamping helpers.
src/queue/shmem.c Implements PschQueueDepth() and PschEffectiveBatchMax().
src/export/stats_exporter.cc Reserves dequeue vector based on current queue depth; uses clamped batch max for export.
src/config/guc.c Updates pg_stat_ch.batch_max default and documents clamping in the GUC description.
README.md Updates documented defaults for queue capacity, flush interval, and batch max.
docs/reference/troubleshooting.mdx Updates tuning guidance to reflect batch_max clamping.
docs/reference/configuration.mdx Updates queue sizing/memory guidance and documents batch_max clamping behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/queue/shmem.c
Comment thread docs/reference/configuration.mdx Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 896228d. Configure here.

Comment thread src/worker/bgworker.c
This avoids wasting memory when reserving vector

Also update docs with new defaults
@serprex
serprex force-pushed the limit-batch-reserve branch from 9267079 to fa6400f Compare August 30, 2026 03:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/export/stats_exporter.cc

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@JoshDreamland JoshDreamland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@serprex
serprex merged commit 04fc3b0 into main Aug 30, 2026
14 checks passed
@serprex
serprex deleted the limit-batch-reserve branch August 30, 2026 05:32
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.

3 participants