pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: David Busby <Busby@pnts.com>
To: Postgres-PHP <pgsql-php@postgresql.org>
Subject: Re: UUID/GUID information
Date: Thu, 30 May 2002 16:34:52 -0700
Message-ID: <200205301634.52634.josh@agliodbs.com> (raw)
In-Reply-To: <35363AB30BF2D311B73C0050DAB989F063C3@SEAPDC01>
References: <35363AB30BF2D311B73C0050DAB989F063C3@SEAPDC01>


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@agliodbs.com
    and data management solutions 	(415) 565-7293
   for law firms, small businesses 	 fax 621-2533
    and non-profit organizations. 	San Francisco




view thread (7+ messages)  latest in thread

Message-ID: <200205301634.52634.josh@agliodbs.com>
Permalink:  ../200205301634.52634.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200205301634.52634.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: josh@agliodbs.com, Busby@pnts.com
  Subject: Re: UUID/GUID information
  In-Reply-To: <200205301634.52634.josh@agliodbs.com>
  References: <35363AB30BF2D311B73C0050DAB989F063C3@SEAPDC01> <200205301634.52634.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox