Premium Feature — Available in the Professional Plus and Enterprise Editions. Learn more or contact LabKey.

You can configure external data sources to log each SQL query, including the user making the query, impersonation information, date and time, and the SQL statement used to query the data source.

Set Up

To configure a data source to log queries, add a Parameter element to the labkey.xml file. For example, the following template uses a data source named “mySqlDataSource".

Note: This template applies to Tomcat 8 (or later). If you are using Tomcat 7, use the earlier template version in the documentation archives.

<Resource name="jdbc/mySqlDataSource" 
auth="Container"
type="javax.sql.DataSource"
username="myname"
password="mypassword"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/?autoReconnect=true&amp;
useUnicode=true&amp;characterEncoding=utf8&amp;zeroDateTimeBehavior=CONVERT_TO_NULL"

maxTotal="15"
maxIdle="7"
useInformationSchema="true"
accessToUnderlyingConnectionAllowed="true"
validationQuery="/* ping */"
/>

Add the following Parameter element. Note that ":LogQueries" has been appended to the name of the data source.

<Parameter name="mySqlDataSource:LogQueries" value="true"/>

The labkey data source itself cannot be configured to log queries in this way. Doing so will cause a warning in the server log at startup -- then startup will proceed as normal.

Viewing Logged SQL Queries

Logged SQL queries can be viewed in the Audit Log.

  • Go to (Admin) > Site > Admin Console.
  • Click Admin Console Links.
  • Under Management, click Audit Log.
  • Select Logged sql queries from the dropdown menu.

Related Topics

Discussion

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand all collapse all