diff --git a/python/plugins/db_manager/db_plugins/postgis/connector.py b/python/plugins/db_manager/db_plugins/postgis/connector.py
index ef15694..bcaeb3f 100644
--- a/python/plugins/db_manager/db_plugins/postgis/connector.py
+++ b/python/plugins/db_manager/db_plugins/postgis/connector.py
@@ -51,8 +51,8 @@ class PostGisDBConnector(DBConnector):
         username = uri.username() or os.environ.get('PGUSER') or os.environ.get('USER')
         password = uri.password() or os.environ.get('PGPASSWORD')
 
-        self.dbname = uri.database() or os.environ.get('PGDATABASE') or username
-        uri.setDatabase(self.dbname)
+        #self.dbname = uri.database() or os.environ.get('PGDATABASE') or username
+        #uri.setDatabase(self.dbname)
 
         expandedConnInfo = self._connectionInfo()
         try:
diff --git a/python/plugins/db_manager/db_plugins/postgis/plugin.py b/python/plugins/db_manager/db_plugins/postgis/plugin.py
index 54d500d..f3549d8 100644
--- a/python/plugins/db_manager/db_plugins/postgis/plugin.py
+++ b/python/plugins/db_manager/db_plugins/postgis/plugin.py
@@ -30,6 +30,8 @@ from qgis.gui import QgsMessageBar
 from ..plugin import ConnectionError, InvalidDataException, DBPlugin, Database, Schema, Table, VectorTable, RasterTable, \
     TableField, TableConstraint, TableIndex, TableTrigger, TableRule
 
+import os
+
 try:
     from . import resources_rc
 except ImportError:
@@ -262,12 +264,17 @@ class PGRasterTable(PGTable, RasterTable):
         if not uri:
             uri = self.database().uri()
         schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
-        dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
+
         host = (u'host=%s' % uri.host()) if uri.host() else ''
-        user = (u'user=%s' % uri.username()) if uri.username() else ''
         passw = (u'password=%s' % uri.password()) if uri.password() else ''
         port = (u'port=%s' % uri.port()) if uri.port() else ''
 
+        user = uri.username() or os.environ.get('PGUSER') or os.environ.get('USER')
+        dbname = uri.database() or os.environ.get('PGDATABASE') or user
+
+        user = (u'user=%s' % user) if user else ''
+        dbname = (u'dbname=%s' % dbname) if dbname else ''
+
         # Find first raster field
         col = ''
         for fld in self.fields():
