To Store Transaction Logs in a Database
For multi-core machines, logging transactions to a database may be more
efficient. Transaction logging is designed to work with any
JDBC-compliant database. For databases with which transaction logging
has been tested, see the GlassFish Server Open Source Edition Release
Notes.
-
Create a JDBC connection Pool. To use non-transactional connections to
insert log records, you can either set the
non-transactional-connections
attribute to true
in this step, or you
can perform step 5 later.
-
Create a JDBC resource that uses the connection pool and note the
JNDI name of the JDBC resource.
-
Automatic table creation for the transaction logs is done by
default. However, if you would prefer to create the table manually, name
it txn_log_table
with the following schema:
Column Name |
JDBC Type |
LOCALTID
|
VARCHAR
|
INSTANCENAME
|
VARCHAR
|
SERVERNAME
|
VARCHAR(n)
|
GTRID
|
VARBINARY
|
The size of the SERVERNAME
column should be at least the length of the
GlassFish Server host name plus 10 characters.
The size of the GTRID
column should be at least 64 bytes.
4. Add the db-logging-resource
property to the transaction service.
For example:
asadmin set server-config.transaction-service.property.db-logging-resource="jdbc/TxnDS"
The property’s value should be the JNDI name of the JDBC resource
configured previously.
5.
If you didn’t set the non-transactional-connections
attribute to
true
in step 1 and you want to use non-transactional
connections to insert log records, use the following
asadmin create-jvm-options
command to reference an existing
transactional resource but use non-transactional connections for the
INSERT
statements:
asadmin create-jvm-options -Dcom.sun.jts.dblogging.use.nontx.connection.for.add=true
-
To disable file synchronization, use the following
asadmin create-jvm-options
command:
asadmin create-jvm-options -Dcom.sun.appserv.transaction.nofdsync
To define the SQL used by the transaction manager when it is storing its
transaction logs in the database, use the following flags:
-Dcom.sun.jts.dblogging.insertquery=sql
statement
-Dcom.sun.jts.dblogging.deletequery=sql
statement
-Dcom.sun.jts.dblogging.selectquery=sql
statement
-Dcom.sun.jts.dblogging.selectservernamequery=sql
statement
The default statements are as follows:
-Dcom.sun.jts.dblogging.insertquery=insert into txn_log_table values ( ?, ?, ?, ? )
-Dcom.sun.jts.dblogging.deletequery=delete from txn_log_table where localtid = ? and servername = ?
-Dcom.sun.jts.dblogging.selectquery=select * from txn_log_table where servername = ?
-Dcom.sun.jts.dblogging.selectservernamequery=select distinct servername from txn_log_table where instancename = ?
To set one of these flags using the asadmin create-jvm-options
command, you must quote the statement. For example:
create-jvm-options '-Dcom.sun.jts.dblogging.deletequery=delete from txn_log_table where gtrid = ?'
You can also set JVM options in the Administration Console. Select the
JVM Settings component under the relevant configuration. These flags and
their statements must also be quoted in the Administration Console. For
example:
'-Dcom.sun.jts.dblogging.deletequery=delete from txn_log_table where gtrid = ?'