def METHOD_NAME(aggregator, dd_run_check, integration_check, pg_instance):
    check = integration_check(pg_instance)
    check._connect()
    def execute_in_thread(q, args):
        with psycopg.connect(
            host=HOST, dbname=DB_NAME, user="bob", password="bob", cursor_factory=ClientCursor
        ) as tconn:
            with tconn.cursor() as cur:
                # this will block, and eventually throw when
                # the deadlock is created
                try:
                    cur.execute(q, args)
                except psycopg.errors.DeadlockDetected:
                    pass
    appname = 'deadlock sess'
    appname1 = appname + '1'
    appname2 = appname + '2'
    appname_sql = "SET application_name=%s"
    update_sql = "update personsdup1 set address = 'changed' where personid = %s"
    deadlock_count_sql = "select deadlocks from pg_stat_database where datname = %s"
    with check._new_connection(pg_instance['dbname']).connection() as conn:
        with conn.cursor() as cursor:
            cursor.execute(deadlock_count_sql, (DB_NAME,))
            deadlocks_before = cursor.fetchone()[0]
    conn_args = {'host': HOST, 'dbname': DB_NAME, 'user': "bob", 'password': "bob"}
    conn1 = psycopg.connect(**conn_args, autocommit=False, cursor_factory=ClientCursor)
    cur1 = conn1.cursor()
    cur1.execute(appname_sql, (appname1,))
    cur1.execute(update_sql, (1,))
    args = (appname2, 2, 1)
    query = """SET application_name=%s;