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 1vWdGf-006EQD-1E for pgsql-general@arkaria.postgresql.org; Fri, 19 Dec 2025 16:23:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWdGe-008R9O-0s for pgsql-general@arkaria.postgresql.org; Fri, 19 Dec 2025 16:23:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWdGd-008R9F-1M for pgsql-general@lists.postgresql.org; Fri, 19 Dec 2025 16:23:48 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWdGb-001d1z-1a for pgsql-general@postgresql.org; Fri, 19 Dec 2025 16:23:47 +0000 Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 818237A001C; Fri, 19 Dec 2025 11:23:43 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 19 Dec 2025 11:23:43 -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=fm3; t=1766161423; x=1766247823; bh=UgRFtdPVRV4X4JaUAY7PV1bb6S4jHjlkmfnqZcpOTY8=; b= u7tID/D2qk14O/iUWEPTnnCLWKLk26+lSLLmHtqOsKTiquz9iS4RCas8slQI9Tq9 Cjgxv+hPT6sE6sVdqeYM1ePgyOJpH5GBP8tQwxeZh9i1Enma/NEgigUjXDH2kjGB UQZaudjUi0efCfJcpxmb6aOAsl+6vvImBtdsF9WNddBHPvOT80iQXPAw7UUpP7ST WYDhIK9plKAra5juaYOcZ5r5is9axSNwCzKHiR2vlTmcbTsP5upZrHNBzLPDwXj7 KXpUbAscIyy9fYUwuErIryS3WbXkOoQsLj1UkEFYrhj00H7rl6JrP+6OHKMCfYif KX9Vw0cHlx+MouzniT1BqA== 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=fm1; t=1766161423; x=1766247823; bh=U gRFtdPVRV4X4JaUAY7PV1bb6S4jHjlkmfnqZcpOTY8=; b=fc9skH5zH39GFxCA2 1PgZgcnHlskFrs07LTM6iYY0mGdQIo0+yrqqslt6MRV9l2UVcyRayRou94BheISM L6Ic+3yCqIkastEln8k+5jqaBXDUMGNuJtBEGkgfIdIsD3RCt3gkSEPLQivyHQgl omxsrngQGnNITCQOi+Zl8aA2nrBdaUmfesvcM5+xtqkHb6q09wDPvqlpno0Btjok C/jus1d7+aWdZ9piqxFG/nYvYNmIleD8KbQybd1+Fsllpl3y3DeFZfvR+PdoHyG2 pdbM600wzQySYenahsl9kEQ7u078tQhrP1nOxsQGGBjsak+fzg7uC6WdfTXBovp1 E5TXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegkeejjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffhvfhfjggtgfesthekredttd dvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefhudevueefveffje eigeehffetteehjeevtedtgfdtfedvgeejgfevvdefhfetffenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehkohgsrhhulhgvhhhtvdeshhhothdrvggvpdhrtghpthhtohepph hgshhqlhdqghgvnhgvrhgrlhesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 19 Dec 2025 11:23:42 -0500 (EST) Message-ID: <22e39323-a1d4-4c07-b840-d796f35e07cc@aklaver.com> Date: Fri, 19 Dec 2025 08:23:42 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: How to get single table data from backup From: Adrian Klaver To: Andrus , pgsql-general References: Content-Language: en-US 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 12/19/25 08:12, Adrian Klaver wrote: > On 12/19/25 04:41, Andrus wrote: >> Hi! >> >> Large database backup is created using >> >> pg_dump -b -f backup.backup -F c >> >> How to restore single table in schema firma2 from it in Windows? >> >> Created database recovery and tried >> >> pg_restore --schema-only --n firma2 -d recovery backup.backup >> pg_restore -n firma2 -t tabletorecover -d recovery backup.backup >> >> This fails since tabletorecover contains lot foreign key references. >> Foreign keys refer to other tables which have foreign keys to another >> tables etc. making huge graph. All tables contain also data. >> >> I need to get table data only. Using PostgresSql 17 in windows. > > 1) Does the table name tabletorecover occur in more then one SCHEMA? > > 2) Do you want only the table data for tabletorecover? > > Assuming 1 is one SCHEMA only and 2 is tabletorecover data only then > maybe something like: > > 1) pg_restore --schema-only --table=tabletorecover -d recovery > backup.backup > > 2) In psql ALTER TABLE tabletorecover DROP CONSTRAINT the FK references > in tabletorecover. > > 3) pg_restore --data-only --table=tabletorecover -d recovery backup.backup > An alternate method: 1) pg_restore --table=tabletorecover --file recovery.sql backup.backup Here you are restoring the table structure and data to a text file. 2) Open the text file and remove the FK references from the table definition. 3) Then do psql -f recovery.sql -d recovery If the amount of data is large and you don't want to deal with that in a text file then in step 1 add --schema to get just the table definition. Then do pg_restore --data-only --table=tabletorecover -d recovery backup.backup as step 4. >> >> Andrus. >> >> > > -- Adrian Klaver adrian.klaver@aklaver.com