Question

I am using Oracle 11g.

I am trying to realize scenario of concurrent loading into a table with index rebuild. I have few flows which are trying to realize this scenario: 1. load data from source, 2. transform the data, 3. turn off the index on DWH table, 4. load data into DWH, 5. rebuild index on DWH table. I turn off and rebuild indexes for better performance, there are situations where one flow is rebuilding the index while the other tries to turn it off. What I need to do is to place some lock between points 2 and 3, which would be released after point 5.

Oracle built in LOCK TABLE mechanism is not sufficient, as the lock is released by the end of transaction, so any ALTER statement releases the lock.

The question is how to solve the problem?

Was it helpful?

Solution

Problem solved. What I wanted to do can be easily achieved using DBMS_LOCK package.

1. DBMS_LOCK.REQUEST(...)
2. ALTER INDEX ... UNUSABLE
3. Load data
4. ALTER INDEX ... REBUILD
5. DBMS_LOCK.RELEASE(...)

OTHER TIPS

You can use DBMS_SCHEDULER:

  1. run jobs that load and transform the data
  2. turn off indexes
  3. run jobs that load data into DWH
  4. rebuild indexes

enter image description here

Using Chains:

You have to range partition your table on minutes/hours basis of insertion time and enable indexes only when time is up. Each partition should have all indexes disabled after creation. Only one process can enable indexes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top