Skip to Main Content
  • Questions
  • Insert into statement running for 7+hrs on an table having 450 million records

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: October 08, 2022 - 5:26 am UTC

Last updated: October 13, 2022 - 12:31 pm UTC

Version: oracle 19c standard edition on rds amazon

Viewed 10K+ times! This question is

You Asked

Hello ,

Database :- Oracle 19c Standard edition

we are trying to Insert around 450 million records from Table A into Table B using the below query

insert into table a  (col1,col2,col3,col4,...,col31 in)
select col1,col2,col3,col4,...,col31 in from table b;


this query is been executing for 7+hrs.

we checked the V$session_longops around 6hrs ago (03.30am IST) and it was showing a remaining time of around 288 mins with ~17% completion rate.
when we are checking it now it shows 280 mins as time remaining after 7+ hrs

We have made all indexes unusable as well on the table.

the DBA team is also monitoring and don't see any resource crunch or tablespace issues.

is there a way to improve this.

Thanks

and Chris said...

Several hours to insert 450 million rows is excessive. If the query really is just reading from one table and you've disabled indexes there's not a huge amount you can do to tune the statement.

It sounds like the insert is stuck waiting on... something. To figure out what Tanel Poder's snapper script can come in handy here:

https://github.com/tanelpoder/tpt-oracle/blob/master/snapper.sql

Until we have this information there's minimal help we can give - we're just guessing what the problem is.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Any triggers on the target table?

A reader, October 11, 2022 - 9:30 am UTC


Check for any triggers on the target table.
Hope it help!

Cheers

Chris Saxon
October 11, 2022 - 2:28 pm UTC

Could be

Direct path inserts...

Rajeshwaran, Jeyabal, October 13, 2022 - 7:53 am UTC

For these kind of large data sets to be inserted, we should be look for Direct path loads and not conventional path inserts.

lets say if that above dml got failed after X hours, then you would spend a huge time for rollback, which is why conventional path inserts are unlikely for huge datasets, also the amount of redo generated would be the another possible reason.

https://asktom.oracle.com/pls/apex/asktom.search?tag=inserts-with-append-hint
Chris Saxon
October 13, 2022 - 12:31 pm UTC

While true, I'm not sure this helps the OP with the specific issue of why their current statement is taking so long.

Any clue in alert log

Narendra, October 25, 2022 - 10:56 am UTC

If the slowness is caused due to either log switches or space pressure then alert log should indicate whether redo logs are struggling to keep up with the amount of redo being generated. Could it be data files either not extending or extending by small size (and hence having to increase frequently) and the user session doing INSERT getting suspended often?

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.