====== Adding UUID functionality to your psql server (uuid-ossp) ======
====== Steps ======
Login as postgres
$ psql -U postgres
Check to see if “uuid-ossp” is installed on your db server
select * from pg_extension;
If it is installed you should see it listed like it is below
{{https://miro.medium.com/max/700/1*VtQNCDrIlyo7vYBCHj04_Q.png?700x209}}\\
{{https://miro.medium.com/max/1400/1*VtQNCDrIlyo7vYBCHj04_Q.png?700x209}} \\
If not present, install “uuid-ossp”
# CREATE EXTENSION "uuid-ossp";
Verify that it was installed correctly
# select * from pg_extension;
To see a list of available pg plugins you can type
# select * from pg_available_extensions;
**Tangential Note:** dropping an extension\\ * [[https://www.postgresql.org/docs/9.1/static/sql-dropextension.html|Ref: sql-dropextension]]\\ If you find the need to remove the uuid-ossp extension, you can do so by executing the below command.
# DROP EXTENSION "uuid-ossp";
===== Database setup¶ =====
XCU stores some data in a PostgreSQL database. By default, ''application.conf'' is configured to connect to a local database named ''icx'' with the username ''icx'' and password ''icx''. You can change these parameters if you wish. We will use the default parameters in this documentation.
First, we need to install PostgresSQL extensions to use UUID functions :
sudo apt-get install postgresql-contrib
We can now create the user and the database associated :
sudo -u postgres psql -c "CREATE USER icx WITH PASSWORD 'icx'"
sudo -u postgres psql -c "CREATE DATABASE icx WITH OWNER icx"
We then have to enable UUID extension on the ''icx'' database. Connect as ''root'' on the ''icx'' database :
sudo -u postgres psql icx -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
SELECT uuid_generate_v4()