shp2pgsql(1)
π shp2pgsql(1) π
okay bestie, welcome to the shp2pgsql page from the PostGIS manual π¦ β it's the shapefile-to-PostGIS loader and honestly? she's iconic.
β¨ NAME β¨
shp2pgsql β shapefile to postgis loader. that's it, that's the name, no notes π
πΈ SYNTAX πΈ
shp2pgsql [options] shapefile [schema.]table
look at her. short. sweet. does exactly what it says. β¨
π¦ DESCRIPTION π¦
The shp2pgsql data loader converts ESRI Shape files into SQL that's suitable for insertion into a PostGIS/PostgreSQL database. it's giving "glow up your shapefile into a real database table" energy fr fr π₯
Version: 1.1.5 (2006/10/06) β
π USAGE π
okay so the <shapefile> is the name of the shape file, without any extension information. for example, 'roads' would be the name of the shapefile comprising the 'roads.shp', 'roads.shx', and 'roads.dbf' files. like, she knows the gang, you don't gotta introduce them all π
The <tablename> is the (optionally schema-qualified) name of the database table you want the data stored in in the database. and inside that table, the geometry goes in the 'geo_value' column by default. periodt π
π OPTIONS π
The loader has several operating modes distinguished by command line flags. it's giving "pick your lane" π
β οΈ Note that-a,-c,-dand-pare mutually exclusive. pick ONE, bestie, they do not share, no cap π
-dβ drops the database table before creating a new table with the data in the Shape file. it's giving "clean slate, out with the old" π-aβ appends data from the Shape file into the database table. note that to use this option to load multiple files, the files must have the same attributes and same data types. like they gotta match, she's not doing the work of figuring out your chaos π€-cβ creates a new table and populates it from the Shape file. this is the default mode. the main character π-pβ only produces the table creation SQL code, without adding any actual data. use this if you need to completely separate the table creation and data loading steps. very "structure now, vibes later" β¨-Dβ use the PostgreSQL"dump"format for the output data. this can be combined with-a,-cand-d. it is much faster to load than the default"insert"SQL format. use this for very large data sets β big data, big slay π-wβ output WKT format, instead of WKB. note that this can introduce coordinate drifts due to loss of precision. she's warning you, listen to her π«Ά-eβ execute each statement on its own, without using a transaction. this allows loading of the majority of good data when there are some bad geometries that generate errors. note that this cannot be used with the-Dflag as the"dump"format always uses a transaction. sorry babe, that combo is a no π-s [<FROM_SRID>:]<SRID>β creates and populates the geometry tables with the specified SRID. ifFROM_SRIDis given, the geometries will be reprojected. reprojection cannot be used with-D. glowed up but with rules β¨-Gβ use the geography type instead of geometry. Geography is used to store lat/lon data. at the moment the only spatial reference supported is4326. literally just the one, bestie π-g <geometry_column>β specify the name of the geometry column (mostly useful in append mode). name your child, it's fine π-kβ keep identifiers case (column, schema and attributes). note that attributes in Shapefile are usually all UPPERCASE. so like, don't be shocked π-m <filename>β specify a file containing a set of mappings of (long) column names to 10 character DBF column names. the content of the file is one or more lines of two names separated by white space and no trailing or leading space:
COLUMNNAME DBFFIELD1\n
AVERYLONGCOLUMNNAME DBFFIELD2\n
etc. yes the \n is right there in the example, keep it exact bestie π
-iβ coerce all integers to standard 32-bit integers, do not create 64-bit bigints, even if the DBF header signature appears to warrant it. she said "we're keeping it cute and small" πΈ-Sβ generate simple Geometries instead of MULTIgeometries. Shape files don't differ betweenLINESTRINGs andMULTILINESTRINGs, soshp2pgsqlgeneratesMULTILINESTRINGs by default. this switch will produceLINESTRINGs instead, butshp2pgsqlwill fail when it hits a realMULTILINESTRING. The same works forPOLYGONs vs.MULTIPOLYGONs. so like, know what you're doing, okay? π-W <encoding>β specify the character encoding of Shapefile's attributes. if this option is used the output will be encoded in UTF-8. glow up the encoding, slay β¨-Iβ create a GiST index on the geometry column. index her, she deserves it π-N <policy>β specify NULL geometries handling policy (insert,skip,abort). three doors, choose wisely πͺ-T <tablespace>β specify the tablespace for the new table. Indexes will still use the default tablespace unless the-Xparameter is also used. The PostgreSQL documentation has a good description on when to use custom tablespaces. like, go read it, i'll wait π-X <tablespace>β specify the tablespace for the new table's indexes. this applies to the primary key index, and the GIST spatial index if-Iis also used. tag team, iconic π€-?β display version and usage information. the "who am i" button π¦
π INSTALLATION π
To compile the program from source, simply run "make" in the source directory. then copy the binary in your shell search path (or wherever you like, she's not judging π«Ά). This text is also available as a man page in the ../doc/man/ directory, ready for copying it into the manual search path on unixoid systems. very plug-and-play of her π
π₯ EXAMPLES π₯
An example session using the loader to create an input file and uploading it might look like this:
# shp2pgsql shaperoads roadstable roadsdb > roads.sql
# psql -d roadsdb -f roads.sql
A conversion and upload can be done all in one step using UNIX pipes. one line, no waiting, ate π
# shp2pgsql shaperoads roadstable roadsdb | psql -d roadsdb
π AUTHORS π
Originally written by Jeff Lounsbury <jeffloun@refractions.net>. Improved and maintained by Sandro Santilli <strk@kbt.io>. Includes small contributions and improvements by others. community effort, we love to see it π«Ά
This application uses functionality from shapelib 1.2.9 by Frank Warmerdam <warmerda@gdal.velocet.ca> to read from ESRI Shape files. shoutout to the library that makes it all happen πΈ
π SEE ALSO π
pgsql2shp(1)β the reverse direction, she does that too π«
More information is available at http://postgis.net β go look, it's free, it's iconic β¨
okay that's the whole page bestie, no skips, no summaries, every single flag accounted for π
sign-off: you've been reading shp2pgsql(1) from the PostGIS manual, version 1.1.5 dated 2006/10/06 β go load some shapefiles, you got this π¦π
β¨
π¦ where this page comes from
- alpine 3.24: postgis-doc 3.6.3-r0 Β· GPL-2.0-or-later
- arch rolling: postgis 3.6.4-1 Β· GPL-2.0-or-later
- centos-stream 10: postgis-client 3.5.3-4.el10 Β· GPL-2.0-or-later
- centos-stream 10: postgresql18-postgis-client 3.5.3-2.el10 Β· GPL-2.0-or-later
- centos-stream 9: postgis-client 3.6.1-1.module_el9+1300+1c4aa8df Β· GPL-2.0-or-later
- debian bookworm: postgis 3.3.2+dfsg-1+b1 Β· GPL-2.0-or-later
- debian trixie: postgis 3.5.2+dfsg-1 Β· GPL-2.0-or-later
- fedora 43: postgis-client 3.6.0-1.fc43 Β· GPL-2.0-or-later
- fedora 43: postgis-client 3.6.4-5.fc43 Β· GPL-2.0-or-later
- fedora 43: postgresql16-postgis-client 3.6.4-5.fc43 Β· GPL-2.0-or-later
- fedora 43: postgresql17-postgis-client 3.6.4-5.fc43 Β· GPL-2.0-or-later
- fedora 44: postgis-client 3.6.2-1.fc44 Β· GPL-2.0-or-later
- fedora 44: postgis-client 3.6.4-5.fc44 Β· GPL-2.0-or-later
- fedora 44: postgresql16-postgis-client 3.6.2-1.fc44 Β· GPL-2.0-or-later
- fedora 44: postgresql16-postgis-client 3.6.4-5.fc44 Β· GPL-2.0-or-later
- fedora 44: postgresql17-postgis-client 3.6.2-1.fc44 Β· GPL-2.0-or-later
- fedora 44: postgresql17-postgis-client 3.6.4-5.fc44 Β· GPL-2.0-or-later
- nixos 26.05: postgis 3.6.4
- nixpkgs unstable: postgis 3.6.4
- ubuntu jammy: postgis 3.2.0+dfsg-1ubuntu1 Β· GPL-2.0-or-later
- ubuntu noble: postgis 3.4.2+dfsg-1ubuntu3 Β· GPL-2.0-or-later
- ubuntu questing: postgis 3.5.3+dfsg-2build1
- ubuntu resolute: postgis 3.6.2+dfsg-1 Β· GPL-2.0-or-later
- ubuntu stonking: postgis 3.6.4+dfsg-2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms