I am running PostgreSQL/PostGIS version 12 (win10/64 bit) attempting to import shapefiles by means of shp2pgsql.exe. Really nothing happens. The GUI only blinks a fraction of a second. Then nothing. What am I doing wrong?
If you want a GUI to import shapefiles I recommend to use DB Manager (comes with QGIS) rather than shp2pqsql. DB Manager is a really efficient plugin which permits to import all kind of data (shapefiles, geojson, tif...) into PostGIS tables.
If you want to use the PyQGIS option, here's an example on how to automatize your PostGIS imports
from qgis.core import QgsVectorLayer, QgsVectorLayerExporter, QgsWkbTypes, QgsCoordinateReferenceSystem layer_path = 'path/to/my/layer' vlayer = QgsVectorLayer(layer_path, 'ogr') # Loading dataset # Checking the geometry type geometry_test = QgsWkbTypes.displayString(int(vlayer.wkbType())) check_format = False if geometry_test in 'Line': format = 'MultiLineString' check_format = True elif geometry_test in 'Polygon': format = 'MultiPolygon' check_format = True elif geometry_test in 'Point': format = 'MultiPoint' check_format = True else: print('Unable to find a correct geometry type') # Exporting the layer to postgis, replace db_arg with your db informations # The key parameter in db_arg is optionnal because id will be created if it doesn't already exist if check_format: db_arg = "host=localhost dbname='mydb' port=5432 user='postgres' password='mypassword' key='name_of_the_primary_key_column' type='" + format + "' table='the_name_for_the_postgis_table' (geom)" QgsVectorLayerExporter.exportLayer(vlayer, db_arg, 'postgres', QgsCoordinateReferenceSystem('4326'))
You just have to change the layer_path variable, the db_arg variable and optionally the QgsCoordinateReferenceSystem to put the projection you want for the import and that's it !