Feature request #11604

DB Manager needs option to create a database connection

Added by Patrick Van Laake about 8 years ago. Updated about 6 years ago.

Category:DB Manager
Pull Request or Patch supplied:No Resolution:duplicate
Easy fix?:No Copied to github as #:19861


The DB Manager window currently has no option to create a new database connection. To create a connection to PostgreSQL I have to use the SPIT tool, after which the newly created connection can be selected in DB Manager.

postgres-conns.png (26.6 KB) Larry Shaffer, 2016-02-08 01:19 PM


#1 Updated by Paolo Cavallini about 8 years ago

No need for SPIT, you can add a connection from the Browser

#2 Updated by Giuseppe Sucameli over 7 years ago

  • Priority changed from Normal to Low

In this moment DBManager allows to add new Spatialite connections only.

Anyway you can add new PostgreSQL connections using "Add Postgis layer" from QGIS.

#3 Updated by Larry Shaffer almost 7 years ago

Adding a Postgres connection manager (for convenience) could be done in two ways:

  1. Make a manager from scratch in Python
  1. Use the Postgres provider's selectWidget() and strip out the 'Add Layer' bits
  1. Edit the QgsVectorDataProvider external plugin interface to provide a new connectionWidget() for managing just connections

The following hack-ish code works to slim the provider's current select widget down to just a connection manager GUI:

from PyQt4.QtGui import *
from PyQt4.QtCore import * 

dprovs = [d for d in QgsDataItemProviderRegistry.instance().providers() if 'postgres' in d.name()]
if dprovs:
    dpitem = dprovs[0].createDataItem('', None)

    dpitemw = dpitem.paramWidget()
    dpiteml = dpitemw.layout()

    grpbxitem = None
    for i in range(0, dpiteml.count()):
        w = dpiteml.itemAt(i).widget()
        if w and w.objectName() == 'connectionsGroupBox':
            grpbxitem = dpiteml.takeAt(i)

    if grpbxitem:
        btn = grpbxitem.widget().findChild(QPushButton, 'btnConnect')
        if btn:

        dlg = QDialog()
        dlg.setWindowTitle('Postgres Connections')
        lay = QVBoxLayout()
        btnbx = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        if dlg.exec_():
            # refresh the Postgres tree item
            print 'accepted'

See attached screenshot. This could be implemented as an action in the contextual menu for the Postgres parent tree item and as a toolbar action.

#4 Updated by Paolo Cavallini about 6 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

Duplicate of #4795

Also available in: Atom PDF