GDAL: PostGIS to Shapefile

  • Software: GDAL 3.X
  • OS: Any
  • Updated: October 2025

You are working with data in PostgreSQL and PostGIS. You want to use GDAL to extract a table out to a shapefile:

ogr2ogr -f 'ESRI Shapefile' test.shp PG:"host=ip.address port=5432 user='rjhale' password='trustno1' dbname='name'" 'schema.table'

An Example:

ogr2ogr -f 'ESRI Shapefile' /home/rjhale/test.shp PG:"host=192.168.1.1 port=5432 user='rjhale' password='trustno1' dbname='chattanooga'" 'public.streams'