Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvTZv-0001Fu-Cp for pgsql-admin@arkaria.postgresql.org; Sun, 17 Feb 2019 21:02:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gvTZu-0006XU-4P for pgsql-admin@arkaria.postgresql.org; Sun, 17 Feb 2019 21:02:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvTZt-0006XN-P3 for pgsql-admin@lists.postgresql.org; Sun, 17 Feb 2019 21:02:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvTZq-000164-RR for pgsql-admin@lists.postgresql.org; Sun, 17 Feb 2019 21:02:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x1HL240G003772; Sun, 17 Feb 2019 16:02:04 -0500 From: Tom Lane To: Mariel Cherkassky cc: Laurenz Albe , pgsql-admin@lists.postgresql.org Subject: Re: pg_restore fails to restore sequence of specific table In-reply-to: References: <41dbc1307b3ebe4c9251194f5f380ca44cc8dc66.camel@cybertec.at> Comments: In-reply-to Mariel Cherkassky message dated "Sun, 17 Feb 2019 22:29:21 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3770.1550437324.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 17 Feb 2019 16:02:04 -0500 Message-ID: <3771.1550437324@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mariel Cherkassky writes: > I tried to restore the sequence also by specifying it in the -t flag but > got the same error. Can you explain why it isn't appearing in the plain > text backup but it does appear in the output of pg_restore -l ? Hmm, worked for me, for small values of "work": pg_restore -t specific_table -t specific_table_id_seq ... This creates the table and the sequence, but fails to establish any connection between them. The trouble here is that pg_restore's "-t" is a very low-level, literal-minded switch. Supposing you have create table specific_table(id serial primary key, effectiveid int); If you do a pg_dump -Fc and then use "pg_restore -l" to see what entries are in the dump archive, you will get something like 197; 1259 102953 TABLE public specific_table postgres 196; 1259 102951 SEQUENCE public specific_table_id_seq postgres 3023; 0 0 SEQUENCE OWNED BY public specific_table_id_seq postgres 2891; 2604 102956 DEFAULT public specific_table id postgres 3016; 0 102953 TABLE DATA public specific_table postgres 3024; 0 0 SEQUENCE SET public specific_table_id_seq postgres 2893; 2606 102958 CONSTRAINT public specific_table specific_table_pkey pos= tgres You need to select *all* of those items if you want to restore the table fully, but "-t specific_table" is stupid and selects only the "TABLE specific_table" one (and the TABLE DATA, I think). The most reliable way to do what you want is to do "pg_restore -l mydb.dump >mydb.list", edit mydb.list down to just the items you want, and then use "pg_restore -L mydb.list ..." to select those items. Not too user-friendly, I'm afraid, especially since pg_dump's "-t" switch is quite a bit smarter about what to dump. But nobody's put any work into making pg_restore's switch better. In the meantime, maybe you could use "pg_dump -t" if you know you just want the one table. regards, tom lane