Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvmK4-0004NP-VJ for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2019 17:03:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gvmK3-0002pZ-QE for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2019 17:03:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvmK3-0002pS-HJ for pgsql-bugs@lists.postgresql.org; Mon, 18 Feb 2019 17:03:15 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvmK1-0006Qt-EG for pgsql-bugs@lists.postgresql.org; Mon, 18 Feb 2019 17:03:15 +0000 Received: by mail-lf1-x144.google.com with SMTP id v7so12840412lfd.2 for ; Mon, 18 Feb 2019 09:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=M7cI2YVa5xOmh2zYUxITVPJJxAcEgAXYOrOKbdwbQj4=; b=RAqr+JgXuD8mXcQpAtmmf4Axx+aomApTZEx/5CjRaBLFnebkHUmaf+10lW6xWoOXlw OkO55xX4+ZY4vo82ByKPyLBfIdcv7Q8Q4l7IZ0MgMBrtvWTmyWKCeRjBss1isN6CedkU JNaZWdOeNWqfA3fMB3lt4cVGS3eof+2k78EVoEMDzsRKcVv2BHmvzmj3pmrD+8LT5RRk rNbB3z1f/1bLr3/rpK9Y+j4Fvy4ljc2+k8Anz5e4D30TU2UGiNHoSxAqk7S3SlTddeGr sgN7hS60OHMnuRHY8kAqCOHBGDvBwUs5rEX9hFQjy/Z9o/MvikQ2sxeEO4lRezlhDKOa YaCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=M7cI2YVa5xOmh2zYUxITVPJJxAcEgAXYOrOKbdwbQj4=; b=KMRnl/GIvY05c3gWR1fsCeq3SjAgRmjebiB4cDHJPiNZGVcR62S+7Im2JHlFi8nZ0H yH1KnhREhdIWEHWrTe/WyBU9IT17u/y8wHJZ493E+kMbEUqbot5bnWzcVEZcDkYvocGX 5xjwV7zrtLtwT9MgwCWpGYxlsBzYMs2bqpAG5/31feyQs6mN6zlMhtpTTaPnOnU5aTsa VN1fFF9ht0KE8q/SrlAmX156KpwgwKhTul5xJpWOsHQWJmkT2nJS2fyaQ6qHI6eE3EhV 7mvfWzv4HrOJuXWmLC2kZN8sZsbqgqflZ8xTbL4pYYhqQfJxw7ZrR0hm1o2rpSP/R1YU 1rIA== X-Gm-Message-State: AHQUAuYBVMN7G2OAD31DoOqpVQzwZwQkdSecGI9R5owmoZNObsmLm5yW HSQYn2yFZjHO4M0mFVW2jANB4kDf X-Google-Smtp-Source: AHgI3IaAVonlQwuuUovKxcuv1pbLdyNmZuBm0SLhRMKmM+rWhr+r4Qmnc6LvKF8J9Ew+jId4n28VGA== X-Received: by 2002:a19:ab19:: with SMTP id u25mr14007246lfe.64.1550509392149; Mon, 18 Feb 2019 09:03:12 -0800 (PST) Received: from [192.168.27.213] ([93.174.131.141]) by smtp.gmail.com with ESMTPSA id y81-v6sm3766141lje.30.2019.02.18.09.03.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 09:03:11 -0800 (PST) Subject: Re: BUG #15638: pg_basebackup with --wal-method=stream incorrectly generates WAL segment created during backup To: Michael Paquier , apiwoni@webmd.net, pgsql-bugs@lists.postgresql.org References: <15638-426547bdd97938dd@postgresql.org> <20190216152503.GK2240@paquier.xyz> From: Maksim Milyutin Message-ID: Date: Mon, 18 Feb 2019 20:03:10 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190216152503.GK2240@paquier.xyz> Content-Type: multipart/alternative; boundary="------------FD60CDD52AA1E908B7257FF2" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------FD60CDD52AA1E908B7257FF2 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit On 2/16/19 6:25 PM, Michael Paquier wrote: > On Sat, Feb 16, 2019 at 12:26:13AM +0000, PG Bug reporting form wrote: >> When new slave is created by taking base backup from the primary using >> pg_basebackup with --wal-method=stream option the WAL file generated during >> the backup is different (as compared with diff or cmp command) than that on >> the master and in WAL archive directory. Furthermore, this file does not >> exist in pg_wal/archive_status with .done extension on new slave, though it >> exists in pg_wal directory, resulting in failed attempt to archive this file >> when slave node is promoted as master node. >> 2019-02-15 14:15:58.872 PST [5369] DETAIL: The failed archive command was: >> test ! -f /mnt/pgsql/archive/000000010000000000000002 && cp >> pg_wal/000000010000000000000002 >> /mnt/pgsql/archive/000000010000000000000002 > How do you promote your standby? In Postgres 10, the last, partial > WAL segment of a past timeline generated at promotion is renamed > .partial to avoid any conflicts, so as this should normally not > happen if you do not use archive_mode = always. This issue concerns only segment that contains wal records from pg_basebackup. For example, I have reproduced this issue on master branch getting the following content of archive directory after standby promoting: 000000010000000000000001.node1 000000010000000000000002.00000028.backup.node1 *000000010000000000000002.node1** **000000010000000000000002.node2* 000000010000000000000003.node1 000000010000000000000004.node1 *000000010000000000000005.partial.node2** **000000020000000000000005.node2* 00000002.history.node2 Each wal segment specifically was appended with . suffix to distinguish its source. Initially the node1 was master, node2 - standby. The segment 000000010000000000000002 has the following content: rmgr: Standby     len (rec/tot):     50/    50, tx: 0, lsn: 0/02000028, prev 0/015DB060, desc: RUNNING_XACTS nextXid 474 latestCompletedXid 473 oldestRunningXid 474 rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000060, prev 0/02000028, desc: CHECKPOINT_ONLINE redo 0/2000028; tli 1; prev tli 1; fpw true; xid 0:474; oid 12690; multi 1; offset 0; oldest xid 467 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 474; online rmgr: XLOG        len (rec/tot):     34/    34, tx:          0, lsn: 0/020000D0, prev 0/02000060, desc: BACKUP_END 0/2000028 rmgr: XLOG        len (rec/tot):     24/    24, tx:          0, lsn: 0/020000F8, prev 0/020000D0, desc: SWITCH On the current state of master branch the content of two segments are the same: $ md5sum 000000010000000000000002.node1 000000010000000000000002.node2 252e3e8cf3a85f218bb467005c565e3c 000000010000000000000002.node1 252e3e8cf3a85f218bb467005c565e3c 000000010000000000000002.node2 But on PG 10.6 the contents are differentiated on the tails: $ cmp 000000010000000000000002.node1 000000010000000000000002.node2 000000010000000000000002.node1 000000010000000000000002.node2 differ: byte *131073*, line 1 while logical part (prefix) are the same - the lsn of last record (SWITCH) in this segment is 0/02000130 and have length 24 bytes. Is it correct behavior? What would be the correct canonical representation of archive command taking into account this issue? -- Regards, Maksim Milyutin --------------FD60CDD52AA1E908B7257FF2 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit

On 2/16/19 6:25 PM, Michael Paquier wrote:

On Sat, Feb 16, 2019 at 12:26:13AM +0000, PG Bug reporting form wrote:
When new slave is created by taking base backup from the primary using
pg_basebackup with --wal-method=stream option the WAL file generated during
the backup is different (as compared with diff or cmp command) than that on
the master and in WAL archive directory. Furthermore, this file does not
exist in pg_wal/archive_status with .done extension on new slave, though it
exists in pg_wal directory, resulting in failed attempt to archive this file
when slave node is promoted as master node.
2019-02-15 14:15:58.872 PST [5369] DETAIL:  The failed archive command was:
test ! -f /mnt/pgsql/archive/000000010000000000000002 && cp
pg_wal/000000010000000000000002
/mnt/pgsql/archive/000000010000000000000002
How do you promote your standby?  In Postgres 10, the last, partial
WAL segment of a past timeline generated at promotion is renamed
.partial to avoid any conflicts, so as this should normally not
happen if you do not use archive_mode = always.


This issue concerns only segment that contains wal records from pg_basebackup. For example, I have reproduced this issue on master branch getting the following content of archive directory after standby promoting:

000000010000000000000001.node1
000000010000000000000002.00000028.backup.node1
000000010000000000000002.node1
000000010000000000000002.node2
000000010000000000000003.node1
000000010000000000000004.node1
000000010000000000000005.partial.node2
000000020000000000000005.node2
00000002.history.node2

Each wal segment specifically was appended with .<node> suffix to distinguish its source. Initially the node1 was master, node2 - standby. The segment 000000010000000000000002 has the following content:

rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000028, prev 0/015DB060, desc: RUNNING_XACTS nextXid 474 latestCompletedXid 473 oldestRunningXid 474
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000060, prev 0/02000028, desc: CHECKPOINT_ONLINE redo 0/2000028; tli 1; prev tli 1; fpw true; xid 0:474; oid 12690; multi 1; offset 0; oldest xid 467 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 474; online
rmgr: XLOG        len (rec/tot):     34/    34, tx:          0, lsn: 0/020000D0, prev 0/02000060, desc: BACKUP_END 0/2000028
rmgr: XLOG        len (rec/tot):     24/    24, tx:          0, lsn: 0/020000F8, prev 0/020000D0, desc: SWITCH


On the current state of master branch the content of two segments are the same:

$ md5sum 000000010000000000000002.node1 000000010000000000000002.node2

252e3e8cf3a85f218bb467005c565e3c  000000010000000000000002.node1
252e3e8cf3a85f218bb467005c565e3c  000000010000000000000002.node2

But on PG 10.6 the contents are differentiated on the tails:

$ cmp 000000010000000000000002.node1 000000010000000000000002.node2

000000010000000000000002.node1 000000010000000000000002.node2 differ: byte 131073, line 1

while logical part (prefix) are the same - the lsn of last record (SWITCH) in this segment is 0/02000130 and have length 24 bytes.


Is it correct behavior? What would be the correct canonical representation of archive command taking into account this issue?


-- 
Regards,
Maksim Milyutin
--------------FD60CDD52AA1E908B7257FF2--