Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLPB1-0007SN-FI for pgsql-admin@arkaria.postgresql.org; Tue, 09 Aug 2022 13:21:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oLPB0-0007rY-2r for pgsql-admin@arkaria.postgresql.org; Tue, 09 Aug 2022 13:21:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLPAz-0007rP-K6 for pgsql-admin@lists.postgresql.org; Tue, 09 Aug 2022 13:21:41 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oLPAv-00042J-L2 for pgsql-admin@lists.postgresql.org; Tue, 09 Aug 2022 13:21:40 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 16DDB380DDD; Tue, 9 Aug 2022 15:21:35 +0200 (CEST) Received: from rs.plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Enz0xQdGVxOh; Tue, 9 Aug 2022 15:21:35 +0200 (CEST) Received: from [192.168.178.28] (ip-037-201-152-231.um10.pools.vodafone-ip.de [37.201.152.231]) by rs.plausibolo.de (Postfix) with ESMTPSA id B75BE380CC9; Tue, 9 Aug 2022 15:21:34 +0200 (CEST) Message-ID: <9ca2d8ca-a175-630e-e449-48c2dee5e0f6@jakobs.com> Date: Tue, 9 Aug 2022 15:21:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.1 Subject: Re: How to fully restore a single table from a custom dump? To: pgsql-admin@lists.postgresql.org References: <1622540476.1110533.1660049347030@email.ionos.com> From: Holger Jakobs In-Reply-To: <1622540476.1110533.1660049347030@email.ionos.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------ascI2CrFJs2E08ORwBwft00O" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------ascI2CrFJs2E08ORwBwft00O Content-Type: multipart/mixed; boundary="------------J33JKNE50HB6FDK4jchSswKH"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: <9ca2d8ca-a175-630e-e449-48c2dee5e0f6@jakobs.com> Subject: Re: How to fully restore a single table from a custom dump? References: <1622540476.1110533.1660049347030@email.ionos.com> In-Reply-To: <1622540476.1110533.1660049347030@email.ionos.com> --------------J33JKNE50HB6FDK4jchSswKH Content-Type: multipart/alternative; boundary="------------Q49UB1ATi20Ub7debhnmkUjf" --------------Q49UB1ATi20Ub7debhnmkUjf Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: base64 QW0gMDkuMDguMjIgdW0gMTQ6NDkgc2NocmllYiBNaWNoYWVsREJBIFZpdGFsZToNCj4gSGks DQo+IElmIHlvdSB1c2UgdGhlIGRpcmVjdG9yeSBkdW1wIG1ldGhvZCwgLUZkLCB0aGVuIHlv dSBjb3VsZCBnZW5lcmF0ZSBhbiANCj4gZWRpdGFibGUgbGlzdGluZyB3aGVyZSB5b3UgY2Fu IHNlbGVjdGl2ZWx5IHJlbW92ZSBzdHVmZiB0aGF0IHlvdSBkb24ndCANCj4gd2FudCB0byBy ZXN0b3JlLCBqdXN0IGtlZXBpbmcgdGhlIHN0dWZmIHJlbGF0ZWQgdG8geW91ciBzcGVjaWZp YyANCj4gdGFibGUuwqAgwqBZb3UgcnVuIHBnX3Jlc3Rv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j4+IHNlbGVjdGVkIHRhYmxlLg0KPj4gQW55IGlkZWFzLCBob3cgSSBjYW4gX2Z1bGx5XyBy ZXN0b3JlIGEgc2luZ2xlIHRhYmxlIGZyb20gYSBjdXN0b20gZHVtcD8NCj4+IFRob21hcw0K DQpDcmVhdGluZyBhIGxpc3Qgb2YgY29udGFpbmVkIGl0ZW1zIGFuZCByZXN0b3Jpbmcgc29t ZSBvZiB0aGVtIHdvcmtzIHRoZSANCnNhbWUgd2l0aCBjdXN0b20gZHVtcHMuIERpcmVjdG9y eSBkdW1wcyBoYXZlIG5vIGFkdmFudGFnZSBoZXJlLg0KDQpKdXN0IGNvbW1lbnQgb3V0IGFs bCBpdGVtcyB5b3UgZG9uJ3Qgd2FudCB0byByZXN0b3JlIGJ5IHB1dHRpbmcgYSA7IGluIA0K ZnJvbnQgb2YgdGhlIGxpbmVzIG9yIGRlbGV0ZSB0aGUgdW53YW50ZWQgbGluZXMgYWx0b2dl dGhlciBhbmQgcmVzdG9yZS4NCg0KQmVzdCByZWdhcmRzLA0KDQpIb2xnZXINCg0KLS0gDQpI b2xnZXIgSmFrb2JzLCBCZXJnaXNjaCBHbGFkYmFjaCwgVGVsLiArNDktMTc4LTk3NTkwMTIN Cg0K --------------Q49UB1ATi20Ub7debhnmkUjf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Am 09.08.22 um 14:49 schrieb MichaelDB= A Vitale:
Hi,
If you use the directory dump method,= -Fd, then you could generate an editable listing where you can selectively remove stuff that you don't want to restore, just keeping the stuff related to your specific table.=C2=A0 =C2=A0You= run pg_restore once to generate the listing.=C2=A0 Then run pg_restor= e again using that modified listing to load into the target database. See the pg_restore docs for exact syntax.
=C2=A0
Regards,
Michael Vitale
=C2=A0
On 08/09/2022 8:06 AM EDT Thomas Kellerer <shammat@gmx.net> wrote= :
=C2=A0
=C2=A0
Hello,
=C2=A0
I just realized that using
=C2=A0
pg_restore -t some_table ... some_dump_file
=C2=A0
doesn't restore things like identity attributes
or indexes on the specified table.
=C2=A0
The dump contains much more than just that table, so simply
using pg_restore without -t is not an option.
=C2=A0
While I could extract the indexes manually using some clever regex
on the index names, I don't see a way to make sure that identity
definitions (or sequence values) are restored properly for the selected table.
=C2=A0
Any ideas, how I can _fully_ restore a single table from a custom dump?
=C2=A0
Thomas

Creating a list of contained items and restoring some of them works the same with custom dumps. Directory dumps have no advantage here.

Just comment out all items you don't want to restore by putting a ; in front of the lines or delete the unwanted lines altogether and restore.

Best regards,

Holger

--=20
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
--------------Q49UB1ATi20Ub7debhnmkUjf-- --------------J33JKNE50HB6FDK4jchSswKH-- --------------ascI2CrFJs2E08ORwBwft00O Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCYvJfXQUDAAAAAAAKCRCKV5yTsxlhuhUu AKDlPxvxwzZjNIxs9AMX7IHa70klnwCg5OsQ6imE4wY1t4YSKW2qwmEWX4M= =1VXf -----END PGP SIGNATURE----- --------------ascI2CrFJs2E08ORwBwft00O--