From 04bbc50ccbf4f9c7d3846990c8315b45be309695 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 4 Apr 2017 12:29:54 -0400 Subject: [PATCH] Add back lost Postgres creation sql for storage backend --- .../configuration/storage/postgresql.html.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/website/source/docs/configuration/storage/postgresql.html.md b/website/source/docs/configuration/storage/postgresql.html.md index a127d9e59..238af3e90 100644 --- a/website/source/docs/configuration/storage/postgresql.html.md +++ b/website/source/docs/configuration/storage/postgresql.html.md @@ -41,6 +41,36 @@ CREATE TABLE vault_kv_store ( CREATE INDEX parent_path_idx ON vault_kv_store (parent_path); ``` +If you're using a version of PostgreSQL prior to 9.5, create the following function: + +```sql +CREATE FUNCTION vault_kv_put(_parent_path TEXT, _path TEXT, _key TEXT, _value BYTEA) RETURNS VOID AS +$$ +BEGIN + LOOP + -- first try to update the key + UPDATE vault_kv_store + SET (parent_path, path, key, value) = (_parent_path, _path, _key, _value) + WHERE _path = path AND key = _key; + IF found THEN + RETURN; + END IF; + -- not there, so try to insert the key + -- if someone else inserts the same key concurrently, + -- we could get a unique-key failure + BEGIN + INSERT INTO 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; + END LOOP; +END; +$$ +LANGUAGE plpgsql; +``` + ## `postgresql` Parameters - `connection_url` `(string: )` – Specifies the connection string to