I have several QGIS documents that pull layers and tables from PostgreSQL / PostGIS databases. When I open the documents QGIS asks for the the credentials several (5-8+) times. Each document pulls its data from a single database, the credentials given have the same level of access to all layers and tables in the database. Is there a way to get the number of requests down to one per session?
I would recommend converting user name and password into a configuration, that is stored behind masterpassword in QGIS. This also means your user name and password are not stored as plain text in QGIS project file. I recommend reading authentication section in QGIS documentation: https://docs.qgis.org/3.16/en/docs/user_manual/auth_system/auth_overview.html One thing to note here: If you are adding data from different machines or opening your QGIS project file from different machines, your configuration ID-s should match. You can change configuration ID by clicking a padlock and unlock it.
In my case, removing the "sslmode=disable" text from each y the .qgs file solved the issue.
Looks like new layers added in my project do not add the sslmode param and old ones (maybe added with QGIS2 some time ago) all have the param in their datasource. This param caused asking for the user/pass two times every time I opened the project.