I'm having a question on loading a PostGIS layer into the project from my QGIS plugin. The code is like this:

uri1 = qgis.core.QgsDataSourceURI() 
uri1.setConnection(str(host), str(port), str(database), str(user), str(password) )
uri1.setDataSource(str(schema), "layer", "geom")
qgis.utils.iface.addVectorLayer(uri1.uri(),"layer", "postgres")

It actually works fine but the performance is causing me lots of troubles. It takes up to 10 minutes, since there are about a 100,000,000 entries in the table.

When I load the layer manually using the PostGIS button on QGIS, there is a checkbox in the settings which says: "Geschätzte Tabellenmetadaten nutzen". In english this would be: "Use estimated table metadata". When checked, the layer loads in realtime.

My question is: Is there a way to load a PostGIS layer into QGIS using the estimated table metadata, and thus increase performance significantly?

1 Answer 1


Can you try


before setting the connection ?

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.