Storing configurations in an RDBMS

Since the first few releases, GeoServer stores configuration data in a folder. This is the default way to persist information and is also the most used method. It allows you to configure a cluster configuration, with more than one GeoServer instance pointing at the same directory. In order to avoid data corruption, you just have to disable the integrated GeoWebCache and carefully avoid editing configuration from more than one GeoServer admin interface at the same time.

Note

For more information about how to configure GeoServer to run multiple instances in parallel, refer to my previous book, GeoServer's Beginners Guide, Packt Publishing.

Are you wondering whether there is a way to store configuration data in an RDBMS? Indeed, there is one option—a community module that you may add to your installation.

The JDBCConfig module lets you use a relational database, such as PostgreSQL, to store GeoServer configurations.

How to do it…

  1. First of all, you need to download the JDBCConfig community module to enable GeoServer to store configurations in a database. Since it is not a released extension, you won't find it in the stable branch download page at http://geoserver.org/release/maintain/.
  2. In fact, you have to go to the nightly build page at http://ares.boundlessgeo.com/geoserver/ and select the branch for your version, 2.5.x for instance. Here, you will be pointed to a repository with the last builds.
    How to do it…
  3. Select the community-latest folder and download the geoserver-2.5-SNAPSHOT-jdbcconfig-plugin.zip file.
  4. After unpacking the archive, you'll find that it contains a .jar file. Move it to the <GEOSERVER_HOME>/WEB-INF/lib folder.
  5. Now, restart your servlet container. After it restarts, you can find a new folder in the GeoServer data directory; it is called jdbcconfig and it contains three files:
    -rw-r--r--  1 root root  506 jdbcconfig.properties
    -rw-r--r--  1 root root 1.5K jdbcconfig.properties.h2
    -rw-r--r--  1 root root 2.2K jdbcconfig.properties.postgres
    drwxr-xr-x  2 root root 4.0K scripts/
    
  6. Stop Tomcat and open the jdbcconfig.properties.postgres file. Inside, there are a lot of comments. You only need to set connection parameters according to your PostgreSQL instance:
    enabled=true
    initdb=true
    initScript=${GEOSERVER_DATA_DIR}/jdbcconfig/scripts/initdb.postgres.sql
    import=true
    jdbcUrl=jdbc:postgresql://localhost:5432/gscatalog
    driverClassName=org.postgresql.Driver
    username=postgres
    password=postgres
  7. Save the file and substitute it with the configuration file read by GeoServer:
    $ mv jdbcconfig.properties jdbcconfig.properties.bck
    $ mv jdbcconfig.properties.postgres jdbcconfig.properties
    
  8. Restart GeoServer. It will now create the database structure and import configurations into it.
  9. Now, check whether the jdbcconfig.properties file was changed by GeoServer. As GeoServer terminated, the import of your configuration changed the initdb and import parameters to false so that the database configuration won't be overwritten at the next restart:
    enabled=true
    initdb=false
    import=false
  10. You can also check whether all went well by logging in to the GeoServer admin interface and pointing at the main page. You should see a message similar to this one:
    How to do it…

How it works…

You may be already familiar with the GeoServer data directory. It contains a structured set of XML files, grouped in folders, where all information about GeoServer configuration is stored.

When you installed the JDBCConfig module, the initdb was set to true. So GeoServer created a set of objects in the database, which are places for the configuration data to be stored inside. If you use a PostgreSQL client, such as pgAdmin, you may have a look at what was created inside the database.

Note

pgAdmin is the most famous GUI interface to administer PostgreSQL. It is released under the open source license and you may find binaries for the main OS or source code to compile and build for yourself. Consult http://www.pgadmin.org/ for more information.

If it seems an overkill to install a full admin client just to have a look at simple data, you may go with psql, the command-line client. It is shipped with PostgreSQL, so you can use it to avoid any extra installation.

How it works…

There are three tables where the data is really stored and 16 views that filter data according to homogeneous categories; layer view, for instance, lets you browse what layers are configured on your GeoServer:

$ psql -U postgres -d gscatalog
gscatalog=# select name, type, enabled, default_style from layer limit 3;
         name         |  type  | enabled | default_style
----------------------+--------+---------+---------------
 GeneralizedCountries | VECTOR | true    |            27
 roads                | VECTOR | true    |            21
 countries            | VECTOR | true    |            27

Try to change the default style or enabled property of some layers and check how the data gets updated in the database.

What does the value inside the default style field mean? Run another query:

gscatalog=# select name, filename from style where oid = 27;
  name   |      filename
---------+---------------------
 polygon | default_polygon.sld

So, it is pointing yet to a file that is not stored inside the database.

In fact, the module is at an early stage and while it lets you import a part of your configuration data, it will not leverage you by using the data directory folder where all information not stored in the database is actually stored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.119