pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Rajesh Kumar <rajeshkumar.dba09@gmail.com>
Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Truncate data from whole cluster
Date: Wed, 20 Dec 2023 11:23:41 +0100
Message-ID: <ZYLArRMPsNu3ZooU@depesz.com> (raw)
In-Reply-To: <CAJk5Atah42SXmNFDJmP22XtTeov+aKfSSkzCAAqXYzMe0En-8A@mail.gmail.com>
References: <CAJk5Atah42SXmNFDJmP22XtTeov+aKfSSkzCAAqXYzMe0En-8A@mail.gmail.com>

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





view thread (2+ messages)

Message-ID: <ZYLArRMPsNu3ZooU@depesz.com>
Permalink:  ../ZYLArRMPsNu3ZooU@depesz.com/
Also on:    postgresql.org/message-id/ZYLArRMPsNu3ZooU@depesz.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: depesz@depesz.com, rajeshkumar.dba09@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: Truncate data from whole cluster
  In-Reply-To: <ZYLArRMPsNu3ZooU@depesz.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox