Publishing from PostGIS#

Publish vector layers from PostGIS spatial databases. This command discovers spatial tables and creates feature types in GeoServer.

Prerequisites#

  • PostGIS database with spatial tables
  • PostGIS datastore configured in GeoServer (created automatically if missing)
  • PostGIS connection configured in config file or via flags

Basic Usage#

Publish Single Table#

1
./geoserver-cli publish postgis --layer roads -w my_workspace

Publish Multiple Tables#

1
./geoserver-cli publish postgis --layers roads,buildings,water -w my_workspace

Publish All Tables#

1
2
# Publish all spatial tables
./geoserver-cli publish postgis --all -w my_workspace

Table Selection#

Include Filter (Regex)#

1
2
# Publish only tables matching pattern
./geoserver-cli publish postgis --all -w my_workspace --include "^roads_"

Exclude Filter (Regex)#

1
2
# Publish all except matching pattern
./geoserver-cli publish postgis --all -w my_workspace --exclude "^temp_"

Combined Filters#

1
2
3
4
# Include roads_* but exclude roads_temp_*
./geoserver-cli publish postgis --all -w my_workspace \
  --include "^roads_" \
  --exclude "^roads_temp_"

PostGIS Connection#

From Config File#

Configure PostGIS connection in configs/*.config.toml:

1
2
3
4
5
6
7
8
[postgis]
host = "localhost"
port = 5432
database = "gis"
user = "postgres"
password = "password"
schema = "public"
sslmode = "disable"

Via Flags#

Override config settings:

1
2
3
4
5
6
7
./geoserver-cli publish postgis --all -w my_workspace \
  --pg-host db.example.com \
  --pg-port 5432 \
  --pg-database gis \
  --pg-user geoserver \
  --pg-password secure_password \
  --pg-schema public

Environment Variables#

1
2
3
4
5
6
export GEOSRVCLI_POSTGIS_HOST=db.example.com
export GEOSRVCLI_POSTGIS_DATABASE=gis
export GEOSRVCLI_POSTGIS_USER=geoserver
export GEOSRVCLI_POSTGIS_PASSWORD=secure_password

./geoserver-cli publish postgis --all -w my_workspace

Datastore Management#

Automatic Creation#

If the specified datastore doesn’t exist, it will be created automatically:

1
2
# Creates "postgis" datastore if missing
./geoserver-cli publish postgis --all -w my_workspace --store postgis

Custom Datastore Name#

1
./geoserver-cli publish postgis --all -w my_workspace --store my_postgis_store

Concurrency#

Control concurrent publishing for better performance:

1
2
# Use 4 workers (default: CPU cores / 2)
./geoserver-cli publish postgis --all -w my_workspace --concurrency 4

Dry Run#

Preview what would be published:

1
./geoserver-cli publish postgis --all -w my_workspace --dry-run

Output:

1
2
3
4
5
Dry-run:
- workspace: "my_workspace"
- store: "postgis"
- postgis: geoserver@db.example.com:5432/gis (schema=public sslmode=disable)
- layers (5): roads, buildings, water, parks, boundaries

Output#

Success Output#

1
2
3
4
5
6
7
roads: published
buildings: published
water: skipped (already exists)
parks: published
boundaries: published

Summary: published=4 skipped=1 failed=0

Error Output#

1
2
3
4
5
roads: published
buildings: failed: HTTP 500: Internal Server Error
water: published

Summary: published=2 skipped=0 failed=1

Examples#

Complete PostGIS Workflow#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 1. Configure PostGIS in config file
# Edit configs/default.config.toml with PostGIS settings

# 2. Create workspace
./geoserver-cli workspace create production

# 3. Publish all spatial tables
./geoserver-cli publish postgis --all -w production

# 4. Apply styles
for layer in roads buildings water; do
  ./geoserver-cli layer update ${layer} --default-style standard_style
done

Schema-Specific Publishing#

1
2
3
4
5
# Publish only from specific schema
./geoserver-cli publish postgis --all -w my_workspace --pg-schema public

# Publish from different schema
./geoserver-cli publish postgis --all -w my_workspace --pg-schema staging

Incremental Publishing#

1
2
3
4
5
# Publish new tables only (existing are skipped)
./geoserver-cli publish postgis --all -w my_workspace

# Publish specific new table
./geoserver-cli publish postgis --layer new_table -w my_workspace

Production Deployment#

1
2
3
4
5
6
7
8
# Use production config
export GEOSRVCLI_CONFIG=prod

# Dry run first
./geoserver-cli publish postgis --all -w production --dry-run

# Publish with high concurrency
./geoserver-cli publish postgis --all -w production --concurrency 8