4
The Query Log plugin logs queries to :ref:`logging-destinations`. When :program:`drizzled` is started with ``--plugin-add=query-log``, the query log plugin is enabled but all logging destinations are disabled to prevent flooding on busy servers because *all* queries are logged by default. A destination can be enabled on the command line or later with ``SET GLOBAL``, and various thresholds can be set which restrict logging.
6
All query log system variables are global and dynamic so they can be changed while Drizzle is running.
13
.. option:: --query-log.file FILE
15
| Default: :file:`drizzled-queries.log`
16
| Variable: ``query_log_file``
18
The query log file. The file is created if it does not exist. If a full
19
path is not specified, the default relative path is the :file:`local`
20
directory under the :option:`--datadir` directory.
22
.. option:: --query-log.file-enabled
25
| Variable: ``query_log_file_enabled``
27
Enable logging to :option:`--query-log.file`.
28
This logging destination is disabled by default. Specify this option to
29
enable it from the command line, or it can be enabled once Drizzle is running
30
by executing ``SET GLOBAL query_log_file_enabled = TRUE``.
32
.. option:: --query-log.threshold-execution-time MICROSECONDS
35
| Variable: ``query_log_threshold_execution_time``
37
Log queries with execution times greater than ``MICROSECONDS``.
38
The query log file writes ``execution_time`` as seconds with six decimal
39
place of precision, but this option must specify a number of microseconds.
40
See :ref:`converting-seconds-to-microseconds`.
42
.. option:: --query-log.threshold-lock-time MICROSECONDS
45
| Variable: ``query_log_threshold_lock_time``
47
Log queries with lock times greater than ``MICROSECONDS``.
48
The query log file writes ``lock_time`` as seconds with six decimal
49
place of precision, but this option must specify a number of microseconds.
50
See :ref:`converting-seconds-to-microseconds`.
52
.. option:: --query-log.threshold-rows-examined N
55
| Variable: ``query_log_threshold_rows_examined``
57
Log queries that examine more than ``N`` rows.
59
.. option:: --query-log.threshold-rows-sent N
62
| Variable: ``query_log_threshold_rows_sent``
64
Log queries that send (return) more than ``N`` rows.
66
.. option:: --query-log.threshold-session-time MICROSECONDS
69
| Variable: ``query_log_threshold_session_time``
71
Log queries form sessions active longer than ``MICROSECONDS``.
72
The query log file writes ``session_time`` as seconds with six decimal
73
place of precision, but this option must specify a number of microseconds.
74
See :ref:`converting-seconds-to-microseconds`.
76
.. option:: --query-log.threshold-tmp-tables N
79
| Variable: ``query_log_threshold_tmp_tables``
81
Log queries that use more than ``N`` temporary tables.
83
.. option:: --query-log.threshold-warnings N
86
| Variable: ``query_log_threshold_warnings``
88
Log queries that cause more than ``N`` errors.
93
Start Drizzle with the query plugin and log queries that take longer than 1 second to execute to the default log file:
98
--plugin-add=query-log \
99
--query-log.file-enabled \
100
--query-log.threshold-execution-time=1000000
102
Disable the query log plugin while Drizzle is running:
104
.. code-block:: mysql
106
SET GLOBAL query_log_enabled = FALSE;
108
Disable and close the query log file while Drizzle is running:
110
.. code-block:: mysql
112
SET GLOBAL query_log_file_enabled = FALSE;
114
Change the query log file while Drizzle is running:
116
.. code-block:: mysql
118
SET GLOBAL query_log_file = "/tmp/new-file.log";
120
.. _converting-seconds-to-microseconds:
123
.. _logging-destinations:
128
A logging destination is a place where the query log plugin writes queries.
129
There is currently only one logging destination: the :ref:`log-file` specified by :option:`--query-log.file`. Other destinations are planned, like a table.
136
The log file destination is enabled when both ``query_log_enabled`` and ``query_log_file_enabled`` are true (``SHOW VARIABLES`` lists ``ON`` and ``OFF`` instead of ``TRUE`` and ``FASLE``). When ``query_log_file_enabled`` is true, the ``query_log_file`` is open. When ``query_log_file_enabled`` is set false, the log file is closed. This is helpful if you want to rotate the log file.
138
The log file is a plain text, structured file that is readable by humans and easily parsable by tools. It looks like:
142
# 2011-05-15T01:48:17.814985
143
# session_id=1 query_id=6 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=1
144
# execution_time=0.000315 lock_time=0.000315 session_time=16.723020
147
set query_log_file_enabled=true;
149
# 2011-05-15T01:48:21.526746
150
# session_id=1 query_id=7 rows_examined=10 rows_sent=10 tmp_tables=0 warnings=0
151
# execution_time=0.000979 lock_time=0.000562 session_time=20.435445
154
show variables like 'query_log%';
157
Events are separated by a single ``#`` character. This record separator can be used by programs like :program:`awk` and :program:`perl` to easily separate events in a log.
159
The first line line of each event is a UTC/GMT timestamp with microsecond precision; the timezone cannot be changed. The second line has attributes with integer values. The third line has attributes with high-precision time values, always with six decimals places of precision. The fourth line has attributes with boolean values, either ``true`` or ``false``. The fifth line has attributes with string values, always double-quoted. Remaining lines are the query which can contain multiple lines, blank lines, et. The record separator marks the event of the event.
164
The authoritative source for issues, bugs and updated information is always
165
`Drizzle on Launchpad <https://launchpad.net/drizzle>`_, but this is a list of notable bugs and limitations at the time of writing of which you should be aware before using this plugin.
167
* Error handling and reporting is not the best. This mostly affects changing ``query_log_file``. If you try to use a file that cannot be opened, the query log plugin prints an error to ``STDERR`` and disabled ``query_log_file_enabled``.
168
* ``lock_time`` is broken, wrong. See https://bugs.launchpad.net/drizzle/+bug/779708.
169
* If the query log file is removed or changed while open (i.e. while ``query_log_file_enabled`` is true), it will not be recreated and query logging will stop. You need to disable and re-enable the log file to restore logging.
171
Converting Seconds to Microseconds
172
----------------------------------
174
Attributes in the query log file that end with ``_time``, like ``execution_time`` and ``lock_time``, are written as seconds with six decimal places of precision, like ``1.000456``. These values are easier for humans to read, but Drizzle uses micrsecond values internally so it is necessary to convert from one to the other.
176
To convert from seconds to microseconds, multiply the seconds value by
177
``1000000`` (that's a one and six zeros). For example:
179
0.5 second * 1000000 = 500000 microseconds
181
To convert back, multiple the number of microseconds by ``0.000001`` (that's zero point five zeros and a one).