Skip to main content
This page has instructions for configuring GeoServer to use CockroachDB as the underlying database. The instructions here reuse parts of the data set described in the , specifically the tutorial.roads table, which contains the U.S. National Atlas data set. Many of the instructions on this page come from the following GeoServer documentation pages:

Before you begin

You must have the following set up before proceeding with this tutorial:
  1. CockroachDB
  2. GeoServer installed on the local machine.
These instructions assume you are running on a UNIX-like system.
Mac users who use Homebrew can install GeoServer by typing brew install geoserver.

Step 1. Start CockroachDB and connect to your cluster

Start a CockroachDB cluster by following the instructions in .

Step 2. Load spatial data

Connect to the running cluster from the and enter the statements below.
  1. the tutorial database:
  2. Switch to the tutorial database:
  3. Load the spatial data set:

Step 3. Turn on CockroachDB’s experimental box comparison operators

CockroachDB’s support for GeoServer is still in development. To use CockroachDB with GeoServer, you will need to enable the use of certain experimental box2d comparison operators by changing the following :
The reasons the box2d comparison operators are experimental in CockroachDB are as follows:
  • PostGIS uses the &&, ~, and @ operators to do bounding box comparisons. These comparisons can always be index-accelerated by PostgreSQL since it uses R-tree based indexing to generate its coverings.
  • CockroachDB since this is necessary for .
    • This means that the coverings generated by CockroachDB’s &&, ~, and @ operators for index-accelerated lookups are not the same as the bounding box coverings generated by PostGIS.
    • In practice, CockroachDB may return a smaller set of results for the same query, as the space-filling curve covering is often more exact than a bounding box covering, and will exclude from the result set any geometries that have an intersecting bounding box but where no part of the geometry hits the actual bounding box.
    • Note that the behavior described above only applies to index-accelerated lookups.

Step 4. Start GeoServer

The easiest place to create the GeoServer data directory is in your user’s home directory.
  1. In the UNIX shell, run the following command:
  2. Start GeoServer by running the following command:
You should see some log output that looks like the following:

Step 5. Log in to GeoServer

In this and the following steps we will set up GeoServer so it can access the spatial data we loaded in Step 2. Open your web browser and navigate to your locally running GeoServer instance. Log in using the default credentials: username admin, password geoserver.

Step 6. Set up a GeoServer Workspace

In the left-hand navigation menu, click Data > Workspaces. The Workspaces page will load. Click the Add new workspace button. On the New Workspace page, enter the following information:
  • In the Name field, enter the text “spatial-tutorial”.
  • In the Namespace URI field, enter the URL for the spatial tutorial where this data set is used: /docs/v23.2/spatial-tutorial.html.
Press the Save button. You will be redirected to the Workspaces page, and you should see a workspace called spatial-tutorial in the list.

Step 7. Configure GeoServer to use CockroachDB

In the left-hand navigation menu, click Data > Stores. The Stores page will load. Click the Add new Store button. You will be taken to the New data source page. Under the list of Vector Data Sources, click PostGIS. This opens the New Vector Data Source page, where you need to enter the following information:
  1. Under Basic Store Info, fill in the Data Source Name field with the text: CockroachDB
  2. Under Connection Parameters, edit port to the default CockroachDB port: 26257
  3. Edit the database field to add the text: tutorial
  4. Fill in the user field with the text: root
  5. Delete the contents of the passwd field, if any
Click Save, and you will be redirected to the New Layer page, with the following unpublished layers:
  • bookstore_routes
  • bookstores
  • roads
Click the Publish button to the right of the roads layer. This will bring you to the Edit Layer page, where you need to enter the following information:
  1. In the Bounding Boxes section, for the Native Bounding Box settings, click the Compute from data button, which will fill in the form fields.
  2. Also in the Bounding Boxes section, for the Lat/Lon Bounding Box setting, click the Compute from native bounds button, which will fill in the form fields.
Click Save, and you will be redirected to the Layers page.

Step 8. View the roads layer

In the left-hand navigation menu, click Data > Layer Preview. You will be redirected to the Layer Preview page. In the row for the roads layer, click the OpenLayers button under the Common Formats column. Your browser should open a new tab with the title OpenLayers map preview. It should show a map view that looks like the following: GeoServer U.S. National Atlas preview

See also