BUG #19894: CREATE DATABASE logs all-zeros visibility map

Поиск
Список
Период
Сортировка
Искать

BUG #19894: CREATE DATABASE logs all-zeros visibility map

От:
PG Bug reporting form <noreply@postgresql.org>
Дата:
The following bug has been logged on the website:

Bug reference:      19894
Logged by:          Sergey Shinderuk
Email address:      s.shinderuk@postgrespro.ru
PostgreSQL version: 17.11
Operating system:   Ubuntu 24.04
Description:        

Hello,

after CREATE DATABASE on a primary
select * from pg_visibility_map('pg_class')
 blkno | all_visible | all_frozen
-------+-------------+------------
     0 | t           | t
     1 | t           | t
     2 | t           | t
     3 | t           | t
     4 | t           | t
     5 | t           | t
     6 | t           | t
     7 | t           | t
     8 | t           | t
     9 | t           | t
    10 | t           | t
    11 | t           | t
    12 | t           | t
    13 | t           | t
(14 rows)

but on a standby:
 blkno | all_visible | all_frozen
-------+-------------+------------
     0 | f           | f
     1 | f           | f
     2 | f           | f
     3 | f           | f
     4 | f           | f
     5 | f           | f
     6 | f           | f
     7 | f           | f
     8 | f           | f
     9 | f           | f
    10 | f           | f
    11 | f           | f
    12 | f           | f
    13 | f           | f
(14 rows)

In the WAL:
rmgr: Storage     len (rec/tot):     42/    42, tx:        738, lsn:
0/018177E0, prev 0/01817790, desc: CREATE base/16384/1259_vm
rmgr: XLOG        len (rec/tot):     49/    73, tx:        738, lsn:
0/01817810, prev 0/018177E0, desc: FPI
        blkref #0: rel 1663/16384/1259 fork vm blk 0 (FPW); hole: offset:
24, length: 8168

VM FPI is just a page header, all the rest is a hole.

I think this fixes the bug:
----------------------------------------
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -4834,7 +4834,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator
srclocator,
 
         /* WAL-log the copied page. */
         if (use_wal)
-            log_newpage_buffer(dstBuf, true);
+            log_newpage_buffer(dstBuf, forkNum != VISIBILITYMAP_FORKNUM);
 
         END_CRIT_SECTION();
 
----------------------------------------

With this patch:
rmgr: Storage     len (rec/tot):     42/    42, tx:        738, lsn:
0/018257E0, prev 0/01825790, desc: CREATE base/16384/1259_vm
rmgr: XLOG        len (rec/tot):     49/  8241, tx:        738, lsn:
0/01825810, prev 0/018257E0, desc: FPI
        blkref #0: rel 1663/16384/1259 fork vm blk 0 (FPW); hole: offset: 0,
length: 0

I was comparing pgdata contents on a primary and a standby after
027_stream_regress and noticed that visibility maps strangely don't match.

Repo script:
----------------------------------------
#!/bin/sh

rm -rf primary standby
rm -f initdb.log primary.log standby.log

initdb -D primary > initdb.log

cp -a primary standby
touch standby/standby.signal
cat > standby/postgresql.auto.conf <

Re: BUG #19894: CREATE DATABASE logs all-zeros visibility map

От:
Christophe Pettus <xof@thebuild.com>
Дата:


> after CREATE DATABASE on a primary
> select * from pg_visibility_map('pg_class')
> blkno | all_visible | all_frozen
> -------+-------------+------------
>     0 | t           | t
>     1 | t           | t
>     2 | t           | t
>     3 | t           | t
>     4 | t           | t
>     5 | t           | t
>     6 | t           | t
>     7 | t           | t
>     8 | t           | t
>     9 | t           | t
>    10 | t           | t
>    11 | t           | t
>    12 | t           | t
>    13 | t           | t
> (14 rows)
> 
> but on a standby:
> blkno | all_visible | all_frozen
> -------+-------------+------------
>     0 | f           | f
>     1 | f           | f
>     2 | f           | f
>     3 | f           | f
>     4 | f           | f
>     5 | f           | f
>     6 | f           | f
>     7 | f           | f
>     8 | f           | f
>     9 | f           | f
>    10 | f           | f
>    11 | f           | f
>    12 | f           | f
>    13 | f           | f
> (14 rows)


Why is this a bug?


Re: BUG #19894: CREATE DATABASE logs all-zeros visibility map

От:
Сергей Шиндерук <s.shinderuk@postgrespro.ru>
Дата:

> 12 нояб. 2026 г., в 20:40, Christophe Pettus  написал(а):
> 
>> after CREATE DATABASE on a primary
>> select * from pg_visibility_map('pg_class')
>> blkno | all_visible | all_frozen
>> -------+-------------+------------
>>    0 | t           | t
>>    1 | t           | t
>>    2 | t           | t
>>    3 | t           | t
>>    4 | t           | t
>>    5 | t           | t
>>    6 | t           | t
>>    7 | t           | t
>>    8 | t           | t
>>    9 | t           | t
>>   10 | t           | t
>>   11 | t           | t
>>   12 | t           | t
>>   13 | t           | t
>> (14 rows)
>> 
>> but on a standby:
>> blkno | all_visible | all_frozen
>> -------+-------------+------------
>>    0 | f           | f
>>    1 | f           | f
>>    2 | f           | f
>>    3 | f           | f
>>    4 | f           | f
>>    5 | f           | f
>>    6 | f           | f
>>    7 | f           | f
>>    8 | f           | f
>>    9 | f           | f
>>   10 | f           | f
>>   11 | f           | f
>>   12 | f           | f
>>   13 | f           | f
>> (14 rows)
> 
> 
> Why is this a bug?


I'm sorry for bothering you. It's already discussed here:
https://www.postgresql.org/message-id/tencent_2E870046716FD94285045E96505A2D4E2908@qq.com
and here, causing data corruption:
https://www.postgresql.org/message-id/CAAKRu_bK7oJvtrrzL_V-OHouCWDKyU2-ERv+QvV6XM9Wh2dpUg@mail.gmail.com

I should have searched hackers before submitting a bug :(



FAQ