Postgresql 中文操作指南
F.49. uuid-ossp — a UUID generator #
uuid-ossp 模块提供函数,使用几种标准算法来生成通用唯一标识符 (UUID)。还有一些函数生成某些特殊的 UUID 常量。此模块仅适用于核心 PostgreSQL 中无法满足的特殊需求。请参阅 Section 9.14 中内置生成 UUID 的方法。
The uuid-ossp 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 PostgreSQL. See Section 9.14 for built-in ways to generate UUIDs.
此模块被认为是“受信任的”,也就是说,它可以由在当前数据库上具有 CREATE 权限的非超级用户安装。
This module is considered “trusted”, that is, it can be installed by non-superusers who have CREATE privilege on the current database.
F.49.1. uuid-ossp Functions #
Table F.34 显示了可用于生成 UUID 的函数。相关的标准 ITU-T Rec. X.667、ISO/IEC 9834-8:2005 和 RFC 4122 指定了四种用于生成 UUID 的算法,其版本编号分别为 1、3、4 和 5。(没有版本 2 算法。)这些算法中的每一个都适用于不同的应用程序集。
Table F.34 shows the functions available to generate UUIDs. The relevant standards ITU-T Rec. X.667, ISO/IEC 9834-8:2005, and RFC 4122 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.
Table F.34. Functions for UUID Generation
Function Description |
uuid_generate_v1 () → uuid 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. |
uuid_generate_v1mc () → uuid Generates a version 1 UUID, but uses a random multicast MAC address instead of the real MAC address of the computer. |
uuid_generate_v3 ( namespace uuid, name text ) → uuid 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 uuid_ns*()_ functions shown in Table F.35. (It could be any UUID in theory.) The name is an identifier in the selected namespace. For example: SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org'); 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. |
uuid_generate_v4 () → uuid Generates a version 4 UUID, which is derived entirely from random numbers. |
uuid_generate_v5 ( namespace uuid, name text ) → uuid 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. |
Table F.35. Functions Returning UUID Constants
Function Description |
uuid_nil () → uuid Returns a “nil” UUID constant, which does not occur as a real UUID. |
uuid_ns_dns () → uuid Returns a constant designating the DNS namespace for UUIDs. |
uuid_ns_url () → uuid Returns a constant designating the URL namespace for UUIDs. |
uuid_ns_oid () → uuid 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 PostgreSQL.) |
uuid_ns_x500 () → uuid Returns a constant designating the X.500 distinguished name (DN) namespace for UUIDs. |
F.49.2. Building uuid-ossp #
从历史上看,此模块依赖于 OSSP UUID 库,这解释了该模块的名称。虽然 OSSP UUID 库仍可以在 http://www.ossp.org/pkg/lib/uuid/ 处找到,但它维护得不够好,并且越来越难以移植到更新的平台。现在可以 uuid-ossp 在某些平台上无需 OSSP 库构建。在 FreeBSD 和某些其他源自 BSD 的平台上,核心 libc 库中包含合适的 UUID 创建函数。在 Linux、macOS 和某些其他平台上,合适的函数在 libuuid 库中提供,该库最初来自 e2fsprogs 项目(尽管在现代 Linux 系统中它被视为 util-linux-ng 的一部分)。调用 configure 时,指定 —with-uuid=bsd 以使用 BSD 函数,或 —with-uuid=e2fs 以使用 e2fsprogs' 的 libuuid,或 —with-uuid=ossp 以使用 OSSP UUID 库。一台机器上可能有多个此类库可用,因此 configure 不会自动选择一个。
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 http://www.ossp.org/pkg/lib/uuid/, it is not well maintained, and is becoming increasingly difficult to port to newer platforms. uuid-ossp 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 libc library. On Linux, macOS, and some other platforms, suitable functions are provided in the libuuid library, which originally came from the e2fsprogs project (though on modern Linux it is considered part of util-linux-ng). When invoking configure, specify —with-uuid=bsd to use the BSD functions, or —with-uuid=e2fs to use e2fsprogs' libuuid, or —with-uuid=ossp to use the OSSP UUID library. More than one of these libraries might be available on a particular machine, so configure does not automatically choose one.
F.49.3. Author #
Peter Eisentraut < link:mailto:peter_e@gmx.net[peter_e@gmx.net]>
Peter Eisentraut <link:mailto:peter_e@gmx.net[peter_e@gmx.net]>