一 准备文件
链接:https://pan.baidu.com/s/1xmUCDSJ2TPT17FuzhdMfog
提取码:y1qj
二 上传文件到pg服务器
将 uuid-ossp.so 文件放在 /usr/local/pgsql/lib 目录下,并赋予执行权限
[postgres@localhost lib]$ cd /usr/local/pgsql/lib
[postgres@localhost lib]$ rz
[postgres@localhost lib]$ chmod +x uuid-ossp.so
将其他文件放在 /usr/local/pgsql/share/extension 目录下
[postgres@localhost lib]$ cd /usr/local/pgsql/share/extension
[postgres@localhost extension]$ rz
此时执行select * from pg_available_extensions where name like '%uuid%';便能看到该插件了:
三 安装 uuid-oss 插件
create extension IF NOT EXISTS "uuid-ossp";
安装完后,就能通过select * from pg_extension;查看了
/*
注意,如果是主从架构,需要也在从库上传相关文件,但是只需要在主库执行create extension集控,它会自动同步到从库上。而且如果在从库上手动建也会报错:
ERROR:cannot execute create extension in a read-only transaction.
注意,还需要\c切换到业务库,执行create extension IF NOT EXISTS "uuid-ossp";命令,否则这些用户在pg_extension里查不到该插件,并且无法使用该插件,会报错:
no function matches the given name and argume
*/
四 使用该插件
select uuid_generate_v4();