Hello, welcome to QGIS Tutorial. Today, I am going to import some vector layers to my PostGIS database using DB Manager on QGIS. In the previous tutorial, I was successfully imported vector layer to PostGIS database using Import into PostGIS toolbox. But now, I am going to import the same data in a different way. Well, there are several ways to import spatial data into PostGIS.
QGIS DB Manager Overview
QGIS comes with a special database manager which is pretty handy to handle some databases supported by QGIS. For example, PostGIS, GeoPackage, and Spatialite. To open DB Manager, go to Database | DB Manager from the QGIS main menu. In the DB Manager window, you will see a list of databases that are connected with QGIS. Within the DB Manager window, we can also import layer and export layer to a file. It also supports SQL operation in a separate window.
Import Layer to PostGIS via DB Manager
Before we can import our layer to PostGIS, we need to create a connection to the PostGIS itself. Also, make sure you have enabled the PostGIS extension on your PostgreSQL database. You can read this article in order to create a new connection to PostGIS. Once you have a connection to your PostGIS database, you can open the DB Manager. You should see your connections there. As you can see, in the picture below I have several PostGIS connections to my servers.
To start importing the layer, simply select the database from the list. Usually, it’s under the Public schema. Then, click Import Layer/File button on the top of the window. Next, specify the layer or file we want to import. Give a name on the output table. There are also some options such as enable the primary key, geometry column etc.
Make sure this process returned no errors.
Viola, the layer is now in the PostGIS database format.
Another useful functionality of this DB Manager is we can rename and delete PostGIS table. Simply right click on the table and choose rename or delete.