PostgreSQL has a built-in UUID type, but the default installation does not have a correlation function and needs to be generated manually.
One, if it is a separate package installation method as shown below
Package to my previous blog mentioned in the website download
1. Main node:
Installing Postgresql94-contrib
# yum Install Postgresql94-contrib-9.4.18-1pgdg.rhel6.x86_64.rpm-y
# Find/-name uuid-ossp*
/usr/pgsql-9.4/lib/uuid-ossp.so
/usr/pgsql-9.4/share/extension/uuid-ossp--unpackaged--1.0.sql
/usr/pgsql-9.4/share/extension/uuid-ossp.control
/usr/pgsql-9.4/share/extension/uuid-ossp--1.0.sql
Log in to Database
# su Postgres
bash-4.1$ Psql
Execute the following statement
postgres=# Create extension "UUID-OSSP";
CREATE EXTENSION
Try to generate a UUID with the imported function
postgres=# select UUID_GENERATE_V4 ();
Uuid_generate_v4
--------------------------------------
28cbfa1e-d659-4aa2-a0fd-95fc7ec0aa8b
(1 row)
2, from the node;
# su Postgres
bash-4.1$ Psql
The package needs to be installed, but no corresponding statements need to be executed
# yum Install Postgresql94-contrib-9.4.18-1pgdg.rhel6.x86_64.rpm-y
# su Postgres
bash-4.1$ Psql
postgres=# select UUID_GENERATE_V4 ();
Uuid_generate_v4
--------------------------------------
88dd0f5e-0011-4471-9b95-008f24852b5b
(1 row)
Second, the process of installing through Yum is as follows
Master node:
Install packages
# yum Install Postgresql-contrib
The other process is the same as above
Third, the matters needing attention
The procedure above is to operate on the database Postgres database created by default, and if you want to use the UUID function for other databases belonging to ordinary users, you must operate on its database.
First Use Super Account login database (database pgdata operation user is Pgone)
bash-4.1$ psql-u postgres-d pgdata-w
peimsm=# Create extension "UUID-OSSP";
CREATE EXTENSION
peimsm=# select UUID_GENERATE_V4 ();
Uuid_generate_v4
--------------------------------------
0533a1cb-085e-49f6-a451-1508e6051e4a
(1 row)
The above operation only needs to be operated on the primary node, and the read-only database cannot execute the corresponding statement.
PostgreSQL Add UUID function