public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sylvain Cuaz <[email protected]>
To: [email protected]
Subject: Re: Restoring only a subset of schemas
Date: Wed, 19 Mar 2025 09:17:06 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

Le 17/03/2025 à 16:21, Adrian Klaver a écrit :
> On 3/17/25 07:57, Sylvain Cuaz wrote:
>> Hi all,
>>
>>      I have a DB with one schema named "Common" holding data referenced by other schemas. All 
>> other schemas have the same structure (tables and fields) and are named "cXXX" where XXX is just 
>> an int. Thus the only cross-schema foreign keys are in "cXXX" pointing to "Common", and each 
>> "cXXX" is completely independent of other "cXXX" schemas.
>>      Now if I want to restore from a full dump of this DB, but with only one "cXXX" and the 
>> "Common" schema :
>> - if I pass --create --schema=Common, then the CREATE SCHEMA is missing, i.e. it only emits data 
>> inside "Common" and the restore fails.
>
> I am not seeing that.
>
> For:
>
> pg_dump -d test -U postgres -s --create --schema=other_sch --schema=public
>
> What is the complete command you are using for the pg_dump?

Hi,

     As I said I'm restoring, not dumping. I make daily full backups and sometimes need to restore a 
specific day, but the full database is quite big and I would like to only restore one or two schemas.

As you said, if one passes --create --schema to pg_dump then a valid SQL is produced with CREATE 
DATABASE, CREATE SCHEMA, CREATE TABLE and all objects inside the schema.

But if one passes --create --schema to pg_restore then an invalid SQL is produced because it 
contains CREATE DATABASE, CREATE TABLE but it doesn't contain the CREATE SCHEMA needed for the 
tables. Is there any reason for that discrepancy between dump & restore and for outputting invalid 
SQL ?

My proposed --include-create-schema would just add the CREATE SCHEMA so that pg_restore behaves the 
same as pg_dump, and would allow to output valid SQL. But ideally this option shouldn't even be 
needed because pg_restore would just emit CREATE SCHEMA like pg_dump.

>
> What Postgres version(s) are you using? 

A lot :-) But for this problem I'm using 13 & 15.


Cheers,

Sylvain.







view thread (6+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Restoring only a subset of schemas
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox