@@ -220,12 +220,36 @@ gitlab_generate_postgresqlrc() {
220
220
echo " ${DB_CLIENT_VERSION_PACKAGE_NAME} ${DB_HOST} :${DB_PORT} ${DB_NAME} " | exec_as_git tee " ${GITLAB_USER_POSTGRESQLRC} "
221
221
}
222
222
223
+ gitlab_uninstall_unused_database_client () {
224
+ if [[ -f " /home/${GITLAB_USER} /.postgresqlrc" ]]; then
225
+ # refer /home/${GITLAB_USER}/.postgresqlrc and pick up versions in use
226
+ # .postgresqlrc contains following information per line
227
+ # database_major_version host:port database_name
228
+ # - ignore lines starts with # by specifying pattern /^[^#]/
229
+ # - first field is the version number in use.
230
+ # - cocnat whole lines into single string. convert newline to \|
231
+ # this is escaped regex "OR"
232
+ # now we got the following regex that can be used as an option to grep:
233
+ # \|-12\|-13
234
+ DB_CLIENT_VERSIONS_IN_USE=" $( awk ' /^[^#]/ {printf("\|-%s",$1)}' " /home/${GITLAB_USER} /.postgresqlrc" ) "
235
+
236
+ # we also need to keep postgresql-client-common package to switch based on ~/.postgresqlrc
237
+ REGEX_DB_CLIENT_VERSIONS_IN_USE=" -common${DB_CLIENT_VERSIONS_IN_USE} "
238
+
239
+ # remove unused client using regex above
240
+ UNUSED_DB_CLIENTS=$( apt-cache pkgnames postgresql-client | grep -v -e " ${REGEX_DB_CLIENT_VERSIONS_IN_USE} " | tr ' \n' ' ' )
241
+ echo " - Uninstalling unused client(s): ${UNUSED_DB_CLIENTS} "
242
+ DEBIAN_FRONTEND=noninteractive apt-get -qq remove -- ${UNUSED_DB_CLIENTS} > /dev/null
243
+ fi
244
+ }
245
+
223
246
gitlab_configure_database () {
224
247
echo -n " Configuring gitlab::database"
225
248
226
249
gitlab_finalize_database_parameters
227
250
gitlab_check_database_connection
228
251
gitlab_generate_postgresqlrc
252
+ gitlab_uninstall_unused_database_client
229
253
230
254
update_template ${GITLAB_DATABASE_CONFIG} \
231
255
DB_ENCODING \
0 commit comments