Directories
The YDB database supports an internal directory structure that can host database objects.
YDB CLI supports operations to change the directory structure and to access schema objects by their directory name.
Creating a directory
The scheme mkdir
command creates the directories:
ydb [connection options] scheme mkdir <path>
where [connection options] are database connection options
In the path
parameter, specify the relative path to the directory being created, from the root database directory. This command creates all the directories that didn't exist at the path when the command was called.
If the destination directory had already existed at the path, then the command execution will be completed successfully (result code 0) with a warning that no changes have been made:
Status: SUCCESS
Issues:
<main>: Error: dst path fail checks, path: /<database>/<path>: path exist, request accepts it,
pathId: [OwnerId: <some>, LocalPathId: <some>], path type: EPathTypeDir, path state: EPathStateNoChanges
It also supports the syntax of a full path beginning with /
. The full path must begin with the path to the database specified in the connection parameters or allowed by the current connection to the cluster.
Examples:
-
Creating a directory at the database root
ydb --profile quickstart scheme mkdir dir1
-
Creating directories at the specified path from the database root
ydb --profile quickstart scheme mkdir dir1/dir2/dir3
Deleting a directory
The scheme rmdir
command deletes a directory:
ydb [global options...] scheme rmdir [options...] <path>
global options
: Global parameters.options
: Parameters of the subcommand.path
: Path to the deleted directory.
Look up the description of the directory deletion command:
ydb scheme rmdir --help
Parameters of the subcommand
Name | Description |
---|---|
-r , --recursive |
This option deletes the directory recursively, which all its child objects (subdirectories, tables, topics). If you use this option, the confirmation prompt is shown by default. |
-f , --force |
Do not prompt for confirmation. |
-i |
Prompt for deletion confirmation on each object. |
-I |
Show a single confirmation prompt. |
--timeout <value> |
Operation timeout, ms. |
If you try to delete a non-empty directory without the -r
or --recursive
option, the command fails with an error.
Status: SCHEME_ERROR
Issues:
<main>: Error: path table fail checks, path: /<database>/<path>: path has children, request
doesn't accept it, pathId: [OwnerId: <some>, LocalPathId: <some>], path type:
EPathTypeDir, path state: EPathStateNoChanges, alive children: <count>
Examples
-
Deleting an empty directory:
ydb scheme rmdir dir1
-
Deleting an empty directory with a confirmation prompt:
ydb scheme rmdir -I dir1
-
Recursively deleting a non-empty directory with a confirmation prompt:
ydb scheme rmdir -r dir1
-
Recursively deleting a non-empty directory without a confirmation prompt:
ydb scheme rmdir -rf dir1
-
Recursively deleting a non-empty directory, showing a confirmation prompt on each object:
ydb scheme rmdir -ri dir1
Using directories in other CLI commands
In all CLI commands to which the object name is passed by the parameter, it can be specified with a directory, for example, in scheme describe
:
ydb --profile quickstart scheme describe dir1/table_a
The scheme ls
command supports passing the path to the directory as a parameter:
ydb --profile quickstart scheme ls dir1/dir2
Using directories in YQL
Names of objects used in YQL queries may contain paths to directories hosting such objects. This path will be concatenated with the path prefix from the TablePathPrefix
pragma. If the pragma is omitted, the object name is resolved relative to the database root.
Implicit creation of directories during import
The data import command creates a directory tree mirroring the original imported catalog.