Re: How to get single table data from backup

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to get single table data from backup
Date: 2025-12-19 16:12:29
Message-ID: f5ab1d4f-e702-488c-a642-6a7967587451@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

>
> Andrus.
>
>

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ray O'Donnell 2025-12-19 16:12:40 Re: How to get single table data from backup
Previous Message Greg Sabino Mullane 2025-12-19 14:49:48 Re: Dealing with SeqScans when Time-based Partitions Cut Over