File tree Expand file tree Collapse file tree
docs/modules/ROOT/pages/vshn-managed/postgresql Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,74 +61,3 @@ $ oc get secrets postgres-creds -o yaml
6161The output of the command above is a secret specification with the following structure:
6262
6363include::page$references/secrets.adoc[tag=postgres]
64-
65- == Create a database with a specific locale
66-
67- The default locale when databases are created is `C.UTF-8`.
68- If an application needs a specific locale that is different, then you can do the following:
69-
70- .Create a user and database in the instance
71- [source,yaml]
72- ----
73- apiVersion: vshn.appcat.vshn.io/v1
74- kind: VSHNPostgreSQL
75- metadata:
76- name: pgsql-app1-prod
77- namespace: prod-app
78- spec:
79- parameters:
80- service:
81- access:
82- - user: myapp <1>
83- writeConnectionSecretToRef:
84- name: postgres-creds
85- ----
86- <1> This will create a user and a database `myapp`
87-
88- After that, we create a pod that will re-create the database with the desired settings.
89-
90- .Run a pod with SQL commands to create custom database
91- [source,yaml]
92- ----
93- ---
94- apiVersion: v1
95- kind: Pod
96- metadata:
97- name: postgres-client
98- namespace: prod-app
99- spec:
100- containers:
101- - name: postgres
102- image: postgres:15
103- resources:
104- limits:
105- memory: "128Mi"
106- cpu: "500m"
107- command:
108- - /bin/sh
109- - -c
110- args:
111- - PGPASSWORD=$POSTGRESQL_PASSWORD psql "sslmode=verify-ca sslrootcert=/etc/secret-volume/ca.crt host=$POSTGRESQL_HOST port=$POSTGRESQL_PORT dbname=$POSTGRESQL_DB" -U $POSTGRESQL_USER -c "drop database if exists $DBNAME with (force)"
112- -c "create database $DBNAME LC_COLLATE='C' LC_CTYPE='C' ENCODING='UTF-8' TEMPLATE='template0'"
113- envFrom:
114- - secretRef:
115- name: postgres-creds # <1>
116- env:
117- - name: DBNAME
118- value: myapp # <2>
119- volumeMounts:
120- - name: secret-volume
121- readOnly: true
122- mountPath: "/etc/secret-volume"
123- volumes:
124- - name: secret-volume
125- secret:
126- defaultMode: 0600
127- secretName: postgres-creds # <1>
128- restartPolicy: OnFailure
129-
130- ----
131- <1> The pod will use the secret to connect to the instance. Has to match the `writeConnectionSecretToRef` field of the instance.
132- <2> Change the name to the database name you want
133-
134- You can use this `postgres-client` pod as a template for any SQL commands you want to run against your AppCat VSHNPostgreSQL instance.
Original file line number Diff line number Diff line change 7474====
7575If you remove a user completely from the array, the user and the database will be removed from the instance!
7676====
77+
78+ == Create a database with a specific locale
79+
80+ The default locale when databases are created is `C.UTF-8`.
81+ If an application needs a specific locale that is different, then you can do the following:
82+
83+ .Create a user and database in the instance
84+ [source,yaml]
85+ ----
86+ apiVersion: vshn.appcat.vshn.io/v1
87+ kind: VSHNPostgreSQL
88+ metadata:
89+ name: pgsql-app1-prod
90+ namespace: prod-app
91+ spec:
92+ parameters:
93+ service:
94+ access:
95+ - user: myapp <1>
96+ writeConnectionSecretToRef:
97+ name: postgres-creds
98+ ----
99+ <1> This will create a user and a database `myapp`
100+
101+ After that, we create a pod that will re-create the database with the desired settings.
102+
103+ .Run a pod with SQL commands to create custom database
104+ [source,yaml]
105+ ----
106+ ---
107+ apiVersion: v1
108+ kind: Pod
109+ metadata:
110+ name: postgres-client
111+ namespace: prod-app
112+ spec:
113+ containers:
114+ - name: postgres
115+ image: postgres:15
116+ resources:
117+ limits:
118+ memory: "128Mi"
119+ cpu: "500m"
120+ command:
121+ - /bin/sh
122+ - -c
123+ args:
124+ - PGPASSWORD=$POSTGRESQL_PASSWORD psql "sslmode=verify-ca sslrootcert=/etc/secret-volume/ca.crt host=$POSTGRESQL_HOST port=$POSTGRESQL_PORT dbname=$POSTGRESQL_DB" -U $POSTGRESQL_USER -c "drop database if exists $DBNAME with (force)"
125+ -c "create database $DBNAME LC_COLLATE='C' LC_CTYPE='C' ENCODING='UTF-8' TEMPLATE='template0'"
126+ envFrom:
127+ - secretRef:
128+ name: postgres-creds # <1>
129+ env:
130+ - name: DBNAME
131+ value: myapp # <2>
132+ volumeMounts:
133+ - name: secret-volume
134+ readOnly: true
135+ mountPath: "/etc/secret-volume"
136+ volumes:
137+ - name: secret-volume
138+ secret:
139+ defaultMode: 0600
140+ secretName: postgres-creds # <1>
141+ restartPolicy: OnFailure
142+
143+ ----
144+ <1> The pod will use the secret to connect to the instance. Has to match the `writeConnectionSecretToRef` field of the instance.
145+ <2> Change the name to the database name you want
146+
147+ You can use this `postgres-client` pod as a template for any SQL commands you want to run against your AppCat VSHNPostgreSQL instance.
You can’t perform that action at this time.
0 commit comments