aboutsummaryrefslogtreecommitdiffstats
path: root/kubernetes/common/postgres/configs/setup.sql
blob: f60b4732426416f5ceb161c211f9b5087baef432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--- System Setup
SET application_name="container_setup";

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

ALTER USER postgres PASSWORD '${PG_ROOT_PASSWORD}';

CREATE USER ${PG_PRIMARY_USER} WITH REPLICATION;
ALTER USER ${PG_PRIMARY_USER} PASSWORD '${PG_PRIMARY_PASSWORD}';

CREATE USER "${PG_USER}" LOGIN;
ALTER USER "${PG_USER}" PASSWORD '${PG_PASSWORD}';

CREATE DATABASE ${PG_DATABASE};
GRANT ALL PRIVILEGES ON DATABASE ${PG_DATABASE} TO "${PG_USER}";

CREATE TABLE IF NOT EXISTS primarytable (key varchar(20), value varchar(20));
GRANT ALL ON primarytable TO ${PG_PRIMARY_USER};

--- PG_DATABASE Setup

\c ${PG_DATABASE}

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgaudit;

--- Verify permissions via PG_USER

\c ${PG_DATABASE} "${PG_USER}";

CREATE SCHEMA IF NOT EXISTS "${PG_USER}";

CREATE TABLE IF NOT EXISTS "${PG_USER}".testtable (
	name varchar(30) PRIMARY KEY,
	value varchar(50) NOT NULL,
	updatedt timestamp NOT NULL
);

INSERT INTO "${PG_USER}".testtable (name, value, updatedt) VALUES ('CPU', '256', now());