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.96) (envelope-from ) id 1vw720-003REK-0D for pgsql-general@arkaria.postgresql.org; Fri, 27 Feb 2026 23:14:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vw71y-007cio-1z for pgsql-general@arkaria.postgresql.org; Fri, 27 Feb 2026 23:13:58 +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.96) (envelope-from ) id 1vw71x-007ciK-22 for pgsql-general@lists.postgresql.org; Fri, 27 Feb 2026 23:13:58 +0000 Received: from fhigh-b8-smtp.messagingengine.com ([202.12.124.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vw71u-00000001Zz8-1yAG for pgsql-general@lists.postgresql.org; Fri, 27 Feb 2026 23:13:56 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 24DB67A01DF; Fri, 27 Feb 2026 18:13:54 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 27 Feb 2026 18:13:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1772234033; x=1772320433; bh=EHFMZnSG5SAsF8Yp7+dDtFG3wYjb82B7X3btO0O6cQE=; b= MtG1Xp412tZGFgcf0NkcgYT2RO5UF2yS17rdMXoFbVM3mcNAJx386ihs9OnD7e7e AeFavIrBoysxficRFwmfw5xkDsrNnOBc2xlRKAu4wR4R5wGkmQ9IWUyAwTXjgV+4 qT1maEIt0VGD5KJEwh3yj9/Bio0xyiOMoVec1fytM9Z4qwAmdFuOYpFWgK3qQax4 G4oAf6BB3rAbk3zEfuG1b8GrNqrzF5Hv/+F3K3xUbag3NoKGmUGVjt+E3+QnNAHT YqzSAiQs6fUIToIAQ+Tx3Jl/HdyoGoprad5Auzrhae3pxKBCJqZ06L797jR08cAi 6G01przlFzNeyoS7aWx0Ew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1772234033; x=1772320433; bh=E HFMZnSG5SAsF8Yp7+dDtFG3wYjb82B7X3btO0O6cQE=; b=fdoO1evPtVB7dIZk0 +WC4zxYEKpNUD85xpFaa8reWhVKy7vCBqBNUNbv3ElOG74qhQWrb23VolCzB4b0B a7gQL2y5Do1WSkuhv3vAsJ4FUD+lwupWR2oyG+pz9Mkd2mBowN4+hBwGjA3deCVa WmzRoF5HL+7jeXKsCjuemnpHER3yrtO35/wZCXGRWdicPOSeZgkI00pIslviU8+i h2pl24IdZ6gX4ADi68TVbmTZcucssnx2sxXhm3UsxAi5GtvIshPJWqQvQMU9Uc0P HAiGuuXoawsiXNwLTJfrv7Zpzcc0KELl98hvOxsCKK2J/AAkkAN+o1VDwcIO090I Mr1FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvhedtvdelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepleegveekkeekue eigfdtveeileeuhfefudefteekjeffkeejueejheegheegkedtnecuffhomhgrihhnpehp ohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm pdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegufh hgphhoshhtghhrvghsfeesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhg vghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Feb 2026 18:13:53 -0500 (EST) Message-ID: <666bc91c-d5df-4a61-aa3a-30fb1e1c9fcb@aklaver.com> Date: Fri, 27 Feb 2026 15:13:52 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can "on delete cascade" dependency be used in pgdump or similar ? To: dfgpostgres , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/27/26 2:39 PM, dfgpostgres wrote: > pg 15.15 on linux > > I have a DB with a table called "projects" which has a primary key > column called "project".  Other child tables are linked in a primary/ > foreign key relationship to "projects" with "on delete cascade".  Each > of those may have grandchild tables linked in via other primary/foreign > key relationships, all with the "on delete cascade".  Etc... .  If I > delete project "a", it'll cascade delete the children,  grandchild, > etc...  recs.  All traces of project "a" will be gone. > > But I don't really want to lose the data from project "a", I want to > archive it in another DB (same DB server, different DB).  The brain-numb > method I've been using thus far is to copy the whole DB via pgdump then > use that to create the DB "a_archive".  Then (here's the wasteful part) > basically delete all the projects in "a-archive" EXCEPT for project > "a".  Then, when that's done, go to the main DB and delete project "a". > In effect, I just archived all the data for project "a" and put it in > the DB called "a_archive".while relieving the main DB of the project "a" > data. But what would be really neat is to leverage that cascade on > delete stuff to just pgdump project "a" and use that to create "a_archive". > > Can pgdump do something like that ? The best you can do, with pg_dump, is use: https://www.postgresql.org/docs/current/app-pgdump.html --table=pattern Dump only tables with names matching pattern. Multiple tables can be selected by writing multiple -t switches. Though it will be up to you to make sure all the related tables are present in the dump. Also depending on how things are setup you might be able to use logical replication: https://www.postgresql.org/docs/current/logical-replication.html In either case you still have to clean out the original database. > Is there a better way to approach this problem of archiving one project > (remembering that we do have the "on delete cascade" set up) ? > > Thanks in Advance ! > -- Adrian Klaver adrian.klaver@aklaver.com