You can configure external data sources to log details of each SQL query, including:
- the user making the query
- impersonation information, if any
- date and time
- the SQL statement used to query the data source
This topic describes how to configure and use SQL Query Logging on an external data source. Note that the labkeyDataSource 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.
Set Up
To configure an external 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".
<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&
useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL"
maxTotal="20"
maxIdle="10"
maxWaitMillis="120000"
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"/>
Viewing Logged SQL Queries
Logged SQL queries can be viewed in the Audit Log.
- Go to (Admin) > Site > Admin Console.
- Click Settings.
- Under Management, click Audit Log.
- Select Logged sql queries from the dropdown menu.
Related Topics