The solidDB® transaction log can be read with a Log Reader specific SELECT statement.
About this task
The transaction log can be read by multiple concurrently active SELECT statements at the same time. Each log read can be started from different log position, independently from the others.
Tip: The solidDB® package contains a sample application that demonstrates the use of the Log Reader interface. The sample application is available in the samples/logreader directory in the solidDB® installation directory.
Procedure
1 Read log data from the SYS_LOG table with a SELECT statement.
The basic syntax to read log is:
SELECT RECID, RELID, FLAGS, LOGADDR, DATA FROM SYS_LOG WHERE LOGADDR > ?;
The WHERE condition is allowed only for LOGADDR field. Only constraint that is allowed is greater than (>). Constraints to other fields will result in an error.
Alternatively, you can start the log read from a specified log position, defined with the LOGADDR field.
b Define the LOGADDR in the SELECT statement. For example:
SELECT RECID,RELID,FLAGS,LOGADDR,DATA FROM SYS_LOG WHERE LOGADDR > '0000000000000001FFFFFFFF0000029500000295';
Result When a read is started, the fetch calls will start returning rows. The user data for the log record is included in the DATA column in binary format.
When no data is available, the server will return empty data in one second intervals. In such a case, you can issue a new fetch call to see if new data is available.
For more details on the DATA column and other columns in the SYS_LOG table, see SYS_LOG table definition in the solidDB® SQL Guide.
2 Reconstruct the user data in the rows returned by the Log Reader.
Note The exact steps for handling the log records depends on the application design. The following steps are the basic steps that are needed to output the user data in a format that can be used to process the log records further.
a Get metadata for the column by querying the solidDB® system tables.
For example, in Java environments, the column metadata can be read from the solidDB® system tables using the ResultSet.getMetaData() call.
b Using the metadata, parse the data in the DATA column to produce output in the format of your choice.
For example, in the sample application (samples/logreader), the log records are converted into plain text SQL statements.