The PostgreSQL storage backend is used to persist Vault's data in a
PostgreSQL server or cluster.
High Availability – the PostgreSQL storage backend supports
high availability. Requires PostgreSQL 9.5 or later.
Community Supported – the PostgreSQL storage backend is supported by the
community. While it has undergone review by HashiCorp employees, they may not
be as knowledgeable about the technology. If you encounter problems with them,
you may be referred to the original author.
Note: The PostgreSQL storage backend plugin will attempt to use SSL
when connecting to the database. If SSL is not enabled the connection_url
will need to be configured to disable SSL. See the documentation below
to disable SSL.
The PostgreSQL storage backend does not automatically create the table. Here is
some sample SQL to create the schema and indexes.
If you're using a version of PostgreSQL prior to 9.5, create the following function:
CREATEFUNCTION vault_kv_put(_parent_path TEXT, _path TEXT, _key TEXT, _value BYTEA)RETURNS VOID AS
$$
BEGINLOOP-- first try to update the keyUPDATE vault_kv_store
SET(parent_path, path,key,value)=(_parent_path, _path, _key, _value)WHERE _path = path ANDkey= _key;IF found THENRETURN;ENDIF;-- not there, so try to insert the key-- if someone else inserts the same key concurrently,-- we could get a unique-key failureBEGININSERTINTO vault_kv_store (parent_path, path,key,value)VALUES(_parent_path, _path, _key, _value);RETURN;
EXCEPTION WHEN unique_violation THEN-- Do nothing, and loop to try the UPDATE again.END;ENDLOOP;END;
$$
LANGUAGE plpgsql;
CREATEFUNCTION vault_kv_put(_parent_path TEXT, _path TEXT, _key TEXT, _value BYTEA)RETURNS VOID AS$$BEGINLOOP-- first try to update the keyUPDATE vault_kv_storeSET(parent_path, path,key,value)=(_parent_path, _path, _key, _value)WHERE _path = path ANDkey= _key;IF found THENRETURN;ENDIF;-- not there, so try to insert the key-- if someone else inserts the same key concurrently,-- we could get a unique-key failureBEGININSERTINTO vault_kv_store (parent_path, path,key,value)VALUES(_parent_path, _path, _key, _value);RETURN; EXCEPTION WHEN unique_violation THEN-- Do nothing, and loop to try the UPDATE again.END;ENDLOOP;END;$$LANGUAGE plpgsql;
connection_url(string: <required>) – Specifies the connection string to
use to authenticate and connect to PostgreSQL. The connection URL can also be
set using the VAULT_PG_CONNECTION_URL environment variable. A full list of supported
parameters can be found in the pq library documentation. For example
connection string URLs, see the examples section below.
table(string: "vault_kv_store") – Specifies the name of the table in
which to write Vault data. This table must already exist (Vault will not
attempt to create it).
max_parallel(string: "128") – Specifies the maximum number of concurrent
requests to PostgreSQL.
ha_enabled(string: "true|false") – Default not enabled, requires 9.5 or later.
ha_table(string: "vault_ha_locks") – Specifies the name of the table to use
for storing high availability information. This table must already exist (Vault
will not attempt to create it).