def create_db_connection(db_config, readonly=False, autocommit=False):
    'Creates a DB connection to the database.\n\n    Imports the config module, which results in the config being read from disk.\n    Changes to the config file made after this method has been called will not be read.\n\n    Calling entity should handle connection errors as appropriate.\n    '
    logger = logging.getLogger('dirbs.sql')
    logger.debug('Attempting to connect to the database {0} on host {1}'.format(db_config.database, db_config.host))
    conn = psycopg2.connect('{0} keepalives=1 keepalives_idle=240'.format(db_config.connection_string), cursor_factory=LoggingNamedTupleCursor)
    conn.set_session(readonly=readonly, autocommit=autocommit)
    logger.debug('Connection to database successful.')
    return conn
Creates a DB connection to the database.

Imports the config module, which results in the config being read from disk.
Changes to the config file made after this method has been called will not be read.

Calling entity should handle connection errors as appropriate.
def create_db_connection(db_config, readonly=False, autocommit=False):
    'Creates a DB connection to the database.\n\n    Imports the config module, which results in the config being read from disk.\n    Changes to the config file made after this method has been called will not be read.\n\n    Calling entity should handle connection errors as appropriate.\n    '
    logger = logging.getLogger('dirbs.sql')
    logger.debug('Attempting to connect to the database {0} on host {1}'.format(db_config.database, db_config.host))
    conn = psycopg2.connect('{0} keepalives=1 keepalives_idle=240'.format(db_config.connection_string), cursor_factory=LoggingNamedTupleCursor)
    conn.set_session(readonly=readonly, autocommit=autocommit)
    logger.debug('Connection to database successful.')
    return conn