pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: xiebin (F) <xiebin18@huawei.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Cc: zhubo (C) <zhubo31@huawei.com>
Cc: Lijun (Lijun, Kunpeng Computing Solution) <lijun.lijun@huawei.com>
Cc: wangxiaopeng (J) <wangxiaopeng99@huawei.com>
Cc: Zhuzheng (IT) <zhuzheng@huawei.com>
Cc: yinfan <yinfan2@huawei.com>
Cc: hw Dong(Dong) <hw.dongdong@huawei.com>
Cc: Sugang <Tank.su@huawei.com>
Cc: Gongyanying <gongyanying@huawei.com>
Cc: guojin (E) <guojin9@huawei.com>
Cc: Guojianlong (Kunpeng) <jianlong.guo@huawei.com>
Cc: Meihuajie (meihuajie, Intelligent Computing Solution Development Dep) <meihuajie@huawei.com>
Cc: Zhuyingjie <zhuyingjie@huawei.com>
Cc: yangshaobo (A) <yangshaobo6@huawei.com>
Subject: Postgresql crashdown and recovery failure
Date: Fri, 11 Jun 2021 03:30:12 +0000
Message-ID: <2715b5290b7548a8a98d14f720008793@huawei.com> (raw)

Hi,

My database (Postgresql 12.5) server uses remote storage as data directory.

I powered off the database server and started postgresql (same version) on another server, with same data. However it failed. I checked wal logs and found that the content around latest checkpoint is empty. (about 1700 zero bytes)

# pg_controldata -D .
pg_control version number:            1201
Catalog version number:               201909212
Database system identifier:           6967594878781603854
Database cluster state:               in production
pg_control last modified:             Wed 09 Jun 2021 04:23:24 PM CST
Latest checkpoint location:           0/9893978
Latest checkpoint's REDO location:    0/9893940
Latest checkpoint's REDO WAL file:    000000010000000000000009
Latest checkpoint's TimeLineID:       1
...

# pg_waldump -p ./pg_wal/ -s 0/9893900
first record is after 0/9893900, at 0/9893908, skipping over 8 bytes
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/09893908, prev 0/098938E0, desc: RUNNING_XACTS nextXid 30176 latestCompletedXid 30175 oldestRunningXid 30176
pg_waldump: fatal: error in WAL record at 0/9893908: invalid record length at 0/9893940: wanted 24, got 0

# hexdump -C ./pg_wal/000000010000000000000009 -s 0x89393a -n 10000
0089393a  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00893ffa  00 00 00 00 00 00 01 d1  05 00 01 00 00 00 00 40  |...............@|
0089400a  89 07 00 00 00 00 4b 00  00 00 00 00 00 00 00 00  |......K.........|
...

It seems the checkpoint record in wal buffer is not flushed to disk, leading to recovery failure.

The remote storage support Posix IO, meaning the data would be written to disk as long as postgresql called fdatasync (or other similar system calls). Please notice the storage server has not been shut down.

Besides, I traced the system calls of postgresql checkpoint (triggered by "psql -c checkpoint").

# strace -fvy -s 64 pg_ctl -D /tmp/data start 2>&1 | grep -E 'open|sync'
...

[pid 109705] openat(AT_FDCWD, "pg_xact/0000", O_RDWR|O_CREAT, 0600 <unfinished ...>
[pid 109705] <... openat resumed> )     = 3</tmp/data/pg_xact/0000>
[pid 109705] fsync(3</tmp/data/pg_xact/0000> <unfinished ...>
[pid 109705] <... fsync resumed> )      = 0
[pid 109705] openat(AT_FDCWD, "pg_xact", O_RDONLY) = 3</tmp/data/pg_xact>
[pid 109705] fsync(3</tmp/data/pg_xact>) = 0
[pid 109705] openat(AT_FDCWD, "pg_commit_ts", O_RDONLY) = 3</tmp/data/pg_commit_ts>
[pid 109705] fsync(3</tmp/data/pg_commit_ts>) = 0
[pid 109705] openat(AT_FDCWD, "pg_subtrans/0000", O_RDWR|O_CREAT, 0600) = 3</tmp/data/pg_subtrans/0000>
[pid 109705] openat(AT_FDCWD, "pg_multixact/offsets/0000", O_RDWR|O_CREAT, 0600) = 3</tmp/data/pg_multixact/offsets/0000>
[pid 109705] fsync(3</tmp/data/pg_multixact/offsets/0000>) = 0
[pid 109705] openat(AT_FDCWD, "pg_multixact/offsets", O_RDONLY) = 3</tmp/data/pg_multixact/offsets>
[pid 109705] fsync(3</tmp/data/pg_multixact/offsets>) = 0
[pid 109705] openat(AT_FDCWD, "pg_multixact/members", O_RDONLY) = 3</tmp/data/pg_multixact/members>
[pid 109705] fsync(3</tmp/data/pg_multixact/members>) = 0
[pid 109705] openat(AT_FDCWD, "pg_logical/snapshots", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3</tmp/data/pg_logical/snapshots>
[pid 109705] openat(AT_FDCWD, "pg_logical/mappings", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3</tmp/data/pg_logical/mappings>
[pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint.tmp", O_WRONLY|O_CREAT|O_EXCL, 0600) = 3</tmp/data/pg_logical/replorigin_checkpoint.tmp>
[pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint.tmp", O_RDWR) = 3</tmp/data/pg_logical/replorigin_checkpoint.tmp>
[pid 109705] fsync(3</tmp/data/pg_logical/replorigin_checkpoint.tmp>) = 0
[pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint", O_RDWR) = 3</tmp/data/pg_logical/replorigin_checkpoint>
[pid 109705] fsync(3</tmp/data/pg_logical/replorigin_checkpoint>) = 0
[pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint", O_RDWR) = 3</tmp/data/pg_logical/replorigin_checkpoint>
[pid 109705] fsync(3</tmp/data/pg_logical/replorigin_checkpoint>) = 0
[pid 109705] openat(AT_FDCWD, "pg_logical", O_RDONLY) = 3</tmp/data/pg_logical>
[pid 109705] fsync(3</tmp/data/pg_logical>) = 0
[pid 109705] openat(AT_FDCWD, "pg_wal/00000001000000000000000B", O_RDWR <unfinished ...>
[pid 109705] <... openat resumed> )     = 3</tmp/data/pg_wal/00000001000000000000000B>
[pid 109705] fdatasync(3</tmp/data/pg_wal/00000001000000000000000B> <unfinished ...>          (Let's say it is A)
[pid 109705] <... fdatasync resumed> )  = 0
[pid 109705] openat(AT_FDCWD, "/tmp/data/global/pg_control", O_RDWR <unfinished ...>
[pid 109705] <... openat resumed> )     = 4</tmp/data/global/pg_control>
[pid 109705] fsync(4</tmp/data/global/pg_control> <unfinished ...>                               (Let's say it is B)
[pid 109705] <... fsync resumed> )      = 0
[pid 109705] openat(AT_FDCWD, "pg_wal", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4</tmp/data/pg_wal>
[pid 109705] openat(AT_FDCWD, "pg_subtrans", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4</tmp/data/pg_subtrans>
[pid 109707] fdatasync(3</tmp/data/pg_wal/00000001000000000000000B>) = 0                        (Let's say it is C)

...

view thread (3+ messages)  latest in thread

Message-ID: <2715b5290b7548a8a98d14f720008793@huawei.com>
Permalink:  ../2715b5290b7548a8a98d14f720008793@huawei.com/
Also on:    postgresql.org/message-id/2715b5290b7548a8a98d14f720008793@huawei.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: xiebin18@huawei.com, zhubo31@huawei.com, lijun.lijun@huawei.com, wangxiaopeng99@huawei.com, zhuzheng@huawei.com, yinfan2@huawei.com, hw.dongdong@huawei.com, Tank.su@huawei.com, gongyanying@huawei.com, guojin9@huawei.com, jianlong.guo@huawei.com, meihuajie@huawei.com, zhuyingjie@huawei.com, yangshaobo6@huawei.com
  Subject: Re: Postgresql crashdown and recovery failure
  In-Reply-To: <2715b5290b7548a8a98d14f720008793@huawei.com>
  References: <2715b5290b7548a8a98d14f720008793@huawei.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox