Informix

 View Only
Expand all | Collapse all

Inspect transactions log

  • 1.  Inspect transactions log

    Posted 28 days ago
    Hi. We use INFROMIX 14. 
    Yesterday we discovered that there was no record in the database for one operation for May 27, in the software logs this operation was completed successfully, but in the database it was completely missing, as if it never happened. Is there a way to see if there were any transaction rollbacks for a specific time?
    And how to enable logging of transaction rollbacks?


    ------------------------------
    Alexander Ivanov
    ------------------------------


  • 2.  RE: Inspect transactions log

    Posted 28 days ago

    Hi Alexander

    trivial, but first check that the database is not in "with no log" mode: if it is "with no log", you won't see any transaction

    Second, if you db is logged, use the onlog utility  (The onlog utility

    Ibm remove preview
    The onlog utility
    The onlog utility displays the contents of a logical-log file, either on disk or on backup.
    View this on Ibm >

    )

    Reading the output is not plain simple, but with some tricks you can fully understand all the transactions, row by row

    Hope this helps

    Eric



    ------------------------------
    [eric] [Vercelletto] []
    [Founder]
    [kandooerp.org]
    [Pont l'Abbé] [France]
    [+33 626 52 50 68]

    Disclaimer: My own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves.
    ------------------------------



  • 3.  RE: Inspect transactions log

    Posted 28 days ago
    Edited by Alexander Ivanov 28 days ago
    Thank you. I was able to read the log file and found no transactions at this time.
    Immediately after this operation the server was rebooted and in the logs I see 17:20:18 Physical Recovery Started at Page (2:469382). 17:20:19 Physical Recovery Complete: 976 Pages Examined, 244 Pages Restored. 17:20:19 Logical Recovery Started. 17:20:19 5 recovery worker threads will be started. 17:20:22 Logical Recovery has reached the transaction cleanup phase. 17:20:22 Logical Recovery Complete. 0 Committed, 0 Rolled Back, 0 Open, 0 Bad Locks I'm interested in Physical Recovery Complete: 976 Pages can this overwrite data?



    ------------------------------
    Alexander Ivanov
    ------------------------------



  • 4.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    Alexander:

    So, on one level the direct answer to your question is that "yes" physical recovery does overwrite data and is intended to do so. "Physical recovery" is the engine finding data in the physical log. Those pages are the original versions of any page that was modified since the last checkpoint before the server crashed. During a normal shutdown the physical log is wiped clean after all modified pages in the cache and logical log buffers have been flushed to disk, so, the physical log is empty on restart after a normal shutdown. If there are pages in the physical log on startup that tells the engine that it had crashed and a) some data was never flushed to disk, and b) some page written during the crash may have only been partially written since an Informix data page is the size of multiple disk "pages". To fix the possibility that some pages were partially written, and consequently essentially "corrupted", the engine overwrites those pages it finds in the physical log with their original images stored there. Then "logical recovery" (aka "fast recovery") begins. This is where the engine goes through the logical logs on disk looking for the last completed checkpoint (since non-blocking checkpoints do not complete the physical flushing until after the "checkpoint" itself has completed, that may be a checkpoint earlier than the last one noted in the logs). At that point, knowing that any corrupted pages have been repaired to their state before the last checkpoint, the engine begins to roll forward all logical log records written to disk after that completed checkpoint. When "fast recovery" reaches the end of the logical logs, it determines if any transactions were not COMMITed. If so, those transactions are automatically rolled back after which the engine is ready for use.

    Either way, if that missing data was actually written to the server, it would have been found in the logical logs, even if it was rolled back during recovery. There is one scenario under which you would not find the data in the logical logs:

    IF and ONLY IF the database containing the affected table(s) was set up as BUFFERED LOG AND the logical log buffers were big enough that the entire transaction was contained in a single logical log buffer with room to spare, AND that buffer was never flushed before the crash (because with BUFFERED LOG databases the logical log buffers are ONLY flushed to disk when they are completely full). Then that transaction (and perhaps others as well as the COMMIT records of other transactions the completed in that buffer) will have never been flushed to disk and so will appear to have never happened. 

    This is why I ALWAYS and STRONGLY recommend to my clients that all databases be created with UNBUFFERED LOG mode set. In that mode the logical log buffer is flushed immediately upon any COMMIT record having been written to it. That means that no committed transaction can be lost unless the server or its host happens to crash between the COMMIT having been written to the log and the log being flushed to disk. This is vanishingly unlikely compared to the likelyhood of a small transaction being lost in a BUFFERED LOG database.

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 5.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    To expand on what Art already elaborated on: what exactly do you mean by "the server was rebooted"?

    Was it an Informix shutdown and restart, in which case any log buffer content would have been flushed to disk during the shutdown - and such problem should not have occurred?

    Or was it a host reboot without any regard to the database server running on the host?



    ------------------------------
    Andreas Legner
    ------------------------------



  • 6.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    Alexander:

    Just to wrap up Eric's post, rollbacks are a;ways logged as long as the database is not an UNLOGGED database.

    That said, once the transaction is COMMITed there is no way to roll it back. Is it possible that the application has a code path that might not actually issue a COMMIT WORK statement and it only "thought" that the transaction was completed successfully? 

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 7.  RE: Inspect transactions log

    Posted 28 days ago

    Thank you. I will ask my developers about your proposal. But I'm sure they will say NO :)



    ------------------------------
    Alexander Ivanov
    ------------------------------



  • 8.  RE: Inspect transactions log

    Posted 28 days ago

    Is there a way to permanently log a SQL trace to a text file?



    ------------------------------
    Alexander Ivanov
    ------------------------------



  • 9.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    Alexander:

    Depends on what you mean be "an SQL trace"? 

    If you turn one SQLTRACE, you could poll the sysmaster tables related to SQLTRACE, those with names that match "sqltrace*" and write the data to disk. I do that for the Level 2 and Level 3 Informix Health Checks that I perform for clients. However, most often too many queries hit the server too fast to ever capture everything. Also, if a transaction involves multiple statements, it is even less likely that you would capture enough of the stream of statements in the transaction to be able to tell what had happened to your missing data.

    If SQLTRACE is not enabled, then there really is no way to capture running SQL. There are sysmaster tables that contain currently running SQL, but there is no history there. Only live queries are available (OK in some cases the previous statement for particular sessions).

    Let me ask you back: Is the database in question a BUFFERED LOG database? If so, you just need to change the database's logging mode to UNBUFFERED LOG using ontape, ondblog, or the SQL API function "alter logmode". I have never seen a single committed transaction lost with UNBUFFERED LOG set.

    Also, as pointed out, make sure that your system's shutdown scripting performs a normal shutdown of the Informix instance(s) on the host before stopping the OS for a restart or power down.



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 10.  RE: Inspect transactions log

    Posted 28 days ago

    DB in Buffered LOG mode. This is the first time I've ever seen a transaction disappear. However, judging by the logs, the software was completed correctly, and then they simply rebooted the server OS without turning off Informix. Could this be causing the problem? I looked through the logical log and did not find the transaction data.



    ------------------------------
    Alexander Ivanov
    ------------------------------



  • 11.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    Yep, that's exactly what unbuffered logging is meant to protect against, at the cost of some performance:

    either an OS reboot or some other form of uncontrolled Informix termination, e.g. a crash.



    ------------------------------
    Andreas Legner
    ------------------------------



  • 12.  RE: Inspect transactions log
    Best Answer

    IBM Champion
    Posted 28 days ago

    Alexander:

    Yea, what Andreas said! BUFFERED LOG is indeed the actual reason why the transaction was lost but the proximate cause was the uncontrolled crashing of the server when the OS was shutdown out from under the Informix instance so that it did not have a chance to flush that last logical log buffer containing the transaction operations and COMMIT record nor the updated data and index pages still dirty in the buffer pool. Either having been flushed would have prevented the data loss, and if the database had been UNBUFFERED LOG the when your application submitted the COMMIT WORK statement and it was written to the logical log buffer, that write would have forced that log buffer to flush to disk saving the transaction and making it available for fast recovery to rerun on startup.

    Again though, make sure that the system shutdown scripts ALWAYS shutdown the database (onmode -ky) before shutting down the OS. That also would have prevented the data loss. Doing both UNBUFFERED LOG and correctly shutting down the Informix instance is the kind of paranoia that is the reason we DBAs get the big bucks!

    Art



    ------------------------------
    Art S. Kagel, President and Principal Consultant
    ASK Database Management Corp.
    www.askdbmgt.com
    ------------------------------



  • 13.  RE: Inspect transactions log

    IBM Champion
    Posted 28 days ago

    Using "onmode -kuy" (rather than only -ky) would also roll back any open transactions "while they're still fresh", saving this effort during fast recovery where it might be more expensive (cold bufferpool) and also a little more risky (hardly any risks left after all those years of bug fixing).



    ------------------------------
    Andreas Legner
    ------------------------------



  • 14.  RE: Inspect transactions log

    Posted 27 days ago

    Thanks everyone. I figured out what my problem is and will try changing the logging mode. And I'll remind local system administrators how to properly close Informix.



    ------------------------------
    Alexander Ivanov
    ------------------------------



  • 15.  RE: Inspect transactions log

    Posted 27 days ago

    What's your operating system? 

     

    If it's any Linux or Unix, you can have the onmode -ky or onmode -yuk in the shutdown routine.  I would put it in the transition from run level 4 (or whatever your fully operational state is) to run level 3 (or whatever your next lower state is).  Look for configuration options in places like /etc/init.d or /etc/rc.d.

     

    If it's Windows, check the configuration on the service, it should also shut down the server cleanly before rebooting the computer.

     

                                    --EEM