How to add uuid-ossp extension to PostgreSQL

How to add uuid-ossp extension to PostgreSQL

PostgreSQL UUID (Universal Unique Identifier) is specified by RFC 4122 and has a 128-bit length. 

Here We will cover two methods for enabling uuid-ossp extension to PostgreSQL: via CMD and PostgreSQL pgAdmin 4 GUI.


Option 1. Enable uuid-ossp extension on PostgreSQL from the terminal

Step 1. Check your Postgres version and install for your version:

yum install postgresql-contrib-12

Step 2. Login to postgre:

# psql -U postgres

psql (9.2.24)
Type "help" for help.

Step 3. Select the database with \c DB_name;

postgres=# \c piz_db;

You are now connected to database "pizzabel_db" as user "postgres".

Step 4. Add the extension with CREATE EXTENSION “uuid-ossp”;

piz_db=# CREATE EXTENSION "uuid-ossp";

CREATE EXTENSION

That’s it.

To check if the extension is created:

pizl_db=# select * from pg_extension;
  extname  | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
-----------+----------+--------------+----------------+------------+-----------+--------------
 plpgsql   |       10 |           11 | f              | 1.0        |           |
 uuid-ossp |       10 |         2200 | t              | 1.0        |           |
(2 rows)

After enabling the uuid-ossp extension system automatically creates the UUID data type and supports B-tree indexes.

piz_db=# \dT

     List of data types
 Schema | Name | Description
--------+------+-------------
 public | uuid |
(1 row)

Option 2. Enable uuid-ossp extension on PostgreSQL from PostgreSQL pgAdmin

Step 1. Login

Open the PostgreSQL ‘pgAdmin 4’ GUI, connect the user ‘postgres’ with the server ‘PostgreSQL 13’ by providing the password for the username, then hit the ‘OK’ button:

pgadmin postgres - How to add uuid-ossp extension to PostgreSQL

Step 2. Select the database and run

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
image2 17 - How to add uuid-ossp extension to PostgreSQL

That’s it, under Extensions you should see the newly installed “uuid-ossp” package.

uuid extension postgresql - How to add uuid-ossp extension to PostgreSQL

whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.