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.96) (envelope-from ) id 1w2Vpe-000MBy-0u for pgsql-general@arkaria.postgresql.org; Tue, 17 Mar 2026 14:55:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2Vpd-002MBC-0l for pgsql-general@arkaria.postgresql.org; Tue, 17 Mar 2026 14:55:41 +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.96) (envelope-from ) id 1w2Vpc-002MB4-2t for pgsql-general@lists.postgresql.org; Tue, 17 Mar 2026 14:55:40 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w2Vpa-00000000cUh-1tuz for pgsql-general@lists.postgresql.org; Tue, 17 Mar 2026 14:55:40 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id A0A4B1400227; Tue, 17 Mar 2026 10:55:37 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Tue, 17 Mar 2026 10:55:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1773759337; x=1773845737; bh=biUZZz437ByTkNykRP7ZsyoTd6WyWLlnwcaiZXRcsec=; b= OP25E7jMYeJx8pK7U39LiizeSvHNHcdSzV7OkR7x9/yOCly2ieh2SD0KL87F6u8W Ji8ocOw467oW6to1iJkiQd6iOxNOD6Z+0PAwJMPwoULSG8J+uwJ2/g5prLxIKMg8 j2HUMxHEbpUF2akNeY323lR/N8fDx2Jm6a87fTkMBlsiAqsnzv2IvjBjT5qi2GtP JIJ/xvCFwT3DditcBB4NHOQuaCHtT8wX9VnMzmgjFDWG4kL5IqSzkx9wxUvOA/v2 PFn4bx+8Rsxyrjzio/+S6XN+Qtrn0U3hLOuK12IK1kkZX9hwlVZ1nERonL+SZ48X eCmwscUqSPRr8Pv+JICUPQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1773759337; x=1773845737; bh=b iUZZz437ByTkNykRP7ZsyoTd6WyWLlnwcaiZXRcsec=; b=KUnICU5cBQizWzoXu 1UVcE6TmifAH9U1OvY8j+8Cpolj9Zs+gm/XUOPZJT/SMOBDFjxP9CP33v/Gh3pYK VuvehCqhHspzXTak20xdKkv84oEmC5yKM5zcJW/Lx9QJxSQCooPFDx283AutKMFQ 06GXKyRW1v5KKbtEeVQLz9AOvA7M9dw6Qpv+v61GIwV1tWLGm4aw7Bst5du9pQrk XYQvUPjiJflPgNg/DS8gj81LSVWHw4OXbQhAwFYlHAI24jFfaUSLCF7IOl+zgTTr 9u2YOdDIPAlQETeypEGWbEvkZ4qS1sc2IoiO8SwPpGMllyyRuPc5GQHVhBPLjCQU fOXnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdeftdduheegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffhvfhfjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghn ucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqe enucggtffrrghtthgvrhhnpefhudevueefveffjeeigeehffetteehjeevtedtgfdtfedv geejgfevvdefhfetffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpdhnsggp rhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehshhgrhhgvvg guhhgrqhhuvgesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhgvghnvghr rghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 17 Mar 2026 10:55:37 -0400 (EDT) Message-ID: <0c4e4d9c-bd93-4bec-91c5-13180eb71aa8@aklaver.com> Date: Tue, 17 Mar 2026 07:55:36 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can I use pg_dump to save a sequence for a table that is not also being saved? From: Adrian Klaver To: Shaheed Haque , pgsql-general list References: <85f5b5b4-e530-4458-b562-5a49a4e2ff09@aklaver.com> Content-Language: en-US In-Reply-To: <85f5b5b4-e530-4458-b562-5a49a4e2ff09@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/17/26 7:37 AM, Adrian Klaver wrote: > On 3/17/26 6:58 AM, Shaheed Haque wrote: >> Hi, >> >> I observe when using pg_dump like this: >> >>     pg_dump -h localhost -p 5432 -U dbcoreuser -Ft -f abc.tar --no- >>     privileges --data-only \ >> >>     --exclude-table="public.(jobs|queues|results) \ >>     --table=public.django_migrations \ >>     --table=public.paiyroll_input \ >> >>     --table=public.*_id_seq \ >> >>     --verbose foo >> >> >> that the dumped data contains the content of the two tables, and the >> two sequences.  (FWIW, the above command is actually submitted via a >> Python subprocess call, so quoting should not be an issue). The >> verbose output confirms this: >> >>     pg_dump: processing data for table "public.django_migrations" >>     pg_dump: processing data for table "public.paiyroll_input" >>     pg_dump: executing SEQUENCE SET django_migrations_id_seq >>     pg_dump: executing SEQUENCE SET paiyroll_input_id_seq >> >> >> Note that the instance "foo" contains many other tables, whose >> sequences I was expecting to be included. To confirm this, if I drop >> the second "--table", the verbose log shows only: >> >>     pg_dump: processing data for table "public.django_migrations" >>     pg_dump: executing SEQUENCE SET django_migrations_id_seq >> >> >> My conclusion is that - despite what I understood from the pg_dump >> docs - the use of "--table=public.*id_seq" does not include all the >> sequences in fo, only those named by another --table. >> >> Did I misunderstand, or formulate the command incorrectly? > > My bet is this due to a dependency of paiyroll_input_id_seq on > public.paiyroll_input. > > Provide the output, in psql, of: > > \d public.paiyroll_input To demonstrate: CREATE TABLE seq_test ( line_id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, bool_fld boolean, str_fld varchar ); \d seq_test Table "public.seq_test" Column | Type | Collation | Nullable | Default ----------+-------------------+-----------+----------+------------------------------ line_id | integer | | not null | generated always as identity bool_fld | boolean | | | str_fld | character varying | | | Indexes: "seq_test_pkey" PRIMARY KEY, btree (line_id) SELECT pg_get_serial_sequence('public.seq_test', 'line_id'); pg_get_serial_sequence ----------------------------- public.seq_test_line_id_seq pg_dump -d plant_grower_db -U db_admin -p 5482 -t seq_test --data-only -- -- PostgreSQL database dump -- [...] COPY public.seq_test (line_id, bool_fld, str_fld) FROM stdin; \. -- -- Name: seq_test_line_id_seq; Type: SEQUENCE SET; Schema: public; Owner: db_admin -- SELECT pg_catalog.setval('public.seq_test_line_id_seq', 1, false); [...] -- -- PostgreSQL database dump complete -- pg_dump -d plant_grower_db -U db_admin -p 5482 -t seq_test_line_id_seq --data-only -- -- PostgreSQL database dump -- [...] -- No sequence data. [...] -- -- PostgreSQL database dump complete -- > >> >> Thanks, Shaheed > > -- Adrian Klaver adrian.klaver@aklaver.com