SQLite Tables Reference
In addition to the tables generated for each log format, lnav includes
the following tables/views:
These extra tables provide useful information and can let you manipulate
lnav’s internal state. You can get a dump of the entire database schema
by executing the ‘.schema’ SQL command, like so:
Note
The tables created by lnav are in the lnav_db database. The
main SQLite database is left empty for your own use. If you
end up creating any tables while processing your logs, you can use
the ;.save path SQL command to save the main database to
a SQLite database file.
environ
The environ table gives you access to the lnav process’ environment
variables. You can SELECT, INSERT, and UPDATE
environment variables, like so:
;SELECT * FROM environ WHERE name = 'SHELL'
name value
SHELL /bin/tcsh
;UPDATE environ SET value = '/bin/sh' WHERE name = 'SHELL'
Environment variables can be used to store simple values or pass values
from lnav’s SQL environment to lnav’s commands. For example, the
:open command will do variable substitution, so you can insert a variable
named “FILENAME” and then open it in lnav by referencing it with
“$FILENAME”:
;INSERT INTO environ VALUES ('FILENAME', '/path/to/file')
:open $FILENAME
fstat(<path|pattern>)
The fstat table-valued function provides access to the local
file system. The function takes a file path or a glob pattern and
returns the results of lstat(2) for the matching files. If
the parameter is a pattern that matches nothing, no rows will be
returned. If the parameter is a path for a non-existent file, a
row will be returned with the error column set and the
stat columns as NULL. To read the contents of a file, you
can SELECT the hidden data column.
lnav_events
The lnav_events table allows you to react to events that occur while
lnav is running using SQLite triggers. For example, when a file is
opened, a row is inserted into the lnav_events table that contains
a timestamp and a JSON object with the event ID and the path of the file.
The following columns are available in this table:
- ts:
The timestamp of the event.
- content:
A JSON object that contains the event information. See the
Reference for more information about the types
of events that are available.
lnav_file
The lnav_file table allows you to examine and perform limited updates to
the metadata for the files that are currently loaded into lnav. The
following columns are available in this table:
- device:
The device the file is stored on.
- inode:
The inode for the file on the device.
- filepath:
If this is a real file, it will be the absolute path. Otherwise,
it is a symbolic name. If it is a symbolic name, it can be UPDATEd
so that this file will be considered when saving and loading session
information.
- mimetype:
The detected MIME type of the file.
- content_id:
The hash of some unique content in the file.
- format:
The log file format for the file.
- lines:
The number of lines in the file.
- time_offset:
The millisecond offset for timestamps. This column can be
UPDATEd to change the offset of timestamps in the file.
- options_path:
Options can be applied to files based on a path or glob
pattern. If this file matches a set of options, the matching path/pattern
is available in this column and the actual options themselves are in the
options column.
- options:
The options that are applicable to this file. Currently, the
only options available are for the timezone set by the
:set-file-timezone command.
lnav_file_value_stats
The lnav_file_value_stats table contains the statistics that are
collected for the values in each open log file. They are the same numbers that
are shown in the details overlay for a message. The numbers are raw values,
on the same scale as the columns in the log tables. Divide them by the
unit_divisor from the lnav_format_values table to get them in the
base unit for the value. The following columns are available in this table:
- filepath:
The path to the file.
- format:
The name of the file’s log format.
- name:
The name of the value.
- count:
The number of numeric values seen.
- text_count:
The number of non-numeric values seen.
- min:
The smallest numeric value, or NULL if there were none.
- max:
The largest numeric value, or NULL if there were none.
- mean:
The mean of the numeric values, or NULL if there were none.
- p50:
The estimated median of the numeric values.
- p90:
The estimated 90th percentile of the numeric values.
- p99:
The estimated 99th percentile of the numeric values.
- distinct_estimate:
The estimated number of distinct non-numeric values,
or NULL if there were none.
For example, to get the 99th percentile of each value with a unit in the base
unit:
;SELECT s.filepath, s.name, s.p99 / v.unit_divisor AS p99, v.unit_suffix
FROM lnav_file_value_stats AS s
JOIN lnav_format_values AS v USING (format, name)
WHERE v.unit_suffix IS NOT NULL
lnav_log_breakpoints
The lnav_log_breakpoints table allows you to view and manage
breakpoints set on log messages. Breakpoints mark log messages that
share a particular source file location or message schema, making it
easy to navigate between related log lines using the F7 and
F8 keys.
You can SELECT, INSERT, UPDATE, and
DELETE breakpoints through this table. The columns in the
table are as follows:
- schema_id:
The schema identifier for the breakpoint. This value
matches the log_msg_schema column in the all_logs
table.
- description:
A human-readable description of the breakpoint
(e.g. format_name:file.cc:42).
- type:
The source of the schema ID, either src_location or
message_schema.
- enabled:
Indicates whether the breakpoint is active (1 or 0).
;SELECT * FROM lnav_log_breakpoints
;UPDATE lnav_log_breakpoints SET enabled = 0 WHERE description LIKE '%main.cc%'
;DELETE FROM lnav_log_breakpoints WHERE description LIKE '%test%'
lnav_user_notifications
The lnav_user_notifications table allows you to display a custom message
in the top-right corner of the UI. For example, to display “Hello, World!”,
you can enter:
;REPLACE INTO lnav_user_notifications (message) VALUES ('Hello, World!')
There are additional columns to have finer control of what is displayed and
when:
- id:
The unique ID for the message, defaults to “org.lnav.user”. This is
the primary key for the table, so more than one type of message is not
allowed.
- priority:
The priority of the message. Higher priority messages will be
displayed until they are cleared or are expired.
- created:
The time the message was created.
- expiration:
The time when the message should expire or NULL if it should
not automatically expire.
- views:
A JSON array of view names where the message is applicable or NULL
if the message should be shown in all views.
- message:
The message itself.
This table will most likely be used in combination with Events (v0.11.0+) and the
lnav_views_echo table.
lnav_views
The lnav_views table allows you to SELECT and UPDATE information related
to lnav’s “views” (e.g. log, text, …). The following columns are
available in this table:
- name:
The name of the view.
- top:
The line number at the top of the view. This value can be UPDATEd to
move the view to the given line.
- left:
The left-most column number to display. This value can be UPDATEd to
move the view left or right.
- height:
The number of lines that are displayed on the screen.
- inner_height:
The number of lines of content being displayed.
- top_time:
The timestamp of the top line in the view or NULL if the view is
not time-based. This value can be UPDATEd to move the view to the given
time.
- top_file:
The file the top line in the view is from.
- paused:
Indicates if the view is paused and will not load new data.
- search:
The search string for this view. This value can be UPDATEd to
initiate a text search in this view.
- filtering:
Indicates if the view is applying filters.
- movement:
The movement mode, either ‘top’ or ‘cursor’.
- top_meta:
A JSON object that contains metadata related to the top line
in the view.
- selection:
The number of the line that is focused for selection.
- options:
A JSON object that contains optional settings for this view.
Besides the settings for the details overlay, time offsets, hidden fields,
and word wrap, the following can be read and UPDATEd:
- filter-context:
For a view that supports filtering, an object with the
before and after number of lines of context to show
around the lines that pass the filters, as set by
:filter-context.
- row-types:
For the TIMELINE view, an object with a property for each
type of row (logfile, thread, opid, tag,
partition, and search) that is either show or
hide, as set by :hide-in-timeline and
:show-in-timeline. A type that is left out
is not changed.
For example, to show two lines of context in the LOG view:
;UPDATE lnav_views
SET options = json_set(options, '$.filter-context.before', 2,
'$.filter-context.after', 2)
WHERE name = 'log'
lnav_views_echo
The lnav_views_echo table is a real SQLite table that you can create
TRIGGERs on in order to react to users moving around in a view.
Note
The table is periodically updated to reflect the current state of the views.
The changes are not performed immediately after the user action.
lnav_view_files
The lnav_view_files table provides access to details about the files
displayed in a particular view. The main purpose of this table is to allow
you to programmatically control which files are shown / hidden in the view.
The following columns are available in this table:
- view_name:
The name of the view.
- filepath:
The file’s path.
- visible:
Determines whether the file is visible in the view. This column
can be changed using an UPDATE statement to hide or show the file.
lnav_view_stack
The lnav_view_stack table allows you to SELECT and DELETE
from the stack of lnav “views” (e.g. log, text, …). The following columns
are available in this table:
- name:
The name of the view.
lnav_view_filters
The lnav_view_filters table allows you to manipulate the filters in the
lnav views. The following columns are available in this table:
- view_name:
The name of the view the filter is applied to.
- filter_id:
The filter identifier. This will be assigned on insertion.
- enabled:
Indicates whether this filter is enabled or disabled.
- type:
The type of filter, either ‘in’ or ‘out’.
- pattern:
The regular expression to filter on.
This table supports SELECT, INSERT, UPDATE, and
DELETE on the table rows to read, create, update, and delete
filters for the views.
lnav_view_filter_stats
The lnav_view_filter_stats table allows you to get information about how
many lines matched a given filter. The following columns are available in
this table:
- view_name:
The name of the view.
- filter_id:
The filter identifier.
- hits:
The number of lines that matched this filter.
This table is read-only.
lnav_view_filters_and_stats
The lnav_view_filters_and_stats view joins the lnav_view_filters
table with the lnav_view_filter_stats table into a single view for ease of use.
lnav_view_searches
The lnav_view_searches table allows you to manipulate the
named searches in the lnav views. The following
columns are available in this table:
- view_name:
The name of the view the search is applied to.
- enabled:
Indicates whether this search is enabled or disabled.
- name:
The name of the search.
- pattern:
The regular expression being searched for.
- hits:
The number of lines that matched this search.
This table supports SELECT, INSERT, and DELETE on the
table rows to read, create, and delete named searches for the views. Only the
enabled column can be changed by an UPDATE, since changing a
pattern means re-scanning the view for it: do a DELETE followed by an
INSERT instead.
lnav_top_view
The lnav_top_view view returns the row for the top view on the view stack.
all_logs
The all_logs table lets you query the format derived from the lnav
log message parser that is used to automatically extract data, see
Extracting Data for more details.
all_metrics
The all_metrics table is a long-format view over every
metrics_log file that lnav currently has open.
Each (file, row, column) combination produces one virtual row, so a
single query can scan metric values across multiple files without
having to know which file each metric came from.
The columns are as follows:
- log_line:
The line number in the LOG view of the sample row. The
value is shared across all metrics at that timestamp, including
sibling files whose rows were folded into the visible line.
- log_time:
The timestamp for the metric sample.
- log_path:
The path of the file the sample came from.
- source:
The file stem shown above the sample’s column in the
focused-row overlay.
- metric:
The column name from the source file.
- value:
The parsed numeric value. Integers pass through as INTEGER;
floats and unit-suffixed cells (e.g. 20.0KB) are REAL.
- raw_value:
(hidden) The original cell text from the file. Collated
with measure_with_units, so ORDER BY raw_value
sorts by magnitude rather than lexicographically.
- log_mark:
(hidden) True when the sample’s visible row is
user-marked. Marking a metric row fans the mark out to every
sibling sample at that timestamp.
;SELECT metric, count(*) AS n, min(value) AS lo, max(value) AS hi
FROM all_metrics
GROUP BY metric
;SELECT log_time, source, metric, value
FROM all_metrics
WHERE metric = 'cpu_pct'
ORDER BY log_time
all_opids
The all_opids table contains information about all opids that were
found in the log files or set via the log_opid column on the log
vtables. The information in this table is the same as available through the
TIMELINE view. The description column can be
SET in an UPDATE statement to customize the description
shown in the timeline.
all_thread_ids
The all_thread_ids table contains information about all the thread
identifiers that were found in logs. Log formats can specify which field
is a thread identifier with the thread-id-field property.
all_thread_opids
The all_thread_opids table has a row for each thread and operation ID
pair found in the logs: the operations each thread logged messages for, with the
first and last time it did and how many messages, errors, and warnings it
logged in each. A thread’s messages without an operation ID have a row with a
NULL opid. It’s built from the thread and operation IDs recorded when
the logs were indexed, so it’s quick to query even for large logs, and the
rows for given threads can be looked up with thread_id = ? or
thread_id IN (...). Like all_thread_ids, it doesn’t follow
the filters. For example, to find the operations a thread took part in:
;SELECT opid, earliest, duration, total FROM all_thread_opids
WHERE thread_id = 'worker-1' ORDER BY earliest
lnav_focused_msg
The lnav_focused_msg view returns the row for the focused log
message from the all_logs table.
http_status_codes
The http_status_codes table is a handy reference that can be used to turn
HTTP status codes into human-readable messages.
regexp_capture(<string>, <regex>)
The regexp_capture() table-valued function applies the regular expression
to the given string and returns detailed results for the captured portions of
the string.