https://blog.csdn.net/ai2000ai/article/details/55253953?utm_source=blogxgwz0
https://www.cnblogs.com/kuang17/p/10084605.html
https://centos.pkgs.org/8/centos-powertools-x86_64/uuid-devel-1.6.2-43.el8.x86_64.rpm.html
postgresql12下安装uuid-ossp
一)检查是否已安装扩展uuid-ossp:
我们可以通过以下命令查看已有的扩展:
postgres=# select * from pg_extension;
oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
-------+---------+----------+--------------+----------------+------------+-----------+--------------
13579 | plpgsql | 10 | 11 | f | 1.0 | |
或者
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgres=# select * from pg_extension;
oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
-------+---------+----------+--------------+----------------+------------+-----------+--------------
13579 | plpgsql | 10 | 11 | f | 1.0 | |
或者
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
二)检查是否有可用来安装的扩展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
(5 rows)
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
(5 rows)
注意: 要用双引号将uuid-ossp引起来,因为有个中划线“-”。否则
postgres=# create extension uuid-ossp;
ERROR: syntax error at or near "-"
LINE 1: create extension uuid-ossp;
^
postgres=# create extension uuid-ossp;
ERROR: syntax error at or near "-"
LINE 1: create extension uuid-ossp;
^
(三)PG源码文件下编译安装扩展
安装uuid依赖包:
yum -y install e2fsprogs-devel uuid uuid-devel libuuid-devel
yum -y install e2fsprogs-devel uuid uuid-devel libuuid-devel
执行编译配置:
[root@Location-01 ~]# cd /usr/local/src/postgresql-12.2/
[root@Location-01 postgresql-12.2]# pwd
/usr/local/src/postgresql-12.2
[root@Location-01 postgresql-12.2]# ./configure --prefix=/opt/pgsql12.2 --with-uuid=ossp
[root@Location-01 ~]# cd /usr/local/src/postgresql-12.2/
[root@Location-01 postgresql-12.2]# pwd
/usr/local/src/postgresql-12.2
[root@Location-01 postgresql-12.2]# ./configure --prefix=/opt/pgsql12.2 --with-uuid=ossp
编译安装uuid-ossp
[root@Location-01 ~]# cd /usr/local/src/postgresql-12.2/contrib/uuid-ossp/
[root@Location-01 uuid-ossp]# pwd
/usr/local/src/postgresql-12.2/contrib/uuid-ossp
[root@Location-01 ~]# cd /usr/local/src/postgresql-12.2/contrib/uuid-ossp/
[root@Location-01 uuid-ossp]# pwd
/usr/local/src/postgresql-12.2/contrib/uuid-ossp
执行编译安装:
make && make install
(四)创建扩展:
查看可用扩展:
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
uuid-ossp | 1.1 | | generate universally unique identifiers (UUIDs)
(6 rows)
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
uuid-ossp | 1.1 | | generate universally unique identifiers (UUIDs)
(6 rows)
创建扩展:
postgres=# create extension "uuid-ossp";
CREATE EXTENSION
postgres=# create extension "uuid-ossp";
CREATE EXTENSION
(五)使用扩展:
postgres=# select uuid_generate_v4();
uuid_generate_v4
--------------------------------------
cba03532-aa87-40be-b4e2-cf2e13b71c6e
(1 row)
postgres=# select uuid_generate_v4();
uuid_generate_v4
--------------------------------------
cba03532-aa87-40be-b4e2-cf2e13b71c6e
(1 row)