GDAL – Postgis Table to Geopackage

  • Shell
  • gdal 3.x
  • Updated: March 2024

So back with another GDAL Trick. What if you need to dump a table from PostGIS into a Geopackage and all you have is your trusty command line.

ogr2ogr -f GPKG test.gpkg PG:"host=ipaddress user=user password=password dbname=dbname" "schema.table" 

A real life example would be:

ogr2ogr -f GPKG test.gpkg PG:"host=gis1 user=rjhale password=trustno1 dbname=test911" "schema.point_layer"

What if you needed to only pull a certain number of fields out with your data:

ogr2ogr -f GPKG test.gpkg -nlt point PG:"host=gis1 user=rjhale dbname=henrycounty911 password=trustno1" -sql "select id, oirid, geom, name from schema.point_layer"

As always Read the Freaking Manual