Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Inserting records into table makes UNDOTBS1 very big !

Posted on 2008-10-27
10
Medium Priority
?
628 Views
Last Modified: 2012-08-14
Hello Experts !

I've got two tables in Oracle 10.1g

TableA
16,594,824 records

TableB
0 records, same structure as TableA

I don't have too much free space in my disk, so I need to get tablespace UNDOTBS1 as small as possible.

When I try to insert the 16 millions rows of TableA into TableB like:

INSERT INTO TableB (select * from TableA);

then UNDOTBS1.DBF gets huge, like 7GB.

I set up UNDO_RETENTION in this way:

ALTER SYSTEM SET UNDO_RETENTION = 5;

I thought that doing that, UNDOTBS1.DBF won't get big.

My questions are:

1. Is the size of UNDOTBS1.DBF affected because setting up "ALTER SYSTEM SET UNDO_RETENTION = 5" or setting up "ALTER SYSTEM SET UNDO_RETENTION = 900";

2. Is there any way that UNDOTBS1.DBF and UNDOTBS1 don't grow so much? I know how to shrink UNDOTBS1.DBF after all transactions are commit, but don't know how to prevent it!
0
Comment
Question by:miyahira
  • 4
  • 3
10 Comments
 
LVL 48

Accepted Solution

by:
schwertner earned 800 total points
ID: 22813894
Setting
ALTER SYSTEM SET UNDO_RETENTION = 5;
you will keep the undo data only 5 minutes,
so you have to expect that in 5 minutes
the UNDO tablespace will shrink.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22813951
> so you have to expect that in 5 minutes the UNDO tablespace will shrink.

It didn't. On the contrary, it got bigger up to 7GB until "INSERT INTO TableB (select * from TableA);" finished
0
 
LVL 48

Expert Comment

by:schwertner
ID: 22814018
Yes, because this happens in that 5 minutes frame.
Only after 5 minutes it will shrink.
It waits for COMMIT or ROLLBACK statement
to decide what to do.
Write ROLLBACK; and it will shrink.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Expert Comment

by:schwertner
ID: 22814051
So I think it will count the time after COMMIT statement.
Before COMMIT it is possible to get ROLLBACK and so
no entries could be emptied.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22814075
Ok, I got it!

Would you mind suggesting me how to make COMMIT when running this command:

INSERT INTO TableB (select * from TableA);

Should it be using CURSOR in a stored procedure? I wouldn't like to load in memory 16 millions records.

Many thanks.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22814084
I mean: how to make COMMIT every 5 minutes when running this command:
INSERT INTO TableB (select * from TableA);
0
 
LVL 10

Assisted Solution

by:dbmullen
dbmullen earned 800 total points
ID: 22815731
few options:
  1)  use oracle copy command and
            change the copycommit and arraysize until you don't have UNDO issues
             see snippet

  2)  why are you inserting data twice?
            drop table tableb;
            create or replace view tableb as select * from tablea;


set arraysize 100
set copycommit 50
truncate table  TableB ;
COPY FROM username/password@source_db TO username/password@target_db insert  TableB  USING SELECT * FROM  TableA;

Open in new window

0
 
LVL 48

Expert Comment

by:schwertner
ID: 22819560
SELECT statement will load in memory all record, but not all of them
will be there. Do not worry about this.
The suggestion of Dbmullen is OK!
You can also try to use stored procedure and cursor inside.
This has some advantages like possibilities to edit the records
on the fly. Also very good control on the flow.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question