Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFtjw-00CgQK-Nc for pgsql-admin@arkaria.postgresql.org; Wed, 20 Dec 2023 10:23:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rFtju-00B26j-PP for pgsql-admin@arkaria.postgresql.org; Wed, 20 Dec 2023 10:23:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFtju-00B26b-Bn for pgsql-admin@lists.postgresql.org; Wed, 20 Dec 2023 10:23:46 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rFtjr-00BJXh-Mi for pgsql-admin@lists.postgresql.org; Wed, 20 Dec 2023 10:23:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description; bh=3idJU5QeJaZ22HpTrBK2Wx+XIOdSwRLXwzisL7kwX7k=; b=PBsAqxNcGM39Ryx5QoJ/YA/l0K /ATBbnU8lXQxaimqizoArF8nEFYDVplJmX3tEZDYvs1NFcPTQjuq0AjXmj6o7me4D/w6peb6i4Gr0 0RnIcsk5knbZVcRgcRkSPEpyM2oGmKU8FVus0GkTmsHf0RIcGgUgOHjQ6w/ACUN7ME3I=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1rFtjp-002J75-0B; Wed, 20 Dec 2023 11:23:41 +0100 Date: Wed, 20 Dec 2023 11:23:41 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Rajesh Kumar Cc: Pgsql-admin Subject: Re: Truncate data from whole cluster Message-ID: Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 20, 2023 at 02:35:52PM +0530, Rajesh Kumar wrote: > Hi all, > > I am using postgres 15.2. one leader and one replica. I have multiple dbs > and multiple tables. I want to keep definitions and only want to delete > 'data only' from all dbs and tables. > > Any command to do that instead of truncating all tables one by one? No such command exists. For starters, no command in SQL can do stuff in other databases than the one you are connected to. You can write a simple one-liner that will do it, in your shell. shouldn't be really complex - get list of dbs, and in each db connect with psql and truncate all tables. basically: `psql | xargs psql` depesz