File tree 1 file changed +71
-0
lines changed
docs/modules/ROOT/pages/vshn-managed/postgresql
1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 74
74
====
75
75
If you remove a user completely from the array, the user and the database will be removed from the instance!
76
76
====
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