2

I am trying to import a shapefile to my database in postgres but there is no shapefile loader appearing in the plugin menu in PgAdmin.

enter image description here

Postgis is definitely installed as I have added it as an extension to my database

The postgis extension has already been created. But I continue to get a syntax error:

postgres=# CREATE EXTENSION postgis;
ERROR:  extension "postgis" already exists
postgres=# 
postgres=# shp2pgsql -I -s 4326 /Users/alexander/Downloads/pluto/pluto.shp pluto | psql -U postgres -d postgres;
ERROR:  syntax error at or near "shp2pgsql"
LINE 1: shp2pgsql -I -s 4326 /Users/alexander/Downloads/pluto/pluto....
        ^
postgres=# 

Any idea as to what the problem could be?

  • 1
    Press the jigsaw puzzle icon. – user30184 May 9 '16 at 22:31
  • You should either do this through the shp2pgsql gui, or, if you don't have that. you should run your command from outside postgres for example shp2pgsql -I -s 4326 /Users/alexander/Downloads/pluto/pluto.shp pluto | psql -U postgres -d postgres running that part from within the windows cmd/or the terminal if you are using linux. make sure that either your pgsql is added to the environment variable, or be physically in the postgres folder (using cd..) before you run your command – yanes May 9 '16 at 22:33
  • 1
    It looks like you're running the shp2pgsql within the psql window. That might not work because shp2pgsql is a command line utility - so it needs to be run from the command line window (and be part of the PATH env variable for ease of use). – SaultDon May 9 '16 at 22:37
  • What do you have in your ...\PostgreSQL\9.5\pgAdmin III\plugins.d folder? You can enable the shapefile loader plugin by placing the needed .ini file there if it's missing. – SaultDon May 9 '16 at 22:41
  • when I run from the command line I get -bash: shp2pgsql: command not found -bash: psql: command not found – the_darkside May 9 '16 at 22:45
5

To load shapefile to postgres database

  1. Go to start menu
  2. Search "POSTGIS 2.0 Shapefile and DBF Loader Exporter" and load your shapefile through it.

OR

  1. You can load your shapefile to QGIS.
  2. Connect to your database from within QGIS.

  3. Then use Database manager to import your shapefile to your desired postgres database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.