Example of a simple bash script to create Geoserver layers for all tables of a given Postgresql schema.
The workspace and the store should already exist in Geoserver. In this example I use the workspace name = database name; the store name = schema name; postgresql server = geoserver server. That is why my URL is: http://$pghost/geoserver/rest/workspaces/$pgdb/datastores/$pgschema/featuretypes
#!/bin/bash
pghost='server.com'
pgport=5432
pguser='geobox'
pgpass='******'
pgschema='sigpdm_2015'
pgdb='pdm2017'
table_names=`PGPASSWORD=$pgpass psql -U $pguser -h $pghost -p $pgport -d $pgdb -t -c "SELECT * FROM (select table_name as t from information_schema.tables where table_schema = '$pgschema') as tnames"`
while read -a table_name ; do
curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>$table_name</name><nativeCRS>EPSG:3763</nativeCRS><srs>EPSG:3763</srs><nativeBoundingBox><minx>-33313.0</minx><maxx>-13047.0</maxx><miny>198924.0</miny><maxy>216948.0</maxy><crs>EPSG:3763</crs></nativeBoundingBox></featureType>" http://$pghost/geoserver/rest/workspaces/$pgdb/datastores/$pgschema/featuretypes
done <<< "$table_names"
The <featureType>
could be more simpler, but I usually run into problems when layers get new features outside the initial bounding box. So I prefer to create the layers with the larger possible bounding box. I also added the local CRS, instead of a global one.