Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lrXsJ-0007JD-PS for pgsql-general@arkaria.postgresql.org; Fri, 11 Jun 2021 03:30:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lrXsI-0005bR-5x for pgsql-general@arkaria.postgresql.org; Fri, 11 Jun 2021 03:30:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lrXsH-0005bJ-Qg for pgsql-general@lists.postgresql.org; Fri, 11 Jun 2021 03:30:25 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lrXsC-0001FU-Er for pgsql-general@postgresql.org; Fri, 11 Jun 2021 03:30:23 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4G1R9P6T8pzZf48 for ; Fri, 11 Jun 2021 11:27:21 +0800 (CST) Received: from dggema724-chm.china.huawei.com (10.3.20.88) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Fri, 11 Jun 2021 11:30:13 +0800 Received: from dggema768-chm.china.huawei.com (10.1.198.210) by dggema724-chm.china.huawei.com (10.3.20.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 11 Jun 2021 11:30:12 +0800 Received: from dggema768-chm.china.huawei.com ([10.9.48.81]) by dggema768-chm.china.huawei.com ([10.9.48.81]) with mapi id 15.01.2176.012; Fri, 11 Jun 2021 11:30:12 +0800 From: "xiebin (F)" To: "pgsql-general@postgresql.org" CC: "zhubo (C)" , "Lijun (Lijun, Kunpeng Computing Solution)" , "wangxiaopeng (J)" , "Zhuzheng (IT)" , yinfan , "hw Dong(Dong)" , Sugang , Gongyanying , "guojin (E)" , "Guojianlong (Kunpeng)" , "Meihuajie (meihuajie, Intelligent Computing Solution Development Dep)" , Zhuyingjie , "yangshaobo (A)" Subject: Postgresql crashdown and recovery failure Thread-Topic: Postgresql crashdown and recovery failure Thread-Index: AddeaRlB2jRo7A7ZQl6xwCY2mJWQuQ== Date: Fri, 11 Jun 2021 03:30:12 +0000 Message-ID: <2715b5290b7548a8a98d14f720008793@huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.101.4] Content-Type: multipart/alternative; boundary="_000_2715b5290b7548a8a98d14f720008793huaweicom_" MIME-Version: 1.0 X-CFilter-Loop: Reflected List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_2715b5290b7548a8a98d14f720008793huaweicom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 f= ound that the content around latest checkpoint is empty. (about 1700 zero b= ytes) # 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/0989= 3908, 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, leadin= g to recovery failure. The remote storage support Posix IO, meaning the data would be written to d= isk 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 [pid 109705] <... openat resumed> ) =3D 3 [pid 109705] fsync(3 [pid 109705] <... fsync resumed> ) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_xact", O_RDONLY) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_commit_ts", O_RDONLY) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_subtrans/0000", O_RDWR|O_CREAT, 0600) =3D= 3 [pid 109705] openat(AT_FDCWD, "pg_multixact/offsets/0000", O_RDWR|O_CREAT, = 0600) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_multixact/offsets", O_RDONLY) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_multixact/members", O_RDONLY) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_logical/snapshots", O_RDONLY|O_NONBLOCK|O= _DIRECTORY|O_CLOEXEC) =3D 3 [pid 109705] openat(AT_FDCWD, "pg_logical/mappings", O_RDONLY|O_NONBLOCK|O_= DIRECTORY|O_CLOEXEC) =3D 3 [pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint.tmp", O_WRO= NLY|O_CREAT|O_EXCL, 0600) =3D 3 [pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint.tmp", O_RDW= R) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint", O_RDWR) = =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_logical/replorigin_checkpoint", O_RDWR) = =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_logical", O_RDONLY) =3D 3 [pid 109705] fsync(3) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_wal/00000001000000000000000B", O_RDWR [pid 109705] <... openat resumed> ) =3D 3 [pid 109705] fdatasync(3 (Let's say it is A) [pid 109705] <... fdatasync resumed> ) =3D 0 [pid 109705] openat(AT_FDCWD, "/tmp/data/global/pg_control", O_RDWR [pid 109705] <... openat resumed> ) =3D 4 [pid 109705] fsync(4 = (Let's say it is B) [pid 109705] <... fsync resumed> ) =3D 0 [pid 109705] openat(AT_FDCWD, "pg_wal", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_C= LOEXEC) =3D 4 [pid 109705] openat(AT_FDCWD, "pg_subtrans", O_RDONLY|O_NONBLOCK|O_DIRECTOR= Y|O_CLOEXEC) =3D 4 [pid 109707] fdatasync(3) =3D 0 = (Let's say it is C) ...