in postgresql_metrics/prepare_db.py [0:0]
def connect_as_super_user(db_name, conf):
db_connection = None
try:
db_connection = psycopg2.connect(database=db_name)
db_connection.autocommit = True
except psycopg2.OperationalError:
LOG.info("could not connect as local superuser with current user, credentials required")
if not db_connection:
superuser, password = query_user_for_superuser_credentials()
db_connection = get_db_connection(db_name, superuser, password,
host=conf['postgres']['host'],
port=int(conf['postgres']['port']))
if not db_connection or db_connection.closed:
raise Exception("failed connecting the database: " + db_name)
return db_connection