Question

There are few shell scripts that use the isql to execute some sql statements on a Sybase database server. I see several Log Suspend messages in the logs and the problem is that the shell script exits with success.

The transaction log in database MAIN_DB is almost full. Your transaction is being suspended until space is made available in the log.

I need to intercept these Log suspend messages and report the correct error. How do I do this? I am not sure about how to proceed here. When it occurs there is no way it gets cleared and the database administrator has to kill the spid after a some time, but the script already exits with success. So, the data-transfer didn't actually happen and was aborted. This is the scenario I need to handle.

Please let me know how we would be able to intercept the Log Suspend and atleast wait for a particular time ?

Was it helpful?

Solution

You have two issues. One is the script does not detect errors correctly. Secondly the transaction log is filling up frequently.

First the script needs to have the standard output AND the error output go to your log file. When you use the > it is using file descriptor 1. When you want to capture error output you need to use 2> for file descriptor 2. So the command would look like the following.

isql > error.log 2> error.log

Better yet use this

isql 2>&1 > error.log

The previous says to have file descriptor 2 go to file descriptor 1.

Now to detect errors look for "Msg" which all errors have in front.

Secondly to resolve the transaction log space, you need to grow the log size which should be on its own device. Then you need to set the threshold to dump the completed transactions to a disk file automatically. You need to investigate the following commands.

sp_helpthreshold
sp_addthreshold
sp_thresholdaction

Good SQL, good night.

OTHER TIPS

You can check the processes inside the databases, and look for a process status of 'LOG SUSPEND'. Specifiying the username is optional.

sp_who {USERNAME}

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