Re: UUID/GUID information

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: David Busby <Busby(at)pnts(dot)com>, 'Postgres-PHP' <pgsql-php(at)postgresql(dot)org>
Subject: Re: UUID/GUID information
Date: 2002-05-30 23:34:52
Message-ID: 200205301634.52634.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php


David,

> Perhaps I should have mentioned that I'm building a multi-database solution
> (20+ databases) in which all 20+ DBs must use the same identifier across
> databases for some objects (ex: Automobile Brands) but their own identifier
> for their own data (ex: Accouts/Clients) this way when the child database
> publish to the master there is no possiblity of some object having the same
> identifer as another...and the object identifier can stay the same across
> all 20+ DBs.
>
> The GUID from Micro$oft is formatted like
> {01234567-89AB-CDEF-0123-456789ABCDEF} it represents a 16 byte number that
> is again unique in spacetime. Is there PostgreSQL solution for something
> like that or will I have to come up with my own.

In that case, you should have the budget for some programming, yes?

The answer is quite simple:
1. You set up a universal sequence as I described.
2. You give each server its own 4-byte Server ID, and put it in the table
server_id. Use whatever number you want; I might suggest something
based on the IP address of the machine (though unfortunately IP
addresses
are 4 bytes unsigned, so you can't use them directly).
3. You create a function as follows:

CREATE FUNCTION unique_id () RETURNS INT8 AS '
SELECT ((server_id.server_id::INT8 * (2^31 - 1)::INT8) +
NEXTVAL('universal_sq'))
FROM server_id; '
LANGUAGE 'sql';

(Somebody correct my math if I'm off, here)

Alternately, you could use a random 4-byte number instead of the server_id,
which wouldn't be perfect but would give you only about a 20 in 2.4 billion
chance of a conflict.

--
-Josh Berkus

--
-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Andrew McMillan 2002-05-31 12:49:00 Re: UUID/GUID information
Previous Message Keary Suska 2002-05-30 21:16:28 Re: UUID/GUID information