CREATE KEY

Create a new key in a database.

CREATE KEY key [ WITH ] SECRET 'hex_string'; 
key
A key name with a maximum length of 128 bytes. Names longer than 128 bytes are automatically truncated. See SQL Identifiers.
hex_string
A valid hexadecimal string with a minimum of 1 character and maximum of 32768 characters. Hexadecimal strings can only contain the following characters: [0-9] and [a-f]. 0x prefix is not supported.

A newly created key is only accessible by the user creating the key. To grant other users permission to use a key, see GRANT.

The CREATE KEY operation is non-transactional and will error out when run inside a transaction block.

Note that keys are not backed up during backup operation because they are not actually stored in the database. Hence, it is the responsibility of the remote keystore administrator to make sure keys are backed up and stored safely.

See also Encrypting Sensitive Data.

For example, create a key named yb100key with secret a1b2c3d4:
premdb=# create key yb100key secret 'a1b2c3d4';
CREATE KEY
Using an invalid hexadecimal string as a secret will result in the following error:
premdb=# create key yb100key secret 'g1h2i3j4';
ERROR:  invalid secret. HINT: secret must be a valid hexadecimal string (i.e. non-empty and without a '0x' prefix) smaller than 32768 characters