postgresql 9.6 + uuid-ossp
生活随笔
收集整理的這篇文章主要介紹了
postgresql 9.6 + uuid-ossp
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
os: centos 7.4
postgresql: 9.16
postgresql 自帶的 extension 叫做 uuid-ossp,是用來產生通用唯一標識符。
安裝uuid依賴包
# yum install uuid uuid-devel
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
如果沒有安裝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
查看 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
總結
以上是生活随笔為你收集整理的postgresql 9.6 + uuid-ossp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么申请信用卡老是被秒拒?这些原因都有
- 下一篇: 上车准备