Avoid building stderr message if possible
Hi hackers,
Now we always build a message formatted for stderr in send_message_to_server_log()
even if it's useless in some case, e.g., log_destination = 'csvlog'. Attach a patch to
avoid building it if possible.
Test
====
I test it with a large sql (32MB) with guc:
```
log_destination = 'csvlog'
logging_collector = on
log_min_duration_statement = 0
```
master:
```
pgbench (20devel)
transaction type: large.sql
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 205
number of failed transactions: 0 (0.000%)
latency average = 293.219 ms
initial connection time = 0.767 ms
tps = 3.410415 (without initial connection time)
```
patched:
```
pgbench (20devel)
transaction type: large.sql
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 229
number of failed transactions: 0 (0.000%)
latency average = 263.087 ms
initial connection time = 1.068 ms
tps = 3.801022 (without initial connection time)
```
Thoughts?
--
Regards,
ChangAo Chen
Attachments:
v1-0001-Avoid-building-stderr-message-if-possible.patchapplication/octet-stream; charset=utf-8; name=v1-0001-Avoid-building-stderr-message-if-possible.patchDownload+82-49
On Aug 2, 2026, at 23:51, cca5507 <cca5507@qq.com> wrote:
Hi hackers,
Now we always build a message formatted for stderr in send_message_to_server_log()
even if it's useless in some case, e.g., log_destination = 'csvlog'. Attach a patch to
avoid building it if possible.Test
====
I test it with a large sql (32MB) with guc:
```
log_destination = 'csvlog'
logging_collector = on
log_min_duration_statement = 0
```master:
```
pgbench (20devel)
transaction type: large.sql
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 205
number of failed transactions: 0 (0.000%)
latency average = 293.219 ms
initial connection time = 0.767 ms
tps = 3.410415 (without initial connection time)
```patched:
```
pgbench (20devel)
transaction type: large.sql
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
duration: 60 s
number of transactions actually processed: 229
number of failed transactions: 0 (0.000%)
latency average = 263.087 ms
initial connection time = 1.068 ms
tps = 3.801022 (without initial connection time)
```Thoughts?
--
Regards,
ChangAo Chen
<v1-0001-Avoid-building-stderr-message-if-possible.patch>
Hi ChangAo,
I just reviewed this patch. I think the idea is good, it builds the string buffer only when needed.
I’m not sure why you use “stderr” in the new function name build_stderr_message() and the variable name has_stderr_message, as the buffer is also consumed by syslog and eventlog. Maybe build_log_buffer() and buf_built?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/