summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/uuid-ossp.sgml
blob: 26bfb908daea184aaede42a7f6044e3e9da1cdc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!-- doc/src/sgml/uuid-ossp.sgml -->

<sect1 id="uuid-ossp" xreflabel="uuid-ossp">
 <title>uuid-ossp</title>

 <indexterm zone="uuid-ossp">
  <primary>uuid-ossp</primary>
 </indexterm>

 <para>
  The <filename>uuid-ossp</filename> module provides functions to generate universally
  unique identifiers (UUIDs) using one of several standard algorithms.  There
  are also functions to produce certain special UUID constants.
  This module is only necessary for special requirements beyond what is
  available in core <productname>PostgreSQL</productname>.  See <xref
  linkend="functions-uuid"/> for built-in ways to generate UUIDs.
 </para>

 <para>
  This module is considered <quote>trusted</quote>, that is, it can be
  installed by non-superusers who have <literal>CREATE</literal> privilege
  on the current database.
 </para>

 <sect2>
  <title><literal>uuid-ossp</literal> Functions</title>

  <para>
   <xref linkend="uuid-ossp-functions"/> shows the functions available to
   generate UUIDs.
   The relevant standards ITU-T Rec. X.667, ISO/IEC 9834-8:2005, and
   <ulink url="https://tools.ietf.org/html/rfc4122">RFC 4122</ulink>
   specify four algorithms for generating UUIDs, identified by the
   version numbers 1, 3, 4, and 5.  (There is no version 2 algorithm.)
   Each of these algorithms could be suitable for a different set of
   applications.
  </para>

  <table id="uuid-ossp-functions">
   <title>Functions for UUID Generation</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>uuid_generate_v1</primary></indexterm>
        <function>uuid_generate_v1</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Generates a version 1 UUID.  This involves the MAC
        address of the computer and a time stamp.  Note that UUIDs of this
        kind reveal the identity of the computer that created the identifier
        and the time at which it did so, which might make it unsuitable for
        certain security-sensitive applications.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>uuid_generate_v1mc</primary></indexterm>
        <function>uuid_generate_v1mc</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Generates a version 1 UUID, but uses a random multicast
        MAC address instead of the real MAC address of the computer.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>uuid_generate_v3</primary></indexterm>
        <function>uuid_generate_v3</function> ( <parameter>namespace</parameter> <type>uuid</type>, <parameter>name</parameter> <type>text</type> )
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Generates a version 3 UUID in the given namespace using
        the specified input name.  The namespace should be one of the special
        constants produced by the <function>uuid_ns_*()</function> functions
        shown in <xref linkend="uuid-ossp-constants"/>.  (It could be any UUID
        in theory.)  The name is an identifier in the selected namespace.
       </para>
       <para>
        For example:

<programlisting>
SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
</programlisting>

        The name parameter will be MD5-hashed, so the cleartext cannot be
        derived from the generated UUID.
        The generation of UUIDs by this method has no random or
        environment-dependent element and is therefore reproducible.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_generate_v4</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Generates a version 4 UUID, which is derived entirely
        from random numbers.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_generate_v5</function> ( <parameter>namespace</parameter> <type>uuid</type>, <parameter>name</parameter> <type>text</type> )
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Generates a version 5 UUID, which works like a version 3
        UUID except that SHA-1 is used as a hashing method.  Version 5 should
        be preferred over version 3 because SHA-1 is thought to be more secure
        than MD5.
       </para></entry>
      </row>
     </tbody>
    </tgroup>
  </table>

  <table id="uuid-ossp-constants">
   <title>Functions Returning UUID Constants</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_nil</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Returns a <quote>nil</quote> UUID constant, which does not occur as a
        real UUID.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_ns_dns</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Returns a constant designating the DNS namespace for UUIDs.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_ns_url</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Returns a constant designating the URL namespace for UUIDs.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_ns_oid</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Returns a constant designating the ISO object identifier (OID) namespace for
        UUIDs.  (This pertains to ASN.1 OIDs, which are unrelated to the OIDs
        used in <productname>PostgreSQL</productname>.)
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>uuid_ns_x500</function> ()
        <returnvalue>uuid</returnvalue>
       </para>
       <para>
        Returns a constant designating the X.500 distinguished name (DN)
        namespace for UUIDs.
       </para></entry>
      </row>
     </tbody>
    </tgroup>
  </table>
 </sect2>

 <sect2>
  <title>Building <filename>uuid-ossp</filename></title>

  <para>
   Historically this module depended on the OSSP UUID library, which accounts
   for the module's name.  While the OSSP UUID library can still be found
   at <ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>, it is not well
   maintained, and is becoming increasingly difficult to port to newer
   platforms.  <filename>uuid-ossp</filename> can now be built without the OSSP
   library on some platforms.  On FreeBSD and some other BSD-derived
   platforms, suitable UUID creation functions are included in the
   core <filename>libc</filename> library.  On Linux, macOS, and some other
   platforms, suitable functions are provided in the <filename>libuuid</filename>
   library, which originally came from the <literal>e2fsprogs</literal> project
   (though on modern Linux it is considered part
   of <literal>util-linux-ng</literal>).  When invoking <filename>configure</filename>,
   specify <option>--with-uuid=bsd</option> to use the BSD functions,
   or <option>--with-uuid=e2fs</option> to
   use <literal>e2fsprogs</literal>' <filename>libuuid</filename>, or
   <option>--with-uuid=ossp</option> to use the OSSP UUID library.
   More than one of these libraries might be available on a particular
   machine, so <filename>configure</filename> does not automatically choose one.
  </para>
 </sect2>

 <sect2>
  <title>Author</title>

  <para>
   Peter Eisentraut <email>peter_e@gmx.net</email>
  </para>

 </sect2>

</sect1>