9

In QGIS I have a project with data from various (~15) PostGIS databases, with no login credentials (authentication user/pwd) stored for each of the connections as shown below.

enter image description here

Now when another user opens the project, he (or she) has to enter credentials for EACH database used:

enter image description here

I strongly fear that legitimatly none of my users is going to accept entering his (or her) credentials 15 times (but in an enterprise environment with potentially 100s of users, acceptance is key for success).

So two questions arise for me:

  • is there a way to suggest the Username according to the global project variable user_account_name and
  • is there a way to tell QGIS to use the credentials entered for the first db connection for any other connection as well?

I can't estimate if it would be a great deal to modify the 'Enter Credentials' dialogue as proposed below, but is this possible?

enter image description here

6
  • so only the "Realm" is changing while all other variables stay the same?
    – LaughU
    Jul 13, 2017 at 7:16
  • yes, within the real only the 'dbname' is changing. it's all on the same server. Jul 13, 2017 at 7:26
  • 5
    PostGIS is the spatial extension. You have over a dozen PostgreSQL databases. While you might be able to cobble together a kludge, you really ought to have one large database. Connecting to more than three is just poor application/database design.
    – Vince
    Jul 13, 2017 at 10:30
  • 3
    Very heplful... Sorry that my english isn't good enough to make clear that my question is not about application/database design. And by the way, I allways thought that PostGIS implies PostgreSQL, and that in QGIS we establish PostGIS connections (cp. screenshot above). While some postgres people say that it is good practice to distribute different content in different databases where possible, please let me participate in from where you know that connecting to more than three databases is poor application design? Please, please provide the related literature reference! And why three?! Jul 14, 2017 at 8:50
  • 1
    I can't point you to literature, but a good solution could be to use seperate schemas within the same database. Jun 5, 2019 at 9:14

1 Answer 1

7

QGIS has a built-in Authentication System. Simply speaking you have a protected database with all your credentials, stored in one qgis-auth.db file, that you can send to someone else, who knows a master password:

 .qgis folder

When you create some new PostGIS connection, instead of typing your login/password you can select it from qgis-auth.db (each login/password pair has a user friendly name).

Set up PostGIS connection in QGIS with the Authentication System

As an example, I have a QGIS project which contains many layers. Each layer is a connection to a remote PostGIS database. Each database has its own user. When I open this project, I have to print a master password once, and all the layers (db connections) start to work.

I can send this project to my colleague, providing my qgis-auth.db file. Beforehand I may delete some credentials that I don't want to share from this file.

After my colleague put qgis-auth.db to his .qgis folder (he may make a backup of his own file before), he opens the project, enters the master password and everything works.

You enter a master password once per session.

4
  • 1
    After my colleague put qgis-auth.db to his .qgis folder (he may make a backup of his own file before), but this isn't going to work in a larger organisation with 100+ users. Can we move this .db file to a shared location and get all 100+ QGIS files to point to it?
    – Theo F
    Oct 14, 2022 at 11:30
  • The parent directory of the qgis-auth.db can be set using the following environment variable, QGIS_AUTH_DB_DIR_PATH, or set on the command line during launch with the --authdbdirectory option. So, it seems that you could put it on a shared drive.
    – Yaroslav
    Oct 26, 2022 at 7:12
  • thanks for the info. But surely you'd have to manually change the environment variable on 100+ machines if doing this for 100+ users?
    – Theo F
    Oct 26, 2022 at 13:28
  • "But surely you'd have to manually change the environment variable" - you can create a batch file which sets the environment variable for the session, and then launches QGIS. Or simply launches QGIS with the command line option. And distribute the fille, or a link to the file if you put in to a network share as well.
    – v_b
    May 26 at 17:12

Your Answer

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

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