PostgreSQL Add UUID function

Source: Internet
Author: User
Tags postgresql psql uuid postgres database

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.