Exporting shapefile to PostGIS database in QGIS

You can use the DBManager core plugin

enter image description here


As @oyvind suggested, shp2pgsql is the best method for just getting the data into a PostGIS database. OpenGEO has a good startup guide for loading data into PostGIS that should get you up and running if you're having issues. As @nathanw pointed out, DB Manager is a good option for importing a shapefile into a database. Also available is PostGIS Manager, which is a great option if you're working specifically with PostGIS. @underdark has a great blog post about how to use it.

You'll need the database connection information (username, hostname or host address, and database name) as well as the SRID for the shapefile, but that is all covered in the OpenGEO startup guide. Good luck!


To export your vector file, with re-projection option using ogr2ogr, here is the command line:

ogr2ogr -overwrite -progress --config PG_USE_COPY YES -f PostgreSQL PG:"host=Your_host port=your_DB_port(5432) dbname=your_DB_name password=DB_password user=DB_user" dir_to_your_Vector(.shp, .gml, .geojson...) -nlt MULTIPOLYGON -lco SCHEMA=your_DB_schema(public) -lco GEOMETRY_NAME=geom -lco FID=id -nln your_Output_Table_Name -s_srs EPSG:your_Source_EPSG_code -t_srs EPSG:your_Target_EPSG_code

Don't forget to check that you have permissions to connect to the hose where the postgis is and to create the database.