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.94.2) (envelope-from ) id 1tuoii-00C9p9-CR for pgsql-general@arkaria.postgresql.org; Wed, 19 Mar 2025 08:24:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tuoig-00GpZI-VZ for pgsql-general@arkaria.postgresql.org; Wed, 19 Mar 2025 08:24:10 +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.94.2) (envelope-from ) id 1tuoig-00GpZ9-Kf for pgsql-general@lists.postgresql.org; Wed, 19 Mar 2025 08:24:10 +0000 Received: from 11.mo581.mail-out.ovh.net ([87.98.173.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tuoid-003j3t-0Y for pgsql-general@lists.postgresql.org; Wed, 19 Mar 2025 08:24:10 +0000 Received: from director6.ghost.mail-out.ovh.net (unknown [10.108.2.251]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 4ZHhZH0pKwz1Qvy for ; Wed, 19 Mar 2025 08:24:07 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-4njnz (unknown [10.110.178.91]) by director6.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 86A171FE84; Wed, 19 Mar 2025 08:24:06 +0000 (UTC) Received: from ilm-informatique.fr ([37.59.142.101]) by ghost-submission-5b5ff79f4f-4njnz with ESMTPSA id Kz1cDCZ/2mdvMQAAEq3FGw (envelope-from ); Wed, 19 Mar 2025 08:24:06 +0000 Authentication-Results:garm.ovh; auth=pass (GARM-101G0047017385d-b0ff-4b21-823d-5e1d27adec14, 2ED49013BC27A568DD41F9660C18C78551FA769F) smtp.auth=sylvain@ilm-informatique.fr X-OVh-ClientIp:77.153.240.138 Content-Type: multipart/mixed; boundary="------------I0XUnSjhdKlHu5J4bwR025rC" Message-ID: <238e8c2a-b202-41b4-92e9-c0dbc4700c26@ilm-informatique.fr> Date: Wed, 19 Mar 2025 09:24:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Restoring only a subset of schemas To: Tom Lane Cc: pgsql-general@lists.postgresql.org References: <7d869dac-5fe0-488c-a7a1-436b1d939057@ilm-informatique.fr> <4009720.1742225376@sss.pgh.pa.us> Content-Language: fr, en-US From: Sylvain Cuaz In-Reply-To: <4009720.1742225376@sss.pgh.pa.us> X-Ovh-Tracer-Id: 9162291967660778201 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeegkeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpegtkfffgggfuffvvehfhfgjsehmtderredtvdejnecuhfhrohhmpefuhihlvhgrihhnucevuhgriicuoehshihlvhgrihhnsehilhhmqdhinhhfohhrmhgrthhiqhhuvgdrfhhrqeenucggtffrrghtthgvrhhnpedttefhieekfffghfekgedtueeggedtgfeivdffkeehjeeugfefjeetueejveegteenucfkphepuddvjedrtddrtddruddpjeejrdduheefrddvgedtrddufeekpdefjedrheelrddugedvrddutddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehshihlvhgrihhnsehilhhmqdhinhhfohhrmhgrthhiqhhuvgdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdfovfetjfhoshhtpehmohehkedumgdpmhhouggvpehsmhhtphhouhht DKIM-Signature: a=rsa-sha256; bh=00cWsS9mNmKtGnnv0m4662quL4OTaz374IkjIbg1Ab0=; c=relaxed/relaxed; d=ilm-informatique.fr; h=From; s=ovhmo24547-selector1; t=1742372647; v=1; b=o0HDgYR6e1K1L3DmdP6gCn44X2L+1eYrYaqh7fv5m/FBh217hFmie8Y7qxNtHaP02YDApk6j xGjMCGmpRAG+qrxYMgjTsOQ2kcz+zSpHLqLooBG/qTaD0iNnVnRACHFN2RrZZbEaWQKImSWdYU9 N+rA9gW7wAJzb11r7Zb4IiAIU6v/vw12WCVJSShTphIMHBkD37GnYUptzUHdcW8Xmh22pEcMvcd IHS7cvy0+4Un3yuZW1d9SnWzVOGSARx/c/wsXJyWFzsCSuESTov5xLzcO6EAk6azj5wh2zOekp2 csp8OQol+Ky25FwpxdjCwEWGNvjLGI2nqjFcAFRQv1+JA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------I0XUnSjhdKlHu5J4bwR025rC Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 17/03/2025 à 16:29, Tom Lane a écrit : > Sylvain Cuaz writes: >>     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. >> - if I could pass --create --exclude-schema='c*' (fictional notation as patterns are only recognized >> by pg_dump), then all schemas would be created, with no data inside except for "Common". Creating >> all schemas is a waste of time, but more importantly would make restoring other schemas more >> difficult (e.g. rows should be inserted before creating foreign keys). > In general, the solution for edge-case restore selection needs is to > make a list of the dump's contents with "pg_restore -l", edit out what > you don't want using any method you like, then use the edited list with > "pg_restore -L". Hi,     I am aware of that feature, but that forces me to know every type of entry that pertains to a schema or database (e.g. DEFAULT ACL, ACL, COMMENT, DATABASE PROPERTIES, etc.) and what about new ones that will be added in the future ? Further, I don't see how it's an edge-case, at the core I just want to restore some but not all the schemas. This is possible for pg_dump, see my response to Adrian Klaver. > While I'd be in favor of improving pg_restore to accept wild-card > patterns, That would definitely be appreciated. > I'm very hesitant to start inventing new kinds of selection > switches for it. The interactions between such switches would be a > mess. Which interactions ? It seems to me that the name of the schema should be used as the namespace to check in _tocEntryRequired() in pg_backup_archiver.c, and then the dependent entries (e.g. ACL, COMMENT) would be handled around line 3050. I've attached a patch with some pseudo-code. In fact, were it not for compatibility, I'd argue that my proposed options should be the default, at least with --create, so as to neither output invalid SQL (for -n) nor extra unwanted ones (for -N) and to behave like pg_dump. Cheers, Sylvain --------------I0XUnSjhdKlHu5J4bwR025rC Content-Type: text/x-patch; charset=UTF-8; name="pg_backup_archiver.patch" Content-Disposition: attachment; filename="pg_backup_archiver.patch" Content-Transfer-Encoding: base64 LS0tIHBnX2JhY2t1cF9hcmNoaXZlci5jCTIwMjUtMDMtMTggMTk6NDM6MTQuMjk3NTQ1NTM3 ICswMTAwCisrKyBwZ19iYWNrdXBfYXJjaGl2ZXJfY3JlYXRlLXNjaGVtYS5jCTIwMjUtMDMt MTggMjE6MTE6MjUuNjgxNTg2MTM5ICswMTAwCkBAIC0zMDY5LDE3ICszMDY5LDIwIEBACiAJ CS8qIEFwcGx5IHNlbGVjdGl2ZS1yZXN0b3JlIHJ1bGVzIGZvciBzdGFuZGFsb25lIFRPQyBl bnRyaWVzLiAqLwogCQlpZiAocm9wdC0+c2NoZW1hTmFtZXMuaGVhZCAhPSBOVUxMKQogCQl7 CisJCQlucyA9ICZyb3B0LT5pbmNsdWRlLWNyZWF0ZS1zY2hlbWEgJiYgc3RyY21wKHRlLT5k ZXNjLCAiU0NIRU1BIikgPT0gMCA/IHRlLT50YWcgOiB0ZS0+bmFtZXNwYWNlOwogCQkJLyog SWYgbm8gbmFtZXNwYWNlIGlzIHNwZWNpZmllZCwgaXQgbWVhbnMgYWxsLiAqLwotCQkJaWYg KCF0ZS0+bmFtZXNwYWNlKQorCQkJaWYgKCFucykKIAkJCQlyZXR1cm4gMDsKLQ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