I have an INSERT query in Oracle 10g that is getting stuck on a “SQL*Net message from dblink” event. It looks like:
INSERT INTO my_table (A, B, C, ...)
SELECT A, B, C, ... FROM link_table@other_system;
I do not see any locks on my_table besides the one from the INSERT I’m trying to do. The SELECT query on link_table@other_system completes without any trouble when run on its own. I only get this issue when I try to do the INSERT.
Does anyone know what could be going on here?
UPDATE
The SELECT returns 4857 rows in ~1.5 mins when run alone. The INSERT was running over an hour with this wait message before I decided to kill it.
UPDATE
I found an error in my methods. I was using a date range to limit the results. The date range I used when testing the SELECT only was before the last OraStats run on the link_table, but the date range that I used when testing the INSERT was after the last OraStats run on the link_table. So, that mislead me to believe there was a problem with the INSERT. Not very scientific of me to do this; my mistake.
Are you using a
/*+ driving_site(link_table) */hint to make Oracle perform the joins on the remote server?If so, that hint will not work with DML, as explained by Jonathan Lewis on this page.
This may be a rare case where running the query just as a
SELECTuses a very different plan than running the query as part of anINSERT. (You will definitely want to learn how to generate explain plans in your environment. Most tools have a button to do this.)As Andras Gabor recommended in the link, you may want to use PL/SQL
BULK COLLECTto improve performance. This may be a rare case where PL/SQL will work faster than SQL.