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 1pIYzC-0003QU-6h for pgsql-performance@arkaria.postgresql.org; Thu, 19 Jan 2023 17:46:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pIYzA-0003rK-Lt for pgsql-performance@arkaria.postgresql.org; Thu, 19 Jan 2023 17:46:00 +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 1pIYzA-0003qK-CJ for pgsql-performance@lists.postgresql.org; Thu, 19 Jan 2023 17:46:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIYz8-0007YB-2b for pgsql-performance@lists.postgresql.org; Thu, 19 Jan 2023 17:45:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30JHjtXw4178688; Thu, 19 Jan 2023 12:45:55 -0500 From: Tom Lane To: aditya desai cc: Pgsql Performance Subject: Re: ALTER STATEMENT getting blocked In-reply-to: References: Comments: In-reply-to aditya desai message dated "Thu, 19 Jan 2023 23:00:41 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4178686.1674150355.1@sss.pgh.pa.us> Date: Thu, 19 Jan 2023 12:45:55 -0500 Message-ID: <4178687.1674150355@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk aditya desai writes: > We have a Postgres 11.16 DB which is continuously connected to informatica > and data gets read from it continuously. > When we have to ALTER TABLE.. ADD COLUMN.. it gets blocked by the SELECTs > on the table mentioned by process above. > Is there any way to ALTER the table concurrently without getting blocked? > Any parameter or option? Can someone give a specific command? ALTER TABLE requires exclusive lock to do that, so it will queue up behind any existing table locks --- but then new lock requests will queue up behind its request. So this'd only happen if your existing reading transactions don't terminate. Very long-running transactions are unfriendly to other transactions for lots of reasons including this one; see if you can fix your application to avoid that. Or manually cancel the blocking transaction(s) after the ALTER begins waiting. regards, tom lane