Don’t insert if permalink is the same?

You could add the additional check to your foreach loop to see if the post with exactly same slug as the one you’re about to add already exists.
Kinda difficult to tell exactly what you would have to do without seeing your current code.

I’m assuming you know the slug and a type of a post that you’re trying to insert?

You could look up the existing post with that slug first:

$existing_item = get_page_by_path( 'your-post-slug', OBJECT, 'your_post_type');

// null means that there is no post with that slug
if ( null === $existing_item ) {
    // proceed with inserting a post 
}

Bear in mind that this would affect your page performance even more, as you’re adding additional query to every item in the loop.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)