changeset 4624:209b10f7bb2c geoserver_sql_views

Add config for GeoServer database session startup SQL Prepended to setting the role in order to avoid any configuration overwriting it.
author Tom Gottfried <tom@intevation.de>
date Wed, 09 Oct 2019 18:47:13 +0200
parents 30bb2d819d57
children 4a5fa53ca4e1
files example_conf.toml pkg/config/config.go pkg/geoserver/boot.go
diffstat 3 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/example_conf.toml	Wed Oct 09 16:40:18 2019 +0200
+++ b/example_conf.toml	Wed Oct 09 18:47:13 2019 +0200
@@ -56,6 +56,17 @@
 # an explicit --geoserver-clean on the command line.
 #geoserver-clean = true
 
+# geoserver-startup-sql can be used to add SQL commands to GeoServers database
+# session start script. See
+# https://docs.geoserver.org/stable/en/user/data/database/sqlsession.html
+# Note that the commands will be executed as the user configured as 'db-user'.
+# This can be used for example to set query planer configurations that fix
+# bad query plans during GeoServer accessing the published layers.
+# Currently, the published layer 'bottlenecks_geoserver' is known to trigger
+# inefficient nested loop joins due to underestimation of the number of entries
+# in the bottlenecks table. Hence the example setting:
+geoserver-startup-sql = "SET enable_nestloop TO off"
+
 # Proxy settings for external OGC services
 #proxy-key = "SECRET"
 #proxy-prefix = "http://localhost:8000"
--- a/pkg/config/config.go	Wed Oct 09 16:40:18 2019 +0200
+++ b/pkg/config/config.go	Wed Oct 09 18:47:13 2019 +0200
@@ -103,6 +103,14 @@
 // rebooting.
 func GeoServerClean() bool { return viper.GetBool("geoserver-clean") }
 
+// GeoServerStartupSQL can be used to add SQL commands to GeoServers database
+// session start script. See
+// https://docs.geoserver.org/stable/en/user/data/database/sqlsession.html
+// Note that the commands will be executed as the user configured as 'db-user'.
+func GeoServerStartupSQL() string {
+	return viper.GetString("geoserver-startup-sql")
+}
+
 // TmpDir is the path where to store temporary files.
 // If left empty the system default for temporary files is used.
 func TmpDir() string { return viper.GetString("tmp-dir") }
--- a/pkg/geoserver/boot.go	Wed Oct 09 16:40:18 2019 +0200
+++ b/pkg/geoserver/boot.go	Wed Oct 09 18:47:13 2019 +0200
@@ -209,7 +209,8 @@
 					{"dbtype", databaseType},
 					{"Primary key metadata table", primaryKeyMetadataTbl},
 					{"Expose primary keys", true},
-					{"Session startup SQL", startupSQL},
+					{"Session startup SQL",
+						config.GeoServerStartupSQL() + ";" + startupSQL},
 					{"Session close-up SQL", closeupSQL},
 					{"validate connections", true},
 					{"Estimated extends", false},