Re: How to generate unique hash-type id?

From: Joe Kramer <cckramer(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to generate unique hash-type id?
Date: 2010-01-29 10:21:00
Message-ID: b4c00a111001290221rf2c4333wa266ec13fde7e8b0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

We have bunch of servers running the app and rebuilding postgres with
support for ossp_uuid on all servers is time consuming.
Is there a way of doing it without third party dependency like
ossp_uuid? Should I just run md5(random number), will itbe the same ?.
According to description it seems that all uuid_generate_v4() does is
simply generate md5 of random number.

Thanks.

On Fri, Jan 29, 2010 at 8:31 PM, Adrian von Bidder <avbidder(at)fortytwo(dot)ch> wrote:
>
> Hi,
>
> On Friday 29 January 2010 09.20:33 Joe Kramer wrote:
>> I need to generate unique id which is not guessable unlike
>> serial(integer) type. I need an id in format like md5 hash of random
>> number.
>> On top of that I need this id to be unique across multiple tables.
>
> Have a look at http://www.postgresql.org/docs/8.3/static/uuid-ossp.html
>
> The usual approach is that (given a sensible random generator[1]) uuid are
> assumed to be unique[2].  So you don't need to check because the probability
> of collisions is so small that for practical purposes you can just ignore
> it.
>
> (If your engineer's mind balks at this, consider that you're trusting this
> already when you use digital cryptography / signatures, for example https
> certificates.)
>
> I haven't looked at this module myself, but from the experience with
> generating gpg keys on an appliance:  if you need lots of randomness, the
> geneation of random numbers might be your bottleneck.  OTOH, our platform
> didn't have disks and usually there was no network traffic while your
> average db server has both, and on many systems there is a hardware random
> generator, so this might not be an issue.
>
> cheers
> -- vbi
>
>
> [1] like, for example: http://www.dilbert.com/strips/comic/2001-10-25/
> [2] you'll want v4 uuids
> --
> Linus has opinions, I have opinions, everybody else has opinions, and
> the only consistency here is that most of us are wrong most of the time.
>        -- Andrew Morton, OLS 2004
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian von Bidder 2010-01-29 11:20:59 Re: How to generate unique hash-type id?
Previous Message 沈雷 2010-01-29 09:45:08 Re: Output float number with hex format