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 1iN09H-0000gb-OB for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 19:48:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iN09F-00043l-CI for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 19:48:53 +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 1iN09E-0003yY-5N for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 19:48:53 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iN097-0001Ya-2O for pgsql-general@postgresql.org; Tue, 22 Oct 2019 19:48:50 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 0E3CE21368; Tue, 22 Oct 2019 15:48:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 22 Oct 2019 15:48:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=b uG2nrPfJgaghtheP7ARAozSU662XKXLR25XnLaEjww=; b=abPH6l78YIMWvMttF C+pYn5OwrA4Ovdp0HiWS4pf/Pe7ENM1hbC4TsQe+y0TjttpBCa4SYrCmtkPCeKmt 1VcaxJ47KUVWhRpDWxfuCeufmyVxRvPMwg284/pJo7Qgf+2ceS+W1n8k2kGdtbTV GlnRbhQNXKPU67TsxYnBV4aDZESFW4Ei0R/c/ZTsYcA4TNWvIBPyUuVsRPMjtdeG OOh/bBXkUHov7Kh3uLNeBJIu+qSKACjecYMv+ljyH5GIdH5q8xh6o1DpGri/ZOYO R10ONWvYcAM/DMqjSjRHaiRWyRalJt3EypKq24yV0K88psENsQtTrdLjFpZ1V2vV XbFPg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=buG2nrPfJgaghtheP7ARAozSU662XKXLR25XnLaEj ww=; b=pssB0Bv/0GSQLFXAmpFYw2QczIE1Zc7keuvECndSk9PA3PWdf9KTybpss KYTQO1oZRp9/FOgAjWkGcNHszjLGxsRUm5l/ZYu9uDoP4IRB26gF77FsnoMGZr7P /rmPvHbjUaBemjye50CMi5koCz3g3LBmmsGcRDyWcgZqJrFwFs8TaoOKDJP1J9S+ 9layaE+0lMDbge26T/0nX7OXcEKPjimplHfOFHSmlHJiCoF849aLLSJXzaWlYfh5 tQP/Bj5TaumG20yv462pQGHunp3l5gV5fJT8aSqfhqn6y0rcoUJFxgzemY+4R/gD Nmamt33AMB/ng5pRhoRZj5Y7mkOdw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrkeejgddugedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvdduvddrudegiedrvd duleenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.146.219]) by mail.messagingengine.com (Postfix) with ESMTPA id 513B88005B; Tue, 22 Oct 2019 15:48:42 -0400 (EDT) Subject: Re: A question about sequences and backup/restore cycles To: stan References: <20191022001331.GC10733@panix.com> <20191022113214.GA19088@panix.com> <5805b200-6569-072c-f2c5-5462361e626c@aklaver.com> <20191022174827.GB1406@panix.com> Cc: pgsql-general From: Adrian Klaver Message-ID: Date: Tue, 22 Oct 2019 12:48:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20191022174827.GB1406@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/22/19 10:48 AM, stan wrote: Please reply to list also: Ccing list. > > Sorry if my description was not clear. > > No, we do not mix test, and production data. Let me try to clarify the > question. Looking at a pg_dump, I see the following: > > > CREATE SEQUENCE public.customer_key_serial > START WITH 1 > INCREMENT BY 1 > NO MINVALUE > NO MAXVALUE > CACHE 1; > > > Yet, in the same pg_dump file I have: > > > > > COPY public.customer (customer_key, cust_no, name, c_type, location, > bill_address_1, bill_address_2, bill_city, bill_state, bill_zip, > bill_country, bill_attention, bill_addressee, ship_address_1, > ship_address_2, ship_addressee, ship_attention, ship_city, ship_state, > ship_zip, office_phone_area_code, office_phone_exchange, > office_phone_number, office_phone_extension, cell_phone_area_code, > cell_phone_exchange, cell_phone_number, ship_phone_area_code, > ship_phone_exchange, ship_phone_number, ship_phone_extension, > fax_phone_area_code, fax_phone_exchange, fax_phone_number, status, modtime) > FROM stdin; > 1 12 Made Up Inc. INDUSTRIAL_CONVEYOR \N 101 Nowhere > Ave. \N LaGrange GA 00000 \N \N \N > \N \N \N \N \N \N 00000 \N \N \N > \N \N \N \N \N \N \N \N \N > \N \N ACTIVE 2019-09-30 23:55:04.594203+00 > 2 5 Jimmys Favorite Customer. PLASTICS \N > 56 Somewhere St. \N No Such City SC 00000 \N > \N \N \N \N \N \N \N \N 00000 > \N \N \N \N \N \N \N \N \N > \N \N \N \N \N ACTIVE 2019-09-30 > 23:55:04.636827+00 > > So it appears to me the customer table is going to get (correctly) populated > with the originally generated keys, yet the sequence will want to return a 1 > the next time it is called, when a new customer gets inserted. > > Am I missing something here? > Yes something like this, in dump file, for non-serial sequence: CREATE SEQUENCE public.plant1_p_item_no_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; SELECT pg_catalog.setval('public.plant1_p_item_no_seq', 5509, true); or for serial sequence: CREATE SEQUENCE public.avail_headers_line_id_seq AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; ALTER TABLE ONLY public.avail_headers ALTER COLUMN line_id SET DEFAULT nextval('public.avail_headers_line_id_seq'::regclass); SELECT pg_catalog.setval('public.avail_headers_line_id_seq', 53, true); If you want to see how things are run on a higher level do something like: pg_dump -Fc -d some_db -f db.out pg_restore -l db_out > db_toc.txt -l on pg_restore creates a TOC(table of contents) showing the ordering of the schema recreation. -- Adrian Klaver adrian.klaver@aklaver.com