24.2.2. DB Manager Plugin¶
The DB Manager Plugin is intended to be the main tool to integrate and manage spatial database formats supported by QGIS (PostGIS, SpatiaLite, GeoPackage, Oracle Spatial, Virtual layers) in one user interface. The DB Manager Plugin provides several features. You can drag layers from the QGIS Browser into the DB Manager, and it will import your layer into your spatial database. You can drag and drop tables between spatial databases and they will get imported.
Themenu allows you to connect to an existing database, to start the SQL window and to exit the DB Manager Plugin. Once you are connected to an existing database, the menus (relevant for DBMSs, such as PostGIS / PostgreSQL) and will appear.
The TopoViewer.menu includes tools to create and delete (only if empty) schemas and, if topology is available (e.g. with PostGIS topology), to start a
The Run Vacuum Analyze for the selected table. Vacuum reclaims space and makes it available for reuse, and analyze updates statistics that is used to determine the most efficient way to execute a query. Change Logging... allows you to add change logging support to a table. Finally, you can Import Layer/File... and Export to File....menu allows you to create and edit tables and to delete tables and views. It is also possible to empty tables and to move tables between schemas. You can
The Providers window lists all existing databases supported by QGIS. With a double-click, you can connect to the database. With the right mouse button, you can rename and delete existing schemas and tables. Tables can also be added to the QGIS canvas with the context menu.
If connected to a database, the main window of the DB Manager offers four tabs. The Info tab provides information about the table and its geometry, as well as about existing fields, constraints and indexes. It allows you to create a spatial index on a the selected table. The Table tab shows the table, and the Preview tab renders the geometries as preview. When you open an SQL Window, it will be placed in a new tab.
18.104.22.168. Working with the SQL Window¶
You can use the DB Manager to execute SQL queries against your spatial database. Queries can be saved and loaded, and there the SQL Query Builder will help you formulate your queries. You can even view spatial output by checking Load as new layer and specifying Column(s) with unique values (IDs), Geometry column and Layer name (prefix). It is possible to highlight a portion of the SQL to only execute that portion when pressing Ctrl+R or clicking the Execute button.
The Query History button stores the last 20 queries of each database and provider.
Double clicking on an entry will add the string to the SQL window.
The SQL Window can also be used to create Virtual Layers. In that case, instead of selecting a database, select QGIS Layers under Virtual Layers before opening the SQL Window. See Creating virtual layers for instructions on the SQL syntax to use.