1

I have a QGIS project which uses PGSQL in the back end. I am now setting up multiple instances of the database (dev, working and published) with a mechanism to migrate data between the in a systematic manner.

Is there a straight forward way of changing the database name in a QGIS project so I can quickly test things after performing migrations? i.e just change the database leaving schema, tables. etc the same.

3

We use the ChangeVectorDataSource plugin, which gives you access to the connection string a layer is using.

You can simply right-click a layer, and change the database parameters:

dbname='databasename' host=server port=5432 user='username' password='****' sslmode=disable key='elem_num' srid=4326 type=MultiPolygon table="dpsdata"."schoolboundaries_elem" (geom) sql=

Click OK and you're all set.

Works for us!

  • This certainly sounds like what I need but when I try and install it on my version of QGIS (2.14.3) it comes up as "broken" :( I have filed an issue on github. I'll accept the answer anyway. – Russell Fulton May 3 '17 at 23:52
  • maybe you need to upgrade to the 2.16 LTS version of QGIS? – DPSSpatial May 4 '17 at 16:02
  • That worked. Thanks for the suggestion. The developer responded to my issue report and we decided that something had got screwed up in my python environment as I had recently had issues trying to install the plugin development tools. It did not occur to either of us to try reinstalling QGIS. – Russell Fulton May 6 '17 at 22:04
  • @RussellFulton great! – DPSSpatial May 7 '17 at 15:02
3

QGIS project files are just xml. Can't you just do a find and replace on the file? Obviously being careful of changing any other string which aren't the database name. If that's too naive maybe you could parse the xml for the tag for the db name.

  • This approach would be useful as a part of scripted migration and I may actually do write a script to mangle the xml. But this isn't something I would generally recommend. – Russell Fulton May 3 '17 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.