Re: creating a subset DB efficiently ?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: David Gauthier <dfgpostgres(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: creating a subset DB efficiently ?
Date: 2024-03-09 17:02:23
Message-ID: f204d4ac-88b2-40de-ad01-3a30728404ff@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/8/24 08:22, David Gauthier wrote:
> Here's the situation....
>
> - The DB contains data for several projects.
> - The tables of the DB contain data for all projects (data is not
> partitioned on project name or anything like that)
> - The "project" identifier (table column) exists in a few "parent"
> tables with many child... grandchild,... tables under them connected
> with foreign keys defined with "on delete cascade".  So if a record in
> one of the parent table records is deleted, all of its underlying,
> dependent records get deleted too.

How many "... child... grandchild,... tables" ?

Do these tables constitute all the tables in the database?

> Related question...
> The "delete from par_tbl_a where project <> 'a' " is taking forever.  I
> fear it's because it's trying to journal everything in case I want to
> rollback.  But this is just in the archive DB and I don't mind taking
> the risk if I can speed this up outside of a transaction.  How can I run
> a delete command like this without the rollback recovery overhead ?

I am assuming that at the point you do "delete from par_tbl_a where
project <> 'a' " project a is no longer receiving data and its records
are static. Further assuming there is a PK that you could order by, then
it would seem the way to go would be to delete in batches as determined
by the PK.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-03-09 18:00:50 Re: Seeing high query planning time on Azure Postgres Single Server version 11.
Previous Message kuldeep singh 2024-03-09 16:34:29 Re: Insert with Jsonb column hangs