pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Truncate data from whole cluster
2+ messages / 2 participants
[nested] [flat]

* Truncate data from whole cluster
@ 2023-12-20 09:05 Rajesh Kumar <rajeshkumar.dba09@gmail.com>
  2023-12-20 10:23 ` Re: Truncate data from whole cluster hubert depesz lubaczewski <depesz@depesz.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Rajesh Kumar @ 2023-12-20 09:05 UTC (permalink / raw)
  To: Pgsql-admin <pgsql-admin@lists.postgresql.org>

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?

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Truncate data from whole cluster
  2023-12-20 09:05 Truncate data from whole cluster Rajesh Kumar <rajeshkumar.dba09@gmail.com>
@ 2023-12-20 10:23 ` hubert depesz lubaczewski <depesz@depesz.com>
  0 siblings, 0 replies; 2+ messages in thread

From: hubert depesz lubaczewski @ 2023-12-20 10:23 UTC (permalink / raw)
  To: Rajesh Kumar <rajeshkumar.dba09@gmail.com>; +Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-12-20 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-20 09:05 Truncate data from whole cluster Rajesh Kumar <rajeshkumar.dba09@gmail.com>
2023-12-20 10:23 ` hubert depesz lubaczewski <depesz@depesz.com>

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