如何在已经安装好的PostgreSQL14中安装uuid 扩展

news2024/10/5 19:10:29

当前环境

             PG14.8 +LINUX 8.8

存在问题:

           开发人员问,PG中,支持 生成UUID吗,具体是什么,答,类似这个函数  uuid_generate_v4()
           看了一下, select uuid_generate_v4();会报错,找不到该函数
           原来postgresql 14 默认是没有该功能,但是可以通过扩展uuid-ossp来实现
 

解决办法


   由于PG是通过源码安装的,
   源码中已经有这个源码包了,不需要到处去找
  位置在:
  /postgresql/soft/postgresql-14.8/contrib/uuid-ossp

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

      postgres=# \dx
                 List of installed extensions
          Name   | Version |   Schema   |         Description         
        ---------+---------+------------+------------------------------
        plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
        (1 row)

           可以看到postgresql目前没有安装uuid-ossp扩展。
 

   2.检查是否有可用安装的扩展UUID-OSSP

      --查看当前可用的扩展

postgres=# select * from pg_available_extensions;

        name        | default_version | installed_version |                                comment                                 

--------------------+-----------------+-------------------+------------------------------------------------------------------------

plpgsql            | 1.0             | 1.0               | PL/pgSQL procedural language

plperl             | 1.0             |                   | PL/Perl procedural language

plperlu            | 1.0             |                   | PL/PerlU untrusted procedural language

plpython2u         | 1.0             |                   | PL/Python2U untrusted procedural language

plpythonu          | 1.0             |                   | PL/PythonU untrusted procedural language

adminpack          | 2.1             |                   | administrative functions for PostgreSQL

amcheck            | 1.3             |                   | functions for verifying relation integrity

bloom              | 1.0             |                   | bloom access method - signature file based index

btree_gin          | 1.3             |                   | support for indexing common datatypes in GIN

btree_gist         | 1.6             |                   | support for indexing common datatypes in GiST

citext             | 1.6             |                   | data type for case-insensitive character strings

cube               | 1.5             |                   | data type for multidimensional cubes

dblink             | 1.2             |                   | connect to other PostgreSQL databases from within a database

dict_int           | 1.0             |                   | text search dictionary template for integers

dict_xsyn          | 1.0             |                   | text search dictionary template for extended synonym processing

earthdistance      | 1.1             |                   | calculate great-circle distances on the surface of the Earth

file_fdw           | 1.0             |                   | foreign-data wrapper for flat file access

fuzzystrmatch      | 1.1             |                   | determine similarities and distance between strings

hstore             | 1.8             |                   | data type for storing sets of (key, value) pairs

intagg             | 1.1             |                   | integer aggregator and enumerator (obsolete)

intarray           | 1.5             |                   | functions, operators, and index support for 1-D arrays of integers

isn                | 1.2             |                   | data types for international product numbering standards

lo                 | 1.1             |                   | Large Object maintenance

ltree              | 1.2             |                   | data type for hierarchical tree-like structures

old_snapshot       | 1.0             |                   | utilities in support of old_snapshot_threshold

pageinspect        | 1.9             |                   | inspect the contents of database pages at a low level

pg_buffercache     | 1.3             |                   | examine the shared buffer cache

pg_freespacemap    | 1.2             |                   | examine the free space map (FSM)

seg                | 1.4             |                   | data type for representing line segments or floating-point intervals

pg_prewarm         | 1.2             |                   | prewarm relation data

pg_stat_statements | 1.9             |                   | track planning and execution statistics of all SQL statements executed

pg_surgery         | 1.0             |                   | extension to perform surgery on a damaged relation

pg_trgm            | 1.6             |                   | text similarity measurement and index searching based on trigrams

pgcrypto           | 1.3             |                   | cryptographic functions

pgrowlocks         | 1.2             |                   | show row-level locking information

pgstattuple        | 1.5             |                   | show tuple-level statistics

pg_visibility      | 1.2             |                   | examine the visibility map (VM) and page-level visibility info

postgres_fdw       | 1.1             |                   | foreign-data wrapper for remote PostgreSQL servers

autoinc            | 1.0             |                   | functions for autoincrementing fields

insert_username    | 1.0             |                   | functions for tracking who changed a table

moddatetime        | 1.0             |                   | functions for tracking last modification time

refint             | 1.0             |                   | functions for implementing referential integrity (obsolete)

tablefunc          | 1.0             |                   | functions that manipulate whole tables, including crosstab

tcn                | 1.0             |                   | Triggered change notifications

tsm_system_rows    | 1.0             |                   | TABLESAMPLE method which accepts number of rows as a limit

tsm_system_time    | 1.0             |                   | TABLESAMPLE method which accepts time in milliseconds as a limit

unaccent           | 1.1             |                   | text search dictionary that removes accents

sslinfo            | 1.2             |                   | information about SSL certificates

xml2               | 1.1             |                   | XPath querying and XSLT

bool_plperlu       | 1.0             |                   | transform between bool and plperlu

bool_plperl        | 1.0             |                   | transform between bool and plperl

hstore_plperl      | 1.0             |                   | transform between hstore and plperl

hstore_plperlu     | 1.0             |                   | transform between hstore and plperlu

jsonb_plperlu      | 1.0             |                   | transform between jsonb and plperlu

jsonb_plperl       | 1.0             |                   | transform between jsonb and plperl

hstore_plpythonu   | 1.0             |                   | transform between hstore and plpythonu

hstore_plpython2u  | 1.0             |                   | transform between hstore and plpython2u

hstore_plpython3u  | 1.0             |                   | transform between hstore and plpython3u

jsonb_plpythonu    | 1.0             |                   | transform between jsonb and plpythonu

jsonb_plpython2u   | 1.0             |                   | transform between jsonb and plpython2u

jsonb_plpython3u   | 1.0             |                   | transform between jsonb and plpython3u

ltree_plpythonu    | 1.0             |                   | transform between ltree and plpythonu

ltree_plpython2u   | 1.0             |                   | transform between ltree and plpython2u

ltree_plpython3u   | 1.0             |                   | transform between ltree and plpython3u

(64 rows)


可以看到postgres目前并没有可用的uuid-ossp扩展。
此时,直接创建uuid-ossp会报错,如:

postgres=# create extension "uuid-ossp";
ERROR:  could not open extension control file "/postgres/pg14/share/extension/uuid-ossp.control": No such file or directory
postgres=#

注意:
要用双引号将uuid-ossp引起来,因为有个中划线“-”。
 

3.PG安装UUID选项



注意:以ROOT用户去编译

su - root

cd /postgresql/soft/postgresql-14.8/
./configure --prefix=/postgresql/pg14 --with-uuid=ossp   #prefix 安装目录

该操作只是在已安装完PG后,把uuid-ossp编译安装进了PG,不影响现有库。

 

4.源码编译UUID 


#进入扩展目录
# cd  /postgresql/soft/postgresql-14.8/contrib/uuid-ossp

#编译安装
# make && make install
 

5.配置UUID的软链接



--这里需要创建软连接,否则,后面创建扩展,会报错 :找不到 /postgresql/pg14/lib/libuuid.so.16

#  find / -name libuuid.so.16

/postgresql/soft/uuid/uuid-1.6.2/.libs/libuuid.so.16

# ln -s /postgresql/soft/uuid/uuid-1.6.2/.libs/libuuid.so.16 /postgresql/pg14/lib/

 

6.创建扩展



查看可用扩展
postgres=# select * from pg_available_extensions;
...
uuid-ossp          | 1.1             |                   | generate universally unique identifiers

可以看到已经有扩展uuid-ossp了。下面可以创建了。


创建扩展
postgres=# create extension "uuid-ossp";
CREATE EXTENSION
 

7.使用UUID


安装扩展成功以后,就可以使用函数uuid_generate_v4()来生产uuid了。

postgres=# select uuid_generate_v4();
           uuid_generate_v4           
--------------------------------------
9ef673d2-3652-455c-8b6e-c634165f514b

(1 row)
 

可以看到,已经安装好了

-------------------------------------------

为了方便交流,我建立了一个微信群:水煮数据库,主要交流日常运维中用到的数据库相关问题,包含但不限于:ORACLE,PG,MYSQL,SQLSERVER,OB,TIDB,达梦,TDSQL,OPENGAUSS,人大金仓,GBASE等等,如果有兴趣交流,可以加我微信:zq24803366, 我可以拉你入群。
————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/cqsztech/article/details/138426614

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1649598.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

“视频号小店”和“抖音小店”新手做电商选择哪个更好?

哈喽~我是电商月月 做电商的老商家和,准备做电商的新手朋友都知道现在最大的电商平台就是“抖音小店” 但抖店小店毕竟发展了四年,流量多,商家也多,最近又崛起了一个新黑马“视频号小店” 那到底去哪个平台发展才有前景呢&…

QX-mini51学习---(2)点亮LED

目录 1什么是ed 2led工作参数 3本节相关原理图分析 4本节相关c 5实践 1什么是ed 半导体发光二极管,将电能转化为光能,耗电低,寿命长,抗震动 长正短负,贴片是绿点处是负极 2led工作参数 3本节相关原理图分析 当…

一文读懂Python的`__init__`,`__init__`方法的终极指南

大家好,今天给大家介绍一个Python中一个特殊的函数__init__。 在Python中,__init__方法是一个特殊的函数,它在创建类的新实例时自动调用。它的作用类似于其他编程语言中的构造函数,用于初始化对象的状态。这篇文章将带你深入了解…

LeetCode刷题记(五):121~150题

121. 买卖股票的最佳时机 给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从…

用PowerPoint创建毛笔字书写动画

先看看下面这个毛笔字书写动画: 这个动画是用PowerPoint创建的。下面介绍创建过程。 1、在任何一款矢量图片编辑软件中创建一个图片,用文字工具输入文字内容。我用的是InkScape。排好版后将图片保存为.svg格式的矢量图片文件。 2、打开PowerPoint&…

强一致性的皇冠:分布式事务模型的至高法则揭秘

关注微信公众号 “程序员小胖” 每日技术干货,第一时间送达! 引言 分布式事务模型是分布式系统设计的核心,关键在于保证数据一致性和事务完整性,尤其强调强一致性。诸如2PC、3PC、Saga、TCC等模型与协议,应运而生以解…

elementui+vue通过下拉框多选字段进行搜索模糊匹配

从字典中选择的值为["01","03"],在最开始的时候进行的处理是类似于表单提交的时候将json对象转换成了String类型 nature:["01","03"] this.queryParams.nature JSON.stringify(this.queryParams.nature); mapper层 <if test&quo…

keystone学习小结

1 keystone middleware 1.1 工作流程 middleware在客户端和服务端之间&#xff0c;会拦截客户端请求并判断请求身份是否是正确合法的&#xff0c;若是&#xff0c;则继续将请求发给其他middleware或app 具体看&#xff0c;干了这些事 1将请求里的auth header去除&#xff0c…

【FL常用插件#1】Ozone11臭氧的安装和使用

本文内容收集自互联网&#xff0c;仅供个人学习参考使用&#xff0c;不允许用于商业用途&#xff0c;造成的侵权行为与本文作者无关 安装 VST2、VST3、AAX和NKS是音频技术界常见的几种插件格式&#xff0c;它们在功能和兼容性上有所不同&#xff1a; VST2 (Virtual Studio Tec…

QT--2

Qt界面设计 #include "widget.h" #include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent) {//窗口相关设置this->resize(680,520);this->setFixedSize(680,520);this->setWindowTitle("Tim");this->setWindowFla…

ES集群设置访问密码

1 新增配置 每个集群节点都需要设置&#xff0c;编辑 elasticsearch.yml 文件&#xff1a; cd /home/isearch/es vi es-cluster-01/config/elasticsearch.yml vi es-cluster-02/config/elasticsearch.yml vi es-cluster-03/config/elasticsearch.yml # 设置启用了X-Pack安全…

Linux专栏10:Linux权限详解(上)

博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;Linux专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ Linux权限详解&#xff08;上&#xff09; 编号&#xff1a;10 文章…

CANdela/Diva系列1--CANdela Studio的基本介绍

大家好&#xff0c;这个系列主要给大家介绍跟诊断相关的Vector 工具CANdela和Diva&#xff0c;首先介绍CANdela。 目录 1.CANdela的简介&#xff1a; 2.如何打开CANdela 工程&#xff1a; 3.CANdela工程的详细介绍&#xff1a; 3.1 工具栏的介绍&#xff1a; 3.2 工作树的…

HarmonyOS开发案例:【电子相册】

介绍 如何实现一个简单的电子相册应用的开发&#xff0c;主要功能包括&#xff1a; 实现首页顶部的轮播效果。 实现页面跳转时共享元素的转场动画效果。 实现通过手势控制图片的放大、缩小、左右滑动查看细节等效果。 相关概念 [Swiper]&#xff1a;滑块视图容器&#x…

软件系统测试方案书(测试计划-Word原件)

2 引言 2.1 编写目的 2.3 测试人员 2.4 项目背景 2.5 测试目标 2.6 简写和缩略词 2.7 参考资料 2.8 测试提交文档 2.9 测试进度 3 测试环境 3.1 软硬件环境 4 测试工具 5 测试策略 5.1 测试阶段划分及内容 5.1.1 集成测试 5.1.2 系统测试 5.1.2.1 功能测试 5.…

通过mask得到bbox(numpy实现)

在SAM的加持下&#xff0c;我们很容易得到物体的mask&#xff0c;但是物体的bbox信息通常也很有用。那么&#xff0c;我们可以写一个函数&#xff0c;立马可以通过mask得到bbox。 代码如下&#xff1a; import numpy as npdef mask2bbox(mask):nonzero_indices np.nonzero(m…

阿里云CentOS 7.9 64位 Liunx 安装redis

具体的步骤如下&#xff1a; 添加 EPEL 仓库&#xff0c;因为 Redis 在标准的 CentOS 仓库中不可用&#xff1a; sudo yum install epel-release安装 Redis&#xff1a; sudo yum install redis启动 Redis 服务&#xff1a; sudo systemctl start redis如果你想让 Redis 在…

python中numpy库使用

array数组 生成array数组 将list转化为array数组 import numpy as np np.array([1,2],typenp.int32)其中dtype定义的是元素类型&#xff0c;np.int32指32位的整形 如果直接定义dtypeint 默认的是32位整形。 zeors和ones方法 zeros()方法&#xff0c;该方法和ones()类似&a…

Unity EventSystem入门

概述 相信在学习Unity中&#xff0c;一定有被UI事件困扰的时候把&#xff0c;当添加UICanvas的时候&#xff0c;Unity会为我们自动添加EventSystem&#xff0c;这个是为什么呢&#xff0c;Unity的UI事件是如何处理的呢&#xff0c;在使用各个UI组件的时候&#xff0c;一定有不…

35 信号处理

什么时候捕捉 如果信号的处理动作是用户自定义函数&#xff0c;在信号递达时就调用这个函数&#xff0c;称为捕捉信号&#xff0c;由于信号处理函数的代码是在用户空间的&#xff0c;处理过程比较复杂&#xff0c;举例如下&#xff1a;用户程序注册了SIGQUIT信号的处理函数sig…