X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 36FB53A1A7D for ; Fri, 14 Jan 2005 18:44:29 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 01991-02 for ; Fri, 14 Jan 2005 18:44:12 +0000 (GMT) Received: from mx-00.sil.at (mx-00.sil.at [62.116.68.196]) by svr1.postgresql.org (Postfix) with ESMTP id 527FC3A1D4F for ; Fri, 14 Jan 2005 18:44:08 +0000 (GMT) Received: (qmail-ldap/ctrl 88752 invoked from network); 14 Jan 2005 18:44:04 -0000 Received: from unknown (HELO jupiter.sonorys.at) ([213.235.243.42]) (envelope-sender ) by mx-00.sil.at (qmail-ldap-1.03) with SMTP for ; 14 Jan 2005 18:44:04 -0000 Received: from neptun.sonorys.at (neptun.sonorys.at [172.24.1.17]) by jupiter.sonorys.at (8.11.7+Sun/8.11.7) with ESMTP id j0EIiHs04186 for ; Fri, 14 Jan 2005 19:44:17 +0100 (MET) Received: by neptun.sonorys.at with Internet Mail Service (5.5.2653.19) id ; Fri, 14 Jan 2005 19:44:08 +0100 Message-ID: From: =?iso-8859-15?Q?K=D6PFERL_Robert?= To: "'pgsql-sql@postgresql.org'" Subject: Re: Column with recycled sequence value (solved (somehow)) Date: Fri, 14 Jan 2005 19:44:06 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200501/100 X-Sequence-Number: 19888 Thank you all for your thinkings. It seems like there's no realy good way to solve that kind of problem = (maybe used IDs). Thus I made a design change happen. We went to 64-Bit which should solve the problem until the computers already fellt into dust. > -----Original Message----- > From: PFC [mailto:lists@boutiquenumerique.com] > Sent: Freitag, 14. J=E4nner 2005 02:27 > To: Andrew Sullivan; 'pgsql-sql@postgresql.org' > Subject: Re: [SQL] Column with recycled sequence value >=20 >=20 >=20 > You could update all the fields which use this sequence=20 > number. You say =20 > you have a lot of activity so you must have mahy holes in=20 > your sequence, =20 > probably of the possible 2^32 values, only a fes millions are used. >=20 > You can do the following : >=20 > - Take down the database, back it up, and restart it=20 > with a single user, =20 > so only you can connect, using psql. > - Create a table : > CREATE TABLE translate ( new_id SERIAL PRIMARY KEY, old_id INTEGER, =20 > UNIQUE(old_id) ) WITHOUT OIDS; >=20 > - Insert into this table all the used sequence values=20 > you have in your =20 > database. If you have all the proper constraints, these=20 > should come from =20 > only one table, so it should be straightformard : >=20 > INSERT INTO translate (old_id) SELECT id FROM your_table; >=20 > Thus the "translate" table maps old id's to a new=20 > sequence that you just =20 > started, and that means your new id's will be compactly=20 > arranged, starting =20 > at 1. >=20 > - Update your existing table, joining it to the=20 > translate table, to =20 > replace the old id by the new id. >=20 >=20 > > On Thu, Jan 13, 2005 at 06:08:20PM +0100, K=D6PFERL Robert wrote: > >> Hi, > >> > >> suppose I have a let's say heavy used table. There's a=20 > column containing > >> UNIQUE in4 > >> values. The data type musn't exceed 32-Bit. Since however=20 > the table is =20 > >> heavy > >> used 2^32 will be reached soon and then? There are far less than =20 > >> 4G-records > >> saved thus these values may be reused. How can this be=20 > accomplished? > > > > You can set the sequence up to cycle (so once it gets to the end, = it > > wraps around to the beginning again). The keyword is CYCLE=20 > at CREATE > > SEQUENCE time. It defaults to NO CYCLE. > > > > One potential problem, of course, are collisions on the table, > > because some value wasn't cleared out. It sounds like you=20 > don't have > > that problem though. > > > > A > > >=20 >=20 >=20 > ---------------------------(end of=20 > broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to=20 > majordomo@postgresql.org >=20