| outline |
|
||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| title | BUFFER_ROWS Annotation | ||||||||||||||||||||||||||||
| titleTemplate | NpgsqlRest | ||||||||||||||||||||||||||||
| description | Configure row buffering for PostgreSQL REST API responses. Control memory usage and streaming behavior for large result sets. | ||||||||||||||||||||||||||||
| head |
|
::: info Also known as
buffer (with or without @ prefix)
:::
Set the number of rows to buffer in the string builder before sending the response.
@buffer_rows <count>
@buffer <count>
Or using custom parameter syntax:
@buffer_rows = <count>
@buffer = <count>
The default value is 25 rows.
| Value | Behavior |
|---|---|
0 |
Disable buffering - write response for each row |
1 |
Buffer the entire array (all rows) |
25 |
Default - buffer 25 rows before writing |
> 1 |
Buffer specified number of rows before writing |
Write each row immediately to the response stream:
comment on function stream_live_data() is
'HTTP GET
@buffer_rows 0';Wait for all rows before sending response:
comment on function get_small_dataset() is
'HTTP GET
@buffer 1';comment on function export_all_data() is
'HTTP GET
@buffer_rows 5000';comment on function stream_data() is
'HTTP GET
@buffer 100';- Controls how many rows are buffered in the string builder before writing to the response stream.
- Applies to rows in JSON object arrays when returning records from the database.
- Buffering is more efficient than writing to the response stream for each row.
- Disabling buffering (
0) can have a slight negative impact on performance. - Higher values can have a negative impact on memory usage, especially with large datasets.
- Low values (0-10): Lower memory usage, more response stream writes, slight performance overhead.
- Default (25): Balanced trade-off between memory and performance.
- High values (1000+): Better throughput, higher memory usage per request.
- Value of 1: Entire result buffered before sending - best for small datasets where you want atomic responses.
- NpgsqlRest Options configuration - Configure default buffer size
- Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration works
- COMMAND_TIMEOUT - Set query timeout
- RAW - Return raw text output