Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKpCt-0000VW-7U for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jul 2016 15:57:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bKpCs-00062c-KW for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jul 2016 15:57:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bKpCs-00062V-16 for pgsql-bugs@postgresql.org; Wed, 06 Jul 2016 15:57:46 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bKpCp-00008b-2I for pgsql-bugs@postgresql.org; Wed, 06 Jul 2016 15:57:44 +0000 Received: by mail-wm0-x22d.google.com with SMTP id r201so198624208wme.1 for ; Wed, 06 Jul 2016 08:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant.it; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=f6iOPZOVSFfrZs1bEkbattK4qSpVSacL8DpQo1JFvFA=; b=CRmwcwONx09brVudLovORn9Bp0w1r4s+cZJDOXXZ60gzWPZxriKqiDkntFPz4aaWhA TwYps1gmcgnKFm8KjuzaacZCRcDB5Mj9QsCfck1p9ic1k+35i2+CGT5sb2Haw0/2+BOQ TCcePfW1T0IA62LJ4HN0IX9Ns+BnuZqUS8uLo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=f6iOPZOVSFfrZs1bEkbattK4qSpVSacL8DpQo1JFvFA=; b=WoRQjfgXCe3Q+78WNhUl482IYdZ65MAC6FoM7BXAVfP/D/o+VZzpohmAVSyuePR+im Uohz1c/Izg6omFZjTm+PXUOR4IDX2Oq8+4HiCLF3zs1z1IH9nwvTAtLke7NYZPBTplG0 SIP+NBFpzeM9X9AH2cxlYUAIduuYND/+UfA6YuI12+v2SMZIcF3yHuBSydLcpcgAIGzL n52oMrjNnfbnhN5HBHt8eWrE6NCDZQYM1+B8h1T+1cq+lLFz14K1/XhKH7iPem1GjhKT i8Tpy9iFrurYFw3ObABd0KPvrO6iYIdoQWc8CYCCo/dVtsty+LtRUo+Y6gn3AIB0Fldg wTiQ== X-Gm-Message-State: ALyK8tIPCiwtp8UaHWDVfQpPpOu1xtZ4KDqYFlrgW62CW49JbnGyCnOxf3pfFE5iTaxJhgjE X-Received: by 10.28.126.2 with SMTP id z2mr22670721wmc.73.1467820660658; Wed, 06 Jul 2016 08:57:40 -0700 (PDT) Received: from titanium.local (net-37-182-231-222.cust.vodafonedsl.it. [37.182.231.222]) by smtp.googlemail.com with ESMTPSA id mn2sm4576637wjc.35.2016.07.06.08.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 08:57:39 -0700 (PDT) Subject: Re: BUG #14230: Wrong timeline returned by pg_stop_backup on a standby To: francesco.canovai@2ndquadrant.it, pgsql-bugs@postgresql.org, PostgreSQL-development References: <20160706150739.1426.84965@wrigleys.postgresql.org> From: Marco Nenciarini Message-ID: Date: Wed, 6 Jul 2016 17:57:34 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="b6mq7SelugC3r7jfBPxPqRnbsCNidFosX" X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --b6mq7SelugC3r7jfBPxPqRnbsCNidFosX Content-Type: multipart/mixed; boundary="0cdOTn8o2FXf0B2V98me6S96w80jBIjSA" From: Marco Nenciarini To: francesco.canovai@2ndquadrant.it, pgsql-bugs@postgresql.org, PostgreSQL-development Message-ID: Subject: Re: [BUGS] BUG #14230: Wrong timeline returned by pg_stop_backup on a standby References: <20160706150739.1426.84965@wrigleys.postgresql.org> In-Reply-To: --0cdOTn8o2FXf0B2V98me6S96w80jBIjSA Content-Type: multipart/mixed; boundary="------------8895E19EEAB2247522BE7948" This is a multi-part message in MIME format. --------------8895E19EEAB2247522BE7948 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/07/16 17:41, Marco Nenciarini wrote: > On 06/07/16 17:37, Marco Nenciarini wrote: >> Hi, >> >> On 06/07/16 17:07, francesco.canovai@2ndquadrant.it wrote: >>> The following bug has been logged on the website: >>> >>> Bug reference: 14230 >>> Logged by: Francesco Canovai >>> Email address: francesco.canovai@2ndquadrant.it >>> PostgreSQL version: 9.6beta2 >>> Operating system: Linux >>> Description: =20 >>> >>> I'm taking a concurrent backup from a standby in PostgreSQL beta2 and= I get >>> the wrong timeline from pg_stop_backup(false). >>> >>> This is what I'm doing: >>> >>> 1) I set up an environment with a primary server and a replica in str= eaming >>> replication. >>> >>> 2) On the replica, I run >>> >>> postgres=3D# SELECT pg_start_backup('test_backup', true, false); >>> pg_start_backup=20 >>> ----------------- >>> 0/3000A00 >>> (1 row) >>> >>> 3) When I run pg_stop_backup, it returns a start wal location belongi= ng to a >>> file with timeline 0. >>> >>> postgres=3D# SELECT pg_stop_backup(false); >>> pg_stop_backup = =20 >>> >>> ---------------------------------------------------------------------= ------ >>> (0/3000AE0,"START WAL LOCATION: 0/3000A00 (file >>> 000000000000000000000003)+ >>> CHECKPOINT LOCATION: 0/3000A38 = =20 >>> + >>> BACKUP METHOD: streamed = =20 >>> + >>> BACKUP FROM: standby = =20 >>> + >>> START TIME: 2016-07-06 16:44:31 CEST = =20 >>> + >>> LABEL: test_backup = =20 >>> + >>> ","") >>> (1 row) >>> >>> The timeline returned is fine (is 1) when running the same commands o= n the >>> master. >>> >>> An incorrect backup label doesn't prevent PostgreSQL from starting up= , but >>> it affects the tools using that information. >>> >>> >> >> The issue here is that the do_pg_stop_backup function uses the >> ThisTimeLineID variable that is not valid on standbys. >> >> I think that it should read it from >> ControlFile->checkPointCopy.ThisTimeLineID as we do in do_pg_start_bac= kup. >> >=20 > No, that's not the solution. >=20 > The backup_label is generated during the do_pg_start_backup call, so > also the copy in ControlFile->checkPointCopy.ThisTimeLineID is > uninitialized. >=20 After further analysis, the issue is that we retrieve the starttli from the ControlFile structure, but it was using ThisTimeLineID when writing the backup label. I've attached a very simple patch that fixes it. Regards, Marco --=20 Marco Nenciarini - 2ndQuadrant Italy PostgreSQL Training, Services and Support marco.nenciarini@2ndQuadrant.it | www.2ndQuadrant.it --------------8895E19EEAB2247522BE7948 Content-Type: text/x-patch; name="timeline.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="timeline.patch" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/trans= am/xlog.c index e4645a3..aecede1 100644 *** a/src/backend/access/transam/xlog.c --- b/src/backend/access/transam/xlog.c *************** do_pg_start_backup(const char *backupids *** 9974,9980 **** } while (!gotUniqueStartpoint); =20 XLByteToSeg(startpoint, _logSegNo); ! XLogFileName(xlogfilename, ThisTimeLineID, _logSegNo); =20 /* * Construct tablespace_map file --- 9974,9980 ---- } while (!gotUniqueStartpoint); =20 XLByteToSeg(startpoint, _logSegNo); ! XLogFileName(xlogfilename, starttli, _logSegNo); =20 /* * Construct tablespace_map file --------------8895E19EEAB2247522BE7948-- --0cdOTn8o2FXf0B2V98me6S96w80jBIjSA-- --b6mq7SelugC3r7jfBPxPqRnbsCNidFosX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJXfSpyAAoJEFifA/AbpVA4JDcP/1tF88rp2PWUho1DVKXyc1IT yBZtC3LjKCdVs35sFTZu/bsEhjwk0czKY6HG+2CBJYSOyxt1vBwDHynu9CvSC+yk sfvBTukLBvxQMT6k4f6/+j7vu5MnkyLthRRHiHoT4AGRM9a5T0J0MhrkBf4yJrMC wyQK7NGBPqG58NX2QugP+9blUIAuFgAPo30+T2C3KZ3FYuuoGHGOkvRMm0gGJrP6 1h8sEjdPzpipRFuzL0HbRkjK/Jd+5tML5heDrwCaHVf09N9yvXQN35rjaOotaMhl ostFxy6utTGX53r5rtU6z/M3AGTAckSHvTf9meDcwWSa0dFd2chgF9Jt+qY3CRSj 0kkROFZJvcjNX1gnAihtMymuQPAmFJK3UVNIdY3KKnZMGnMc2As/b3pmehjWWBuI 5cEh6zpZpXJrnYA7AaY5A8DJx/mPB9AgZWSx1fQI0eC8RS8s+6kM+hTFM3JXs1kX GyvnOsC94utR9tWmPrC5zeBnWiqrvlKFJw/lEHH3WFpzNJZFQDNjIUgHSYo1wTEO 4wa4FHZ4pZMSMaGC/NgqfOxOuYbd4eD1VghPN3X3Lb0dxbIDVXwPGLMhxci1QdA7 KXnhtMLxYJK0OofUGWfe27B6He7d+jlFddUjXD5+HDmayTqnvNnmY/hEeQipfaMn yXajQUf3R5Ly8rLaSzEC =nIg4 -----END PGP SIGNATURE----- --b6mq7SelugC3r7jfBPxPqRnbsCNidFosX--