WiredTiger includes a command line utility, wt
.
wt [-BLRrVv] [-C config] [-E secretkey ] [-h directory] command [command-specific arguments]
The wt
tool is a command-line utility that provides access to various pieces of the WiredTiger functionality.
There are several global options:
-B
-C
config-E
secretkey-h
directory-L
-m
-R
-r
-V
-v
Unless otherwise described by a wt
command, the wt
tool exits zero on success and non-zero on error.
The wt
tool supports several commands. If configured in the underlying database, some commands will run recovery when opening the database. If the user wants to force recovery on any command, use the -R
option. In general, commands that modify the database or tables will run recovery by default and commands that only read data will not run recovery. It is recommended when attempting to diagnose a corrupt database, that the -r flag be used. This flag will open the connection read-only and prevent utility commands from writing prevent utility commands from writing to any of the existing database objects.
Alter a table.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] alter uri configuration ...
The uri
and configuration
pairs may be specified to the alter
command. These configuration pairs can be used to modify the configuration values from those passed to the WT_SESSION::create call.
The uri
part of the configuration pair should match only one of the objects being altered, but may be a prefix of the object being matched. For example, the following two sets of configuration pairs are equivalent in the case of altering a single table named xxx
.
It's an error, however, to specify a matching prefix that matches more than a single object being altered.
Multiple configuration
arguments may be specified. For example, the following two sets of configuration pairs are equivalent:
Perform a backup of a database or set of data sources.
The backup
command performs a backup of the database, copying the underlying files to a specified
directory, which can be subsequently opened as a WiredTiger database. See Backups for more information, and File permissions for specifics on the copied file permissions.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] backup [-t uri] directory
The following are command-specific options for the backup
command:
-t
uribackup
command does a backup of the entire database; the -t
option changes the backup
command to do a backup of only the named data sources.Compact a table.
The compact
command attempts to rewrite the specified table to consume less disk space.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] compact uri
The compact
command has no command-specific options.
Create a table.
The create
command creates the specified uri
with the specified configuration. It is equivalent to a call to WT_SESSION::create with the specified string arguments.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] create [-c config] uri
The following are command-specific options for the create
command:
-c
Downgrade a database.
The downgrade
command downgrades the database to the specified compatibility version.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] downgrade -V version
The following are command-specific options for the downgrade
command:
-V
version-V
option is required, and specifies the version to which the database is downgraded.Drop a table.
The drop
command drops the specified uri
. It is equivalent to a call to WT_SESSION::drop with the "force" configuration argument.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] drop uri
The drop
command has no command-specific options.
Export data in a text format.
The dump
command outputs the specified table in a portable format which can be re-loaded into a new table using the load
command.
See Dump Formats for details of the dump file formats.
wt [-RrVv] [-C config] [-E secretkey ] [-h directory] dump [-jprx] [-c checkpoint] [-f output] [-t timestamp] uri
The following are command-specific options for the dump
command:
-c
dump
command opens the most recent version of the data source; the -c
option changes the dump
command to dump as of the named checkpoint.-f
dump
command output is written to the standard output; the -f
option re-directs the output to the specified file.-j
-p
-p
flag is incompatible with the load
command. The -p
flag can be combined with -x
. In this case, raw data elements will be formatted like -x
with hexadecimal encoding.-r
-t
dump
command opens the most recent version of the data source; the -t
option changes the dump
command to dump as of the specified timestamp.-x
-x
flag can be combined with -p
. In this case, the dump will be formatted similar to -p
except for raw data elements, which will look like -x
with hexadecimal encoding. If the two options are combined the output is no longer compatible with load
.List the tables in the database.
By default, the list
command prints out the tables stored in the database. If a URI is specified as an argument, only information about that data source is printed.
wt [-RrVv] [-C config] [-E secretkey ] [-h directory] list [-cv] [uri]
The following are command-specific options for the list
command:
-c
-c
option is specified, the data source's checkpoints are printed in a human-readable format.-v
-v
option is specified, the data source's complete schema table value is printed.Load a table from dump output.
The load
command reads the standard input for data and loads it into a table, creating the table if it does not yet exist. The data should be the format produced by the dump
command; see Dump Formats for details.
By default, if the table already exists, key/value pairs in the table will be overwritten by new data with matching keys (use the -n
option to make an attempt to overwrite existing data return an error). Existing keys will not be removed.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] load [-ajn] [-f input] [-r name] [uri configuration ...]
The following are command-specific options for the load
command:
-a
-a
option is specified, record number keys in the input are ignored and the data is appended to the data source and assigned new record number keys. The -a
option is only applicable when loading into a column store.-f
load
command reads from the standard input; the -f
option reads the input from the specified file.-j
dump
-j command.-n
-n
option causes the load
command to fail if there's an attempt to overwrite already existing data.-r
load
command uses the table name taken from the input; the -r
option renames the data source.Additionally, uri
and configuration
pairs may be specified to the load
command. These configuration pairs can be used to modify the configuration values from the dump header passed to the WT_SESSION::create call.
The uri
part of the configuration pair should match only one of the objects being loaded, but may be a prefix of the object being matched. For example, the following two sets of configuration pairs are equivalent in the case of loading a single table named xxx
.
It's an error, however, to specify a matching prefix that matches more than a single object being loaded.
Multiple configuration
arguments may be specified. For example, the following two sets of configuration pairs are equivalent:
Load text into a table.
The loadtext
command reads the standard input for text and loads it into a table. The input data should be printable characters, with newline delimiters for each key or value.
The loadtext
command does not create the object if it does not yet exist.
In the case of inserting values into a column-store table, each value is appended to the table; in the case of inserting values into a row-store table, lines are handled in pairs, where the first line is the key and the second line is the value. If the row-store table already exists, key/value pairs in the table will be overwritten by new data with matching keys. For either column-store or row-store tables, existing keys will not be removed.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] loadtext [-f input] uri
The following are command-specific options for the loadtext
command:
-f
loadtext
command reads from the standard input; the -f
option reads the input from the specified file.Display the database log. By default any operations in the log containing user data are redacted.
The printlog
command outputs the database log.
wt
[-RrVv] [-C config] [-E secretkey ] [-h directory] printlog [-mux] [-f output]
The following are command-specific options for the printlog
command:
-f
printlog
command output is written to the standard output; the -f
option re-directs the output to the specified file.-m
-u
-x
Read records from a table.
The read
command prints out the records associated with the specified keys from the specified data source. The data source must be configured with string or record number keys and string values.
The read
command exits non-zero if a specified record is not found.
wt [-RrVv] [-C config] [-E secretkey ] [-h directory] read uri key ...
The read
command has no command-specific options.
Rename a table.
The rename
command renames the specified table.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] rename uri name
The rename
command has no command-specific options.
Recover data from a corrupted table.
The salvage
command salvages the specified data source, discarding any data that cannot be recovered. Underlying files are re-written in place, overwriting the original file contents.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] salvage [-F] uri
The following are command-specific options for the salvage
command:
-F
-F
option forces the salvage of the table, regardless.Display database or data source statistics.
The stat
command outputs run-time statistics for the WiredTiger engine, or, if specified, for the URI on the command-line.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] stat [-f] [uri]
The following are command-specific options for the stat
command:
-f
statistics=(fast))
to WT_SESSION::open_cursor.Truncate a table, removing all data.
The truncate
command truncates the specified uri
. It is equivalent to a call to WT_SESSION::truncate with no start or stop specified.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] truncate uri
The truncate
command has no command-specific options.
Upgrade a table.
The upgrade
command upgrades the specified table, exiting success if the data source is up-to-date, and failure if the data source cannot be upgraded.
wt [-RVv] [-C config] [-E secretkey ] [-h directory] upgrade uri
The upgrade
command has no command-specific options.
Check the structural integrity of a table.
The verify
command verifies the specified table, exiting success if the data source is correct, and failure if the data source is corrupted.
wt [-RrVv] [-C config] [-E secretkey ] [-h directory] verify [-s] [-d dump_address | dump_blocks | dump_layout | dump_offsets=#,# | dump_pages ] [uri]
The following are command-specific options for the verify
command:
-d
[config] This option allows you to specify values which you want to be displayed when verification is run. See the WT_SESSION::verify configuration options.
-s
This option allows you to verify against the stable timestamp, valid only after a rollback-to-stable operation. See the WT_SESSION::verify configuration options.
Write records to a table.
The write
command stores records into the specified data source. The data source must be configured with string or record number keys and string values.
If the write
command is called with the -a
option, each command-line argument is a single value to be appended to the specified column-store data source. If the write
command is not called with the -a
option, the command-line arguments are key/value pairs.
Attempting to overwrite an already existing record will fail.
wt
[-RVv] [-C config] [-E secretkey ] [-h directory] write -a uri value ...
wt [-RVv] [-C config] [-E secretkey ] [-h directory] write [-o] uri key value ...
The following are command-specific options for the write
command:
-a
-o
-o
option changes write
to overwrite previously existing records.