Feb 8, 2010 4:37 AM
Autonomous Transactions for error logging
-
Like (0)
Hello,
we are having a requirement for logging the steps in stored procedure.
However, the problem is that if any step errors out, the entire procedure, including the logging (done by calling logging procedures in main procedure) gets rolled back. Hence neither can we see the changes done by the successful steps above the error step nor is any sort of logging recorded (for earlier successful steps and the errored step).
Is ther a way to resolve this.
Can Autonomous transaction be used in Netezza?
Thanks,
Parag
For the maximum visibility for operators, troubleshooters etc, logging should be the domain of flat log files. It is the only way to preserve the chain of events with complete context.
Also avoid having too many disparate or unrelated SQL operations in the same proc. A proc's reason for existence is to solve a difficult feature issue, not be the "place where all ELT runs". That's why it's a procedure, rather than a program.
The simple way is to use RAISE NOTICE to put debug messages into your code. If that isn't acceptable you could write a UDX which logs information to a file or possibly even invokes nzsql to insert a record into a table (very inefficient). See the section "Using UDXs with Stored Procedures" in the onstream dev guide for basic information as to how this can be done.
I need to see log records while the stored proc( it's batch process whcih takes half an hour) to check which step I am in. also to log when the error occured. I prefer log table over raise notice or external table.Please let me know the best way to achieve this(UDX or no UDX).
Is it possible to insert rows from UDX in netezza or any other database . If yes any thing i have to take care when I start writing the UDX.
You could write a UDX which calls nzsql to insert a row into a table. I'd recommened against doing that though. You are better off just writing data out to a flat file (using a UDX)
If you must use a log table, you can still access the rows after a rollback...
set show_deleted_records = true;
select * from mylogtable;
This will show all rows in the table, including those that were deleted.
That is brilliant one Nick. Would give it a 5* rating.

