You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've noticed for quite a while that server sometimes does not sends us WAL segment eagerly - it just idles and sends status report request to keep the connection open, even when it has more segments not yet streamed to us.
We'll try to force server to do CHECKPOINT, so that all the records on WAL get applied to disk, and see if that triggers streaming.
Would influencing wal_writer_delay have an impact on this? i've been reading on some material but most of these come from configuring the database itself and would have tradeoffs.
Would influencing wal_writer_delay have an impact on this? i've been reading on some material but most of these come from configuring the database itself and would have tradeoffs.
That sounds like a direction to investigate. If nothing else we can probably identify the cause of the issue. But judging from the description I kinda doubt if this is the reason. The default value is merely 200ms, which is quite negligible. The problem is that the issue is a little bit hard to steadily recreate. We probably need more logging on this issue as well, like the LSN difference between server and us whenever the server sends a keep alive message.
We currently have no steady way to recreate the issue. But it's very likely to show up during pgbench. To somehow recreate the issue, you can do
createdb -E UTF8 -O myuser test
pgbench -i -s 5 -U myuser test
pgbench -M prepared -T 15 -U myuser test
Rerun pgbench multiple times and you'll see a case like the following:
WAL streamer stops receiving stream data at LSN 2/2D1D4F0 (the segment is 000000010000000200000002.partial), which is also what SELECT pg_current_wal_flush_lsn () or SELECT pg_current_wal_lsn () returns. However, there are more log segment files on the serverside to come: from 000000010000000200000003 to 000000010000000200000006. This situation doesn't improve with CHECKPOINT command, it merely advances the current WAL lsn to 2/2D1D738.
At first we suspect that those segments are pre-generated or reused old segments by the server for furture records, given that the amount of records generated were significant. But upon parsing the contents, those segments actually seems to have meanings. For example, parsing 000000010000000200000003 with our pgmoneta-walinfo gives:
But comparing with result generated by pg_waldump, we found that this content is actually invalid. Doing pg_waldump data/pg_wal/000000010000000200000003 data/pg_wal/000000010000000200000003 gives
pg_waldump: error: could not find a valid record after 2/3000000
In fact, even 00000010000000200000002 is incomplete at server side:
$ pg_waldump data/pg_wal/000000010000000200000002 data/pg_wal/000000010000000200000002
...
pg_waldump: error: error in WAL record at 2/2D1D9F8: invalid record length at 2/2D1DA70: expected at least 24, got 0
With the above analysis I think it's safe to conclude that the server isn't actually streaming WAL to us lazily, the extra WAL segments don't actually contain any real contents, and may just be reused or pregenerated segments. The content generated by our walinfo tool, however, remains a mystery, why does server generate seemingly meaningful records beforehand instead of simply padding 0? Or are they old records that didn't get overwritten?
Activity
jesperpedersen commentedon Apr 9, 2024
We only require a
REPLICATIONuser so we don't have access to executing theCHECKPOINTcommandjesperpedersen commentedon Apr 9, 2024
For PostgreSQL 15+ we could add the
pg_checkpointrole, and update our requirements forpg_hba.confto allow non-replication based login.So, it has to be an optional operation
jesperpedersen commentedon Apr 9, 2024
Unless we can come up with something else
Jubilee101 commentedon Apr 9, 2024
..That doesn't seem ideal. I'll think about it.
bassamadnan commentedon Apr 26, 2025
Would influencing wal_writer_delay have an impact on this? i've been reading on some material but most of these come from configuring the database itself and would have tradeoffs.
Jubilee101 commentedon Apr 27, 2025
That sounds like a direction to investigate. If nothing else we can probably identify the cause of the issue. But judging from the description I kinda doubt if this is the reason. The default value is merely 200ms, which is quite negligible. The problem is that the issue is a little bit hard to steadily recreate. We probably need more logging on this issue as well, like the LSN difference between server and us whenever the server sends a keep alive message.
bassamadnan commentedon Apr 28, 2025
That is very true -- i've been wanting to ask how was this detected in the first place? Seems like a very interesting problem
Jubilee101 commentedon Jul 19, 2025
Updates
We currently have no steady way to recreate the issue. But it's very likely to show up during pgbench. To somehow recreate the issue, you can do
Rerun pgbench multiple times and you'll see a case like the following:
WAL streamer stops receiving stream data at LSN
2/2D1D4F0(the segment is000000010000000200000002.partial), which is also whatSELECT pg_current_wal_flush_lsn ()orSELECT pg_current_wal_lsn ()returns. However, there are more log segment files on the serverside to come: from000000010000000200000003to000000010000000200000006. This situation doesn't improve withCHECKPOINTcommand, it merely advances the current WAL lsn to2/2D1D738.At first we suspect that those segments are pre-generated or reused old segments by the server for furture records, given that the amount of records generated were significant. But upon parsing the contents, those segments actually seems to have meanings. For example, parsing
000000010000000200000003with our pgmoneta-walinfo gives:But comparing with result generated by pg_waldump, we found that this content is actually invalid. Doing
pg_waldump data/pg_wal/000000010000000200000003 data/pg_wal/000000010000000200000003givesIn fact, even
00000010000000200000002is incomplete at server side:With the above analysis I think it's safe to conclude that the server isn't actually streaming WAL to us lazily, the extra WAL segments don't actually contain any real contents, and may just be reused or pregenerated segments. The content generated by our walinfo tool, however, remains a mystery, why does server generate seemingly meaningful records beforehand instead of simply padding 0? Or are they old records that didn't get overwritten?