2

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.

2 Answers 2

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!

4
  • 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. May 3, 2017 at 23:52
  • maybe you need to upgrade to the 2.16 LTS version of QGIS? May 4, 2017 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. May 6, 2017 at 22:04
  • @RussellFulton great! May 7, 2017 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.

1
  • 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. May 3, 2017 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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