Create Directory in Autonomous AI Database

To create directories use the database CREATE DIRECTORY command. Using CREATE DIRECTORY you specify the path as a relative path or an absolute path for the new directory.

Supported path forms

Autonomous AI Database accepts the following types of paths in CREATE DIRECTORY:

  • You can specify a relative path such as stage or stage/sales.
  • You can specify either an alias or the name of the final directory in the path.
  • You can also specify an absolute path such as /my_subdirectory/my_dir.

CREATE DIRECTORY creates the database directory object and also creates the file system directory if it does not already exist. If the file system directory exists then CREATE DIRECTORY only creates the database directory object. For example, the following command creates the database directory named staging and creates the file system directory stage:

CREATE DIRECTORY staging AS 'stage';

You can also create subdirectories. For example, the following command creates the database directory object sales_staging and the file system directory stage/sales:

CREATE DIRECTORY sales_staging AS 'stage/sales';
You can also use an absolute path to create directories. For example:
SQL> SHOW USER;
USER is "ADMIN"

SQL> CREATE DIRECTORY my_dir AS '/my_subdirectory/my_dir';

Directory created.

SQL> SELECT directory_name, directory_path
     FROM dba_directories
     WHERE directory_name = 'MY_DIR';

DIRECTORY_NAME   DIRECTORY_PATH
---------------  ---------------------------------------------------
MY_DIR           /u03/dbfs/3E4A0A9023242950E0633814000AEFB3/data/my_subdirectory/my_dir

In the above example, you provide an absolute path in the CREATE DIRECTORY command, and Autonomous AI Database creates the directory object and the corresponding directory in the managed file system.

When you create subdirectories you do not have to create the initial file system directory. For example, in the previous example if the directory stage does not exist then the CREATE DIRECTORY command creates both directories stage and stage/sales.

To add a directory, you must have the CREATE ANY DIRECTORY system privilege. The ADMIN user is granted the CREATE ANY DIRECTORY system privilege. The ADMIN user can grant CREATE ANY DIRECTORY system privilege to other users.

See CREATE DIRECTORY for more information.

Note

  • CREATE DIRECTORY creates the database directory object in the database and also creates the file system directory. For example the directory path could be:
    /u03/dbfs/7C149E35BB1000A45FD/data/stage
  • You can create a directory in the root file system to see all the files with the following commands:

    CREATE OR REPLACE DIRECTORY ROOT_DIR AS '';

    After you create the ROOT_DIR directory, use the following command to list all files:

    SELECT * FROM DBMS_CLOUD.list_files('ROOT_DIR');

    To run DBMS_CLOUD.LIST_FILES with a user other than ADMIN you need to grant read privileges on the directory to that user. See LIST_FILES Function for more information.

  • Space in the file system allocated for the directories you create and their contents is part of your storage allocation. See Database Dashboard Overview to view the total space allocated.