def _create_postgres_url(db_user, db_password, db_name, db_host,
                         db_port=5432, db_ssl_mode=None,
                         db_root_cert=None):
    """Helper function to construct the URL connection string

    Args:
        db_user: (string): the username to connect to the Postgres
            DB as
        db_password: (string): the password associated with the
            username being used to connect to the Postgres DB
        db_name: (string): the name of the Postgres DB to connect
            to
        db_host: (string): the host where the Postgres DB is
            running
        db_host: (number, optional): the port to connect to the
            Postgres DB at
        db_ssl_mode: (string, optional): the SSL mode to use when
            connecting to the Postgres DB
        db_root_cert: (string, optional): the root cert to use when
            connecting to the Postgres DB

    Returns:
        [string]: Postgres connection string
    """

    ssl_mode = ''
    if db_ssl_mode:
        # see
        # https://www.postgresql.org/docs/11/libpq-connect.html#
        # LIBPQ-CONNECT-SSLMODE
        ssl_mode = '?sslmode=%s' % (db_ssl_mode)
        if db_root_cert:
            ssl_mode += '&sslrootcert=%s' % (db_root_cert)

    return ('postgresql://%(user)s:%(password)s@%(host)s:%(port)s/'
            '%(db)s%(ssl)s' % {
                'user': db_user,
                'password': db_password,
                'db': db_name,
                'host': db_host,
                'port': db_port,
                'ssl': ssl_mode})