Re: UUID/GUID information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux