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 1iN0sq-0002dz-RD for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 20:36:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iN0so-0007Uw-4C for pgsql-general@arkaria.postgresql.org; Tue, 22 Oct 2019 20:35:58 +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 1iN0sn-0007Up-N3 for pgsql-general@lists.postgresql.org; Tue, 22 Oct 2019 20:35:57 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iN0sk-00020x-TQ for pgsql-general@postgresql.org; Tue, 22 Oct 2019 20:35:56 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46yQJ94rR9z12qj; Tue, 22 Oct 2019 16:35:53 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46yQJ9458Nz1ZVj; Tue, 22 Oct 2019 16:35:53 -0400 (EDT) Date: Tue, 22 Oct 2019 16:35:53 -0400 From: stan To: Adrian Klaver Cc: pgsql-general@postgresql.org, crodmail@gmail.com, docrtp@gmail.com, stanbrow@gmail.com Subject: Re: A question about sequences and backup/restore cycles Message-ID: <20191022203553.GA6369@panix.com> References: <20191022001331.GC10733@panix.com> <20191022113214.GA19088@panix.com> <5805b200-6569-072c-f2c5-5462361e626c@aklaver.com> <20191022174827.GB1406@panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Oct 22, 2019 at 12:48:41PM -0700, Adrian Klaver wrote: > On 10/22/19 10:48 AM, stan wrote: > Please reply to list also: > Ccing list. >=20 >=20 > >=20 > > Sorry if my description was not clear. > >=20 > > 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: > >=20 > >=20 > > CREATE SEQUENCE public.customer_key_serial > > START WITH 1 > > INCREMENT BY 1 > > NO MINVALUE > > NO MAXVALUE > > CACHE 1; > >=20 > >=20 > > Yet, in the same pg_dump file I have: > >=20 > >=20 > >=20 > >=20 > > 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, modt= ime) > > FROM stdin; > > 1 12 Made Up Inc. INDUSTRIAL_CONVEYOR \N 101 Now= here > > 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 000= 00 > > \N \N \N \N \N \N \N \N \N > > \N \N \N \N \N ACTIVE 2019-09-30 > > 23:55:04.636827+00 > >=20 > > So it appears to me the customer table is going to get (correctly) popu= lated > > with the originally generated keys, yet the sequence will want to retur= n a 1 > > the next time it is called, when a new customer gets inserted. > >=20 > > Am I missing something here? > >=20 >=20 > Yes something like this, in dump file, for non-serial sequence: >=20 > CREATE SEQUENCE public.plant1_p_item_no_seq > START WITH 1 > INCREMENT BY 1 > NO MINVALUE > NO MAXVALUE > CACHE 1; >=20 > SELECT pg_catalog.setval('public.plant1_p_item_no_seq', 5509, true); >=20 > or for serial sequence: >=20 > CREATE SEQUENCE public.avail_headers_line_id_seq > AS integer > START WITH 1 > INCREMENT BY 1 > NO MINVALUE > NO MAXVALUE > CACHE 1; >=20 > ALTER TABLE ONLY public.avail_headers ALTER COLUMN line_id SET DEFAULT > nextval('public.avail_headers_line_id_seq'::regclass); >=20 >=20 > SELECT pg_catalog.setval('public.avail_headers_line_id_seq', 53, true); >=20 > If you want to see how things are run on a higher level do something like: >=20 > pg_dump -Fc -d some_db -f db.out >=20 > pg_restore -l db_out > db_toc.txt >=20 > -l on pg_restore creates a TOC(table of contents) showing the ordering of > the schema recreation. >=20 Oh, excellent.=7F!! Thanks for the patience to teach me about this. Does make me wonder what the vendor did to create our issue on their database. --=20 "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin