File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
docs/modules/ROOT/pages/vshn-managed/postgresql Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,74 @@ $ oc get secrets postgres-creds -o yaml
61
61
The output of the command above is a secret specification with the following structure:
62
62
63
63
include::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.
You can’t perform that action at this time.
0 commit comments