uuid-ossp

os: centos 7.4
postgresql: 9.16

postgresql 自带的 extension 叫做 uuid-ossp,是用来产生通用唯一标识符。

安装uuid依赖包

# yum install uuid uuid-devel

如果没有安装os的 uuid、uuid-devel,就会报如下错误。

checking for uuid_export in -lossp-uuid... no
checking for uuid_export in -luuid... no
configure: error: library 'ossp-uuid' or 'uuid' is required for OSSP UUID

configure 时添加 --with-uuid=ossp

# cd /tmp
# wget https://ftp.postgresql.org/pub/source/v9.6.9/postgresql-9.6.9.tar.gz
# tar -zxvf ./postgresql-9.6.9.tar.gz
# cd postgresql-9.6.9
# ./configure --prefix=/usr/pgsql-9.6 --with-perl --with-tcl --with-python --with-openssl --with-pam \
--without-ldap --with-libxml --with-libxslt --with-uuid=ossp

# make world
# make install-world

查看 uuid-ossp

# cd /usr/pgsql-9.6/lib/
# ls -l |grep -i uuid
-rwxr-xr-x 1 root root  14384 Jun 21 18:25 uuid-ossp.so

# cd /usr/pgsql-9.6/share/extension/
# ls -l |grep -i uuid
-rw-r--r-- 1 root root   688 Jun 21 18:25 uuid-ossp--1.0--1.1.sql
-rw-r--r-- 1 root root  1516 Jun 21 18:25 uuid-ossp--1.1.sql
-rw-r--r-- 1 root root   163 Jun 21 18:25 uuid-ossp.control
-rw-r--r-- 1 root root   853 Jun 21 18:25 uuid-ossp--unpackaged--1.0.sql

创建 uuid-ossp extension

初始化数据库集群略。

postgres=# create database peiybdb;
CREATE DATABASE
postgres=# \c peiybdb
You are now connected to database "peiybdb" as user "postgres".
peiybdb=# select * from pg_available_extensions where name like '%uuid%';
   name    | default_version | installed_version |                     comment                     
-----------+-----------------+-------------------+-------------------------------------------------
 uuid-ossp | 1.1             |                   | generate universally unique identifiers (UUIDs)
(1 row)

peiybdb=# create extension "uuid-ossp";
CREATE EXTENSION

peiybdb=# \df
                                  List of functions
 Schema |        Name        | Result data type |    Argument data types    |  Type  
--------+--------------------+------------------+---------------------------+--------
 public | uuid_generate_v1   | uuid             |                           | normal
 public | uuid_generate_v1mc | uuid             |                           | normal
 public | uuid_generate_v3   | uuid             | namespace uuid, name text | normal
 public | uuid_generate_v4   | uuid             |                           | normal
 public | uuid_generate_v5   | uuid             | namespace uuid, name text | normal
 public | uuid_nil           | uuid             |                           | normal
 public | uuid_ns_dns        | uuid             |                           | normal
 public | uuid_ns_oid        | uuid             |                           | normal
 public | uuid_ns_url        | uuid             |                           | normal
 public | uuid_ns_x500       | uuid             |                           | normal
(10 rows)

这些函数的使用可以参考官网的uuid-ossp描述。

参考:
http://postgres.cn/docs/9.6/contrib.html
http://postgres.cn/docs/9.6/uuid-ossp.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据库人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值