Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1epdTv-0000FE-NI for pgsql-performance@arkaria.postgresql.org; Sat, 24 Feb 2018 17:19:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epdTu-000095-Lj for pgsql-performance@arkaria.postgresql.org; Sat, 24 Feb 2018 17:19:30 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1epdTu-00008o-2f for pgsql-performance@lists.postgresql.org; Sat, 24 Feb 2018 17:19:30 +0000 Received: from mail-bn3nam01on0060.outbound.protection.outlook.com ([104.47.33.60] helo=NAM01-BN3-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1epdTq-0003ro-AA for pgsql-performance@lists.postgresql.org; Sat, 24 Feb 2018 17:19:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NETORG2528281.onmicrosoft.com; s=selector1-laurenthasson-com01i; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qUVqwTzNxkaecnqHoZtX/pyPY9BxVRNFUMt+bfyBvC8=; b=pWV511FnNNYWEFz7rPEdi7hbFvcjTwHH9aq2x3/YQQaJzkur+mt63FiLkeES9UtZCcTUhK/yo6kWAZPtrM9w8I1TRrL1b4bv5FT40W5Be5fdQaVOEyQpMS9RemC2pL4VSAK3w77fhOb+X5iqIlzW6rjUkLI5+GxGbBa4pQb3M0c= Received: from BY2PR15MB0872.namprd15.prod.outlook.com (10.164.171.142) by BY2PR15MB0790.namprd15.prod.outlook.com (10.164.171.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Sat, 24 Feb 2018 17:19:22 +0000 Received: from BY2PR15MB0872.namprd15.prod.outlook.com ([10.164.171.142]) by BY2PR15MB0872.namprd15.prod.outlook.com ([10.164.171.142]) with mapi id 15.20.0527.017; Sat, 24 Feb 2018 17:19:21 +0000 From: "ldh@laurent-hasson.com" To: Stephen Frost CC: "pgsql-performance@lists.postgresql.org" Subject: RE: Updating large tables without dead tuples Thread-Topic: Updating large tables without dead tuples Thread-Index: AdOs999XVgVoZU7YRAuMVlWzH/i5PQAC+QgAACOygIA= Date: Sat, 24 Feb 2018 17:19:21 +0000 Message-ID: References: <20180224000940.GP2416@tamriel.snowman.net> In-Reply-To: <20180224000940.GP2416@tamriel.snowman.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ldh@laurent-hasson.com; x-originating-ip: [98.15.75.184] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY2PR15MB0790;7:bZeG9XT6N9Xwl/Dk/qmDnum54msfghfQQUjGDrq7mgWCWI2dn+vVUlpK7Fme5v19bxR5CktHbgH+w8rtCyyOa3B24sfS8L1Q/uystV7aBSPOizxRLNIK1i72NOGKDbhw5vvQ/Qf237NvwK7Y++md1oa8Q1UVBkLzdyIlgJXnb9Foks5+J/E2vP0RHJNlVPBbT1AubQhZj2n4Pw7DEyHIJ2lqp1Ql3Wu9Jx/82Y4HmRF57un3x3CCEr/btIAjDcqo x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 5f611c22-3b74-4aa6-489b-08d57baabe9f x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(7021125)(4534165)(7022125)(4603075)(4627221)(201702281549075)(7048125)(7024125)(7027125)(7028125)(7023125)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020);SRVR:BY2PR15MB0790; x-ms-traffictypediagnostic: BY2PR15MB0790: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501161)(52105095)(3002001)(10201501046)(6041288)(20161123560045)(20161123562045)(20161123564045)(2016111802025)(20161123558120)(6043046)(6072148)(201708071742011);SRVR:BY2PR15MB0790;BCL:0;PCL:0;RULEID:;SRVR:BY2PR15MB0790; x-forefront-prvs: 0593E261C4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(396003)(39380400002)(39830400003)(346002)(189003)(199004)(13464003)(7696005)(2900100001)(6436002)(74316002)(53936002)(6916009)(2950100002)(305945005)(97736004)(7736002)(106356001)(86362001)(33656002)(551934003)(99286004)(86582002)(14454004)(229853002)(105586002)(9686003)(66066001)(478600001)(55016002)(81166006)(81156014)(8676002)(8936002)(6116002)(3846002)(26005)(5660300001)(25786009)(77096007)(3660700001)(68736007)(316002)(3280700002)(59450400001)(6246003)(6506007)(186003)(2906002)(76176011)(102836004)(53546011)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR15MB0790;H:BY2PR15MB0872.namprd15.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: laurent-hasson.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: PsO8N5LrriATbTvAPUqB9yfaQwyPP5ejQoPx7rhiG32ikiCPYW3w05i9UvFetHR54PMmDl/P3IGyM89+3Ci9d8uZgh8UmDrpO+LP/ZjX61BqKqQmerlvakdpvgWmu/DOLMTWmZ++OrLAChPRsLbtAUazGCGUdKnHAlxGl3qwH6M= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: laurent-hasson.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f611c22-3b74-4aa6-489b-08d57baabe9f X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2018 17:19:21.4309 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7f9c0a0d-79fd-4329-b129-754c4501a177 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR15MB0790 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > -----Original Message----- > From: Stephen Frost [mailto:sfrost@snowman.net] > Sent: Friday, February 23, 2018 19:10 > To: ldh@laurent-hasson.com > Cc: pgsql-performance@lists.postgresql.org > Subject: Re: Updating large tables without dead tuples >=20 > Greetings, >=20 > * ldh@laurent-hasson.com (ldh@laurent-hasson.com) wrote: > > This was done during a maintenance window, and that table is read-only > except when we ETL data to it on a weekly basis, and so I was just wonder= ing > why I should pay the "bloat" penalty for this type of transaction. Is the= re a trick > that could be use here? >=20 > Yes, create a new table and INSERT the data into that table, then swap th= e new > table into place as the old table. Another option, if you don't mind the > exclusive lock taken on the table, is to dump the data to another table, = then > TRUNCATE the current one and then INSERT into it. >=20 > There's other options too, involving triggers and such to allow updates a= nd > other changes to be captured during this process, avoiding the need to lo= ck the > table, but that gets a bit complicated. >=20 > > More generally, I suspect that the MVCC architecture is so deep that > something like LOCK TABLE, which would guarantee that there won't be > contentions, couldn't be used as a heuristic to not create dead tuples? T= hat > would make quite a performance improvement for this type of work though. >=20 > I'm afraid it wouldn't be quite that simple, particularly you have to thi= nk about > what happens when you issue a rollback... >=20 > Thanks! >=20 > Stephen [Laurent Hasson]=20 [Laurent Hasson]=20 This table several other tables with foreign keys into it... So any physica= l replacement of the table wouldn't work I believe. I'd have to disable/rem= ove the foreign keys across the other tables, do this work, and then re-set= the foreign keys. Overall time in aggregate may not be much shorter than t= he current implementation. This table represents Hospital visits, off of which hang a lot of other inf= ormation. The updated column in that Visits table is not part of the key. As for the rollback, I didn't think about it because in our case, short of = a db/hardware failure, this operation wouldn't fail... But the risk is ther= e and I understand the engine must be prepared for anything and fulfill the= ACID principles. With respect to that, I read in many places that an UPDATE is effectively a= DELETE + INSERT. Does that mean in the rollback logs, there are 2 entries = for each row updated as a result? Thank you, Laurent.