找回密码
 立即注册
首页 业界区 安全 PostgreSQL UUID扩展安装

PostgreSQL UUID扩展安装

哈妙思 2025-6-17 12:34:00
postgresql uuid扩展的安装
postgresql uuid扩展的安装,由于PG是通过源码安装的,源码中已经有这个源码包了,不需要到处去找,(以笔者的版本)位置在:/postgresql/soft/postgresql-16.4/contrib/uuid-ossp
1.png

1.检查是否已安装扩展uuid-ossp

-- 已安装扩展
select * from pg_extension ;
2.检查是否有可用安装的扩展UUID-OSSP
  1. -- 可用扩展
  2. select * from pg_available_extensions where name like '%uuid%';
  3. name|default_version|installed_version|comment|
  4. ----+---------------+-----------------+-------+
复制代码
可以看到postgres目前并没有可用的uuid-ossp扩展。
此时,直接创建uuid-ossp会报错,如:
  1. create extension "uuid-ossp";
  2. SQL Error [0A000]: ERROR: extension "uuid-ossp" is not available
  3.   Detail: Could not open extension control file "/usr/local/pgsql16/server/share/extension/uuid-ossp.control": No such file or directory.
  4.   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这个依赖,折腾了很久很久
  1. apt update
  2. apt install libicu-dev -y
  3. apt install libossp-uuid-dev e2fslibs-dev uuid-dev
复制代码
2.png
  1. -- 进入PostgreSQL的源码目录
  2. cd /usr/local/postgresql_install_package/postgresql-16.4
  3.  
  4. -- prefix 安装目录
  5. -- 该操作只是在已安装完PG后,把uuid-ossp编译安装进了PG,PG编译后的目录,不影响现有库。
  6. ./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路径下
3.png

 
5.创建扩展

查看可用扩展
  1. select * from pg_available_extensions where name like '%uuid%';
  2. ...
  3. uuid-ossp | 1.1 | | generate universally unique identifiers
复制代码
可以看到已经有扩展uuid-ossp了。下面可以创建了。
 
创建扩展
  1. create extension "uuid-ossp";
复制代码
 
6.测试uuid函数
  1. select uuid_generate_v4();
  2. uuid_generate_v4                    |
  3. ------------------------------------+
  4. bb75debd-23fd-4757-bf34-354ed44dcf63|
复制代码
 
 
参考
https://blog.csdn.net/cqsztech/article/details/138546381

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册