views:

109

answers:

4

Advice/suggestions needed for a bit of application design.

I have an application which uses 2 tables, one is a staging table, which many separate processes write to, once a 'group' of processes has finished, another job comes along a aggregates the results together into a final table, then deletes that 'group' from the staging table.

The problem that I'm having is that when the staging table is being cleared out, lots of redo is generated and I'm seeing a lot of 'log file sync' waits in the database. This is a shared database with many other applications and this is causing some issues.

When applying the aggregate, the rows are reduced to about 1 row in the final table for every 20 rows in the staging table.

I'm thinking of getting around this by rather than having a single 'staging' table, I will create a table for each 'group'. Once done, this table can just be dropped, which should result in much less redo.

I only have SE, so partitioned tables isn't an option. Also faster disks for the redo probably isn't an option in the short term either.

Is this a bad idea? Any better solutions to be offered?

Thanks.

A: 

Loading each group into a separate table sounds like a fine plan to reduce redo. You can truncate individual group table following each aggregation.

Another (but I think probably worse) option is to create a new staging table with the groups that haven't been aggregated then drop the original and rename the new table to replace the staging table.

Nick Pierpoint
+2  A: 

Would it be possible to solve the problem by having your process do a logical delete (i.e. set a DELETE_FLAG column in the table to 'Y') and then having a nightly process that truncates the table (potentially writing any non-deleted rows to a separate table before the truncate and then copy them back after the table is truncated)?

Are you certain that the source of the log file sync waits is that your disks can't keep up with the I/O? That's certainly possible, of course, but there are other possible causes of excessive log file sync waits including excessive commits. There is an excellent article on tuning log file sync events on the Pythian blog.

Justin Cave
Yes, its definitely not due to excessive commits, this process does a single commit. Turning off this process massively reduces the redo. I have implemented the solution in the question, and it has greatly reduced the amount of redo and log file sync waits.
Matthew Watson
A: 

I prefer Justin's suggestion ("logical delete"), but another option to consider might be a partitioned table, if you have the EE licence. The aggregation process could drop a partition instead of deleting the rows.

Jeffrey Kemp
I believe Matthew indicated that he's got the standard edition so that partitioning isn't possible.
Justin Cave
Partitioned table would be ideal, however thats not an option. However, what i'm doing is essentially "poor mans partitioning". I never query outside of a "group" so there really isn't any need to have all rows accessible within a single query.
Matthew Watson
+1  A: 

The most common cause of excessive log file syncs is too frequent commits, which are often deliberately coded in a mistaken attempt to reduce system load due to locking. You should commit only when your business transaction is complete.

David Aldridge