Author: Federico Gianoli
License: GNU GPLv3
QGIS version: ≥ 3.16
PG2GPKG is a QGIS plugin that exports entire PostgreSQL/PostGIS databases (or selected tables) to GeoPackage files. It supports three export modes, selective table export, and automatic rewriting of QGIS projects stored in the database.
-
Three export modes:
- One GeoPackage per schema (
output/schema.gpkg) - Everything in a single GeoPackage (
output/database.gpkg) - One GeoPackage per table (
output/schema/table.gpkg)
- One GeoPackage per schema (
-
Selective export: Tree widget with checkboxes allows selecting individual schemas and tables. Quick-select buttons for "all", "none", or "spatial only".
-
QGIS project export: Detects QGIS projects stored in the database (
qgis_projectstable), exports them as.qgsfiles, and rewrites all PostgreSQL datasource paths to point to the corresponding GeoPackage files. -
Handles edge cases:
fidfields of typedouble/real(GeoPackage requires integer FID)- SSL mode normalization (Qt enum → psycopg2 strings)
- Compressed project formats (zlib, ZIP/.qgz)
- System tables are automatically filtered out
-
Bilingual: Full Italian and English interface (auto-detected from QGIS locale).
- Download or create the
pg2gpkg.zipfile - In QGIS: Plugins → Manage and Install Plugins → Install from ZIP
- Select the ZIP file and click Install Plugin
- Copy the
pg2gpkgfolder to your QGIS plugins directory:- Windows:
%APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\ - Linux:
~/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ - macOS:
~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/
- Windows:
- Restart QGIS
- Enable the plugin in Plugins → Manage and Install Plugins
The plugin requires psycopg2. Install it if not already present:
pip install psycopg2-binaryOn Windows with OSGeo4W:
python -m pip install psycopg2-binary-
Open the plugin from Database → PG2GPKG → Export PostgreSQL to GeoPackage or from the toolbar icon.
-
Select a connection: Choose a registered PostgreSQL connection from the dropdown, or enter parameters manually.
-
Click "Connect and load schemas/tables" to populate the tree widget.
-
Select tables: Use checkboxes to select/deselect individual tables or entire schemas. Use the quick buttons:
- Select all — check everything
- Deselect all — uncheck everything
- Spatial only — check only tables with geometry columns
-
Choose export mode:
- One GeoPackage per schema — creates
schema.gpkgin the output folder, each containing all selected tables from that schema - Single GeoPackage — creates one file with all tables; if multiple schemas are selected, layer names are prefixed with
schema__ - One GeoPackage per table — creates a subfolder per schema with individual
.gpkgfiles
- One GeoPackage per schema — creates
-
Options:
- Export QGIS projects — finds projects in the
qgis_projectstable and exports them with rewritten datasource paths
- Export QGIS projects — finds projects in the
-
Select output folder and click Export.
-
Check the QGIS Log Messages panel (tab "PG2GPKG") for detailed progress and diagnostic information.
If you modify the .ts translation files, compile them to .qm:
cd pg2gpkg/i18n
lrelease pg2gpkg_it.tsOr use the provided script:
python pg2gpkg/i18n/compile_translations.pyAutore: Federico Gianoli
Licenza: GNU GPLv3
Versione QGIS: ≥ 3.16
PG2GPKG è un plugin QGIS che esporta interi database PostgreSQL/PostGIS (o tabelle selezionate) in file GeoPackage. Supporta tre modalità di esportazione, selezione selettiva delle tabelle e riscrittura automatica dei progetti QGIS salvati nel database.
-
Tre modalità di esportazione:
- Un GeoPackage per schema (
output/schema.gpkg) - Tutto in un unico GeoPackage (
output/database.gpkg) - Un GeoPackage per tabella (
output/schema/tabella.gpkg)
- Un GeoPackage per schema (
-
Esportazione selettiva: Widget ad albero con checkbox per selezionare singoli schemi e tabelle. Pulsanti rapidi per "tutto", "niente" o "solo spaziali".
-
Esportazione progetti QGIS: Rileva i progetti salvati nel database (tabella
qgis_projects), li esporta come file.qgse riscrive tutti i percorsi delle sorgenti dati PostgreSQL per puntare ai file GeoPackage corrispondenti. -
Gestione casi particolari:
- Campi
fiddi tipodouble/real(GeoPackage richiede FID intero) - Normalizzazione modalità SSL (enum Qt → stringhe psycopg2)
- Formati progetto compressi (zlib, ZIP/.qgz)
- Tabelle di sistema filtrate automaticamente
- Campi
-
Bilingue: Interfaccia completa in italiano e inglese (rilevamento automatico dalla lingua di QGIS).
- Scarica o crea il file
pg2gpkg.zip - In QGIS: Plugin → Gestisci e installa plugin → Installa da ZIP
- Seleziona il file ZIP e clicca Installa plugin
- Copia la cartella
pg2gpkgnella directory dei plugin QGIS:- Windows:
%APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\ - Linux:
~/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ - macOS:
~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/
- Windows:
- Riavvia QGIS
- Abilita il plugin in Plugin → Gestisci e installa plugin
Il plugin richiede psycopg2. Installalo se non già presente:
pip install psycopg2-binary-
Apri il plugin da Database → PG2GPKG → Esporta PostgreSQL in GeoPackage o dall'icona nella toolbar.
-
Seleziona una connessione: scegli una connessione PostgreSQL registrata o inserisci i parametri manualmente.
-
Clicca "Connetti e carica schemi/tabelle" per popolare l'albero.
-
Seleziona le tabelle con le checkbox. Usa i pulsanti rapidi:
- Seleziona tutto
- Deseleziona tutto
- Solo spaziali — seleziona solo le tabelle con colonne geometria
-
Scegli la modalità di esportazione.
-
Seleziona la cartella di output e clicca Esporta.
-
Controlla il pannello Messaggi di log di QGIS (tab "PG2GPKG") per informazioni dettagliate.