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 1pMbPW-0005ey-3P for pgsql-admin@arkaria.postgresql.org; Mon, 30 Jan 2023 21:09:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pMbPU-0001vt-Ud for pgsql-admin@arkaria.postgresql.org; Mon, 30 Jan 2023 21:09:52 +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 1pMbPU-0001v2-It for pgsql-admin@lists.postgresql.org; Mon, 30 Jan 2023 21:09:52 +0000 Received: from mailout.easymail.ca ([64.68.200.34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pMbPS-0006Dl-BP for pgsql-admin@lists.postgresql.org; Mon, 30 Jan 2023 21:09:52 +0000 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 2C32868246; Mon, 30 Jan 2023 21:09:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at emo09-pco.easydns.vpn Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo09-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r9Dxm_6iMc32; Mon, 30 Jan 2023 21:09:46 +0000 (UTC) Received: from smtpclient.apple (unknown [165.140.184.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id A7AC467EDA; Mon, 30 Jan 2023 21:09:46 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) Subject: Re: Foreign key creation on table with huge record count. From: Scott Ribe In-Reply-To: Date: Mon, 30 Jan 2023 14:09:35 -0700 Cc: pgsql-admin@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <954C1F48-B9C7-48FE-A135-E643EBCD9892@elevated-dev.com> References: To: Gambhir Singh X-Mailer: Apple Mail (2.3731.300.101.1.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 30, 2023, at 1:12 PM, Gambhir Singh = wrote: >=20 > do we have parallel hint like option in postgreSQL as there in Oracle.=20= I don't know of a hint option you can put on a query. But if you are = running a recent enough version of PG, there are options to support = parallel queries, and you can tune up number of workers etc. I don't = actually know if it can use multiple workers on constraint creation, but = you can use "explain" on your command to create the constraint, to see = if the planner will be using parallel workers. Of course make sure that the field being referred to is indexed, in = other words given col1 references table2(col2) make sure col2 is indexed Is this operation effectively taking your database out of service while = it runs? If so, then you can temporarily use a config tuned for just = this: let work mem for this one connection use up a big % of RAM, use = multiple workers etc. In some cases I've even turned fsync off--this = means if you crash you could wind up with a corrupted database, but if = you have a current backup, then you either succeed and turn fsync back = on when you're done, or you have your backup if something bad happens.=