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 1k2q73-0004gH-Uq for pgsql-general@arkaria.postgresql.org; Tue, 04 Aug 2020 06:07:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k2q72-0006x2-NO for pgsql-general@arkaria.postgresql.org; Tue, 04 Aug 2020 06:07:48 +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 1k2q72-0006wu-Eb for pgsql-general@lists.postgresql.org; Tue, 04 Aug 2020 06:07:48 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k2q70-0003Y3-2n for pgsql-general@lists.postgresql.org; Tue, 04 Aug 2020 06:07:48 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id EB3A315B3; Tue, 4 Aug 2020 02:07:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 04 Aug 2020 02:07:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=kzkrPGv2fvdKC8lFY19osekd6Lc UoQI/KGQri8YgquU=; b=eXB1BXGICCO9xl4MC0bqGKRiHylL2/f03ye5ybtnl9b OExX1Ep85Vf0QilsLnu8/t0VZwdpWeAET08YIu1l2KqEJNZKpRISZr2vXAb55/Kj t2XCAioaDVoRWaIslu2FFNPtWCRTIitxbcPx0cottVN0TJ4J8P/+P6jW2k7N5aiY MsSym6S1fVV9EB/AaMV1d3G4RsxrlbzLRxjOsA9w5EIsJpXCDoazfq9pJkMmIQ7/ rcTQvmnidy5CmRvUCHoi0MWShjyg1P966JMlO4fXFOkvEXptiM7pshh3hfxkV1QX xxBTU18kd4wOdXroT5uvwVyG7r7RPaX8/qO28Q79yyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=kzkrPG v2fvdKC8lFY19osekd6LcUoQI/KGQri8YgquU=; b=KzyOp3g76MH8Or+AnSLg00 0fp49Al51w2fOFITPw87Y9QkdVX6wdlmaOfkIFSi6i+L+o8+p6kFs8erZSRKoK+P b+6W7POqDOtJR6zWd+czudVt74vx1MDQQmRe7begMEnnJM7cXdP7DjhQj9UW0b4h fu/ZIT2smKxfpG96rwVhEstPN6L2SQ+Y7R2lf2Hyrex14s8z1hXvb7bkHmUT4PmR St+/r47+pUb/TMMznSzcWmvhnjc99MZDe0g+q8w/xrCHQ4gLuwjYrhokfFkW1Shy xVARY2UZf2nMvPcmX9OVhueL0bDZCvuVIW4ci19KYF4htQRIWibJyXWoTp3MjHaw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrjeehgddutdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhu ihgvrhcuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrh hnpedvgeduuefhtdeuleettdevjeehheeiveeuieegleetgeeljeelieeuieehgeevhfen ucfkphepudduuddruddtvddrudektddrudekheenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 2E1D630600A9; Tue, 4 Aug 2020 02:07:40 -0400 (EDT) Date: Tue, 4 Aug 2020 15:07:37 +0900 From: Michael Paquier To: Ron Cc: pgsql-general@lists.postgresql.org Subject: Re: How to rebuild index efficiently Message-ID: <20200804060737.GD2091@paquier.xyz> References: <5131947A-0470-46C0-93B8-7AE07BBC22FA@thebuild.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rqzD5py0kzyFAOWN" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --rqzD5py0kzyFAOWN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 03, 2020 at 01:04:45PM -0500, Ron wrote: > same definition, and when that is complete, drop the old index. The > locking that is required here is modest: CREATE INDEX CONCURRENTLY > needs to lock the table briefly at a couple of points in the > operation, and dropping the old index requires a brief lock on the > table. It is, however, much less overall lock time than REINDEX would b= e. >=20 > Of course, you need enough disk space... :) A SHARE UPDATE EXCLUSIVE lock is taken during a CIC, meaning that writes and reads are allowed on the parent table while the operation works, but no DDLs are allowed (roughly). The operation takes a couple of transactions to complete, and there are two wait points after building and validating the new index to make sure that there are no transactions remaining around that may cause visiblity issues once the new index is ready to use and becomes valid. So the operation is longer, takes more resources, but it has the advantage to be non-disruptive. -- Michael --rqzD5py0kzyFAOWN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl8o+ykACgkQnvQgOdby QH31vxAApt5IqjSer/ZgvzJSQfr7MOBrZcizgFE8UbyryPl6+6rsUFR/HT+2Mi3i AZRoFRGFVpu5uA/u0vjkZtXEvVA0wGDgjwmWQCsCkmaTl+sFuTc2Bgy0CYcpmeQB 9AEeZyfNCzl4xnEihYpf8xv9iOTTh6IXWQxJfDrnPVb/eXZ66tJAu4EnQn9riXQf v0N5TbPOGtxTjmWop9rhj60BlLgz2V7fm8foJIOvyXYnYE0/ZdlOAGi5RnHL1xnf s24QtJysVUyIt8gkrM+fflmNVnjv4UlHXN+qnm/0AAcfeyzm317YozaC7M2V9G1i LT3ayl1lxozC3sRasYvnZfYn79JI+HS9Gg+H9YdTNYTGHdN7gtxAHh2txgcSOEht CfEpOEavLygW2M1hqkmvi1QkrGWQYo3/lgQqhhH/YlVs31k5e0dsrlD5145IYVQZ qXT1yBQPmHiaXhybCekllQ52nueMWlbM4hzUxQgfBttWo6ju/cpYScPfs9ISa58Q zsVK/LpkMlU8pQ2woUkMkfc0Ry8kJIAavPi3oW++4hr+TuZ7rDIF7nflEgduZyJ4 ika9eUEnA3vbbJz0KjSMmE5NYIyusS130Krxs7hHBaC6i84U+ENDIyGTNmG9C+x+ S5hYs2DevREAREcY0KsFbli93ogqf/3CNWNGQIbAOaBGKK4+UYg= =P25H -----END PGP SIGNATURE----- --rqzD5py0kzyFAOWN--