postgresql uuid扩展的安装
postgresql uuid扩展的安装,由于PG是通过源码安装的,源码中已经有这个源码包了,不需要到处去找,(以笔者的版本)位置在:/postgresql/soft/postgresql-16.4/contrib/uuid-ossp
1.检查是否已安装扩展uuid-ossp
-- 已安装扩展
select * from pg_extension ;
2.检查是否有可用安装的扩展UUID-OSSP
- -- 可用扩展
- select * from pg_available_extensions where name like '%uuid%';
- name|default_version|installed_version|comment|
- ----+---------------+-----------------+-------+
复制代码 可以看到postgres目前并没有可用的uuid-ossp扩展。
此时,直接创建uuid-ossp会报错,如:- create extension "uuid-ossp";
- SQL Error [0A000]: ERROR: extension "uuid-ossp" is not available
- Detail: Could not open extension control file "/usr/local/pgsql16/server/share/extension/uuid-ossp.control": No such file or directory.
- Hint: The extension must first be installed on the system where PostgreSQL is running.
复制代码 注意:
要用双引号将uuid-ossp引起来,因为有个中划线“-”。
3.PG安装UUID选项
中间遇到这个错误,折腾了很久,#error please use configure s --with-uuid switch to select a UUID library,ubuntu下需要安装一下依赖,尤其是libicu-dev这个依赖,折腾了很久很久- apt update
- apt install libicu-dev -y
- apt install libossp-uuid-dev e2fslibs-dev uuid-dev
复制代码- -- 进入PostgreSQL的源码目录
- cd /usr/local/postgresql_install_package/postgresql-16.4
-
- -- prefix 安装目录
- -- 该操作只是在已安装完PG后,把uuid-ossp编译安装进了PG,PG编译后的目录,不影响现有库。
- ./configure --prefix=/usr/local/pgsql16/server --with-uuid=ossp
复制代码
4.源码编译UUID
cd /usr/local/postgresql_install_package/postgresql-16.4/contrib/uuid-ossp
--编译安装
make && make install
编译之后请确保编译文件uuid-ossp.so的位置,在构建系统./configure --prefix=指定的路径要为PostgreSQL编译的根目录,否则这个uuid-ossp.so变编译到其他路径下去,这个地方要注
是否在PostgreSQL的编译目录/usr/local/pgsql16/server/lib路径下
5.创建扩展
查看可用扩展- select * from pg_available_extensions where name like '%uuid%';
- ...
- uuid-ossp | 1.1 | | generate universally unique identifiers
复制代码 可以看到已经有扩展uuid-ossp了。下面可以创建了。
创建扩展- create extension "uuid-ossp";
复制代码
6.测试uuid函数
- select uuid_generate_v4();
- uuid_generate_v4 |
- ------------------------------------+
- bb75debd-23fd-4757-bf34-354ed44dcf63|
复制代码
参考
https://blog.csdn.net/cqsztech/article/details/138546381
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |