Инструменты пользователя

Инструменты сайта


postgres:uuid

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



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
* 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()
postgres/uuid.txt · Последние изменения: 2023/01/12 12:18 (внешнее изменение)