~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/query_log/docs/index.rst

  • Committer: Mark Atwood
  • Date: 2011-08-06 22:44:31 UTC
  • mfrom: (2311.1.10 query-log-plugin)
  • Revision ID: me@mark.atwood.name-20110806224431-57s1770jarqncrl7
mergeĀ lp:~daniel-nichter/drizzle/query-log-plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Query Log
 
2
=========
 
3
 
 
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.
 
5
 
 
6
All query log system variables are global and dynamic so they can be changed while Drizzle is running.
 
7
 
 
8
Configuration
 
9
-------------
 
10
 
 
11
.. program:: drizzled
 
12
 
 
13
.. option:: --query-log.file FILE
 
14
 
 
15
  | Default: :file:`drizzled-queries.log`
 
16
  | Variable: ``query_log_file``
 
17
 
 
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.
 
21
 
 
22
.. option:: --query-log.file-enabled
 
23
 
 
24
  | Default: ``FALSE``
 
25
  | Variable: ``query_log_file_enabled``
 
26
 
 
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``.
 
31
 
 
32
.. option:: --query-log.threshold-execution-time MICROSECONDS
 
33
 
 
34
  | Default: ``0``
 
35
  | Variable: ``query_log_threshold_execution_time``
 
36
 
 
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`.
 
41
 
 
42
.. option:: --query-log.threshold-lock-time MICROSECONDS
 
43
 
 
44
  | Default: ``0``
 
45
  | Variable: ``query_log_threshold_lock_time``
 
46
 
 
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`.
 
51
 
 
52
.. option:: --query-log.threshold-rows-examined N
 
53
 
 
54
  | Default: ``0``
 
55
  | Variable: ``query_log_threshold_rows_examined``
 
56
 
 
57
  Log queries that examine more than ``N`` rows.
 
58
 
 
59
.. option:: --query-log.threshold-rows-sent N
 
60
 
 
61
  | Default: ``0``
 
62
  | Variable: ``query_log_threshold_rows_sent``
 
63
 
 
64
  Log queries that send (return) more than ``N`` rows.
 
65
 
 
66
.. option:: --query-log.threshold-session-time MICROSECONDS
 
67
 
 
68
  | Default: ``0``
 
69
  | Variable: ``query_log_threshold_session_time``
 
70
 
 
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`.
 
75
 
 
76
.. option:: --query-log.threshold-tmp-tables N
 
77
 
 
78
  | Default: ``0``
 
79
  | Variable: ``query_log_threshold_tmp_tables``
 
80
 
 
81
  Log queries that use more than ``N`` temporary tables.
 
82
 
 
83
.. option:: --query-log.threshold-warnings N
 
84
 
 
85
  | Default: ``0``
 
86
  | Variable: ``query_log_threshold_warnings``
 
87
 
 
88
  Log queries that cause more than ``N`` errors.
 
89
 
 
90
Examples
 
91
--------
 
92
 
 
93
Start Drizzle with the query plugin and log queries that take longer than 1 second to execute to the default log file:
 
94
 
 
95
.. code-block:: none
 
96
 
 
97
  sbin/drizzled               \
 
98
    --plugin-add=query-log    \
 
99
    --query-log.file-enabled  \
 
100
    --query-log.threshold-execution-time=1000000
 
101
 
 
102
Disable the query log plugin while Drizzle is running:
 
103
 
 
104
.. code-block:: mysql
 
105
 
 
106
  SET GLOBAL query_log_enabled = FALSE;
 
107
 
 
108
Disable and close the query log file while Drizzle is running:
 
109
 
 
110
.. code-block:: mysql
 
111
 
 
112
  SET GLOBAL query_log_file_enabled = FALSE;
 
113
 
 
114
Change the query log file while Drizzle is running:
 
115
 
 
116
.. code-block:: mysql
 
117
 
 
118
  SET GLOBAL query_log_file = "/tmp/new-file.log";
 
119
 
 
120
.. _converting-seconds-to-microseconds:
 
121
 
 
122
 
 
123
.. _logging-destinations:
 
124
 
 
125
Logging Destinations
 
126
--------------------
 
127
 
 
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.
 
130
 
 
131
.. _log-file:
 
132
 
 
133
Log File
 
134
^^^^^^^^
 
135
 
 
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.
 
137
 
 
138
The log file is a plain text, structured file that is readable by humans and easily parsable by tools.  It looks like:
 
139
 
 
140
.. code-block:: none
 
141
 
 
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
 
145
  # error=true
 
146
  # schema=""
 
147
  set query_log_file_enabled=true;
 
148
  #
 
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
 
152
  # error=false
 
153
  # schema=""
 
154
  show variables like 'query_log%';
 
155
  #
 
156
 
 
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.
 
158
 
 
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.
 
160
 
 
161
Bugs and Limitations
 
162
--------------------
 
163
 
 
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.
 
166
 
 
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.
 
170
 
 
171
Converting Seconds to Microseconds
 
172
----------------------------------
 
173
 
 
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.
 
175
 
 
176
To convert from seconds to microseconds, multiply the seconds value by
 
177
``1000000`` (that's a one and six zeros).  For example:
 
178
 
 
179
  0.5 second *  1000000 = 500000 microseconds
 
180
 
 
181
To convert back, multiple the number of microseconds by ``0.000001`` (that's zero point five zeros and a one).