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

Started by PG Bug reporting form17 days ago4 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1PG 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 <<EOF
port = 5433
primary_conninfo = 'port=5432'
EOF

pg_ctl -D primary -l primary.log start
pg_ctl -D standby -l standby.log start

createdb demo
psql -d demo -c "create extension pg_visibility"
psql -d demo -c "select * from pg_visibility_map('pg_class')"
sleep 1
psql -p 5433 -d demo -c "select * from pg_visibility_map('pg_class')"

pg_ctl -D primary stop
pg_ctl -D standby stop
----------------------------------------

Best regards,
Sergey

#2Sergey Shinderuk
s.shinderuk@postgrespro.ru
In reply to: PG Bug reporting form (#1)
Re: BUG #19894: CREATE DATABASE logs all-zeros visibility map

12 нояб. 2026 г., в 03:49, 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)

Sorry, looks like it's a known issue:
/messages/by-id/CAAKRu_bK7oJvtrrzL_V-OHouCWDKyU2-ERv+QvV6XM9Wh2dpUg@mail.gmail.com
/messages/by-id/CAAKRu_aaP=0GZe+D721byOM9Vwjtu94VdAE_em0PNC0r3EK2zg@mail.gmail.com

Didn't follow the discussion yet.

#3Christophe Pettus
xof@thebuild.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19894: CREATE DATABASE logs all-zeros visibility map

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?

#4Sergey Shinderuk
s.shinderuk@postgrespro.ru
In reply to: Christophe Pettus (#3)
Re: BUG #19894: CREATE DATABASE logs all-zeros visibility map

12 нояб. 2026 г., в 20:40, 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?

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

I should have searched hackers before submitting a bug :(