I want to get attributes like schema name and table name from PostgreSQL and PostGIS loaded layers in QGIS 3. I've searched in API docs but just found about set data sources, anyone knows how to get this info?
You can get this information from your layer with the
source() method. It returns the same string that you can see when you hover the layer in the legend, then you can parse it. As the postgres/postgis source contains sensitive data (e.g. password), you can alternatively use
publicSource() to get only non-sensitive data.
layer = iface.activeLayer() #select a postgis layer before running that source = layer.source() public_source = layer.publicSource() print source print public_source