CREATE DIRECTORY v11

Name

CREATE DIRECTORY -- create an alias for a file system directory path.

Synopsis

CREATE DIRECTORY <name> AS '<pathname>'

Description

The CREATE DIRECTORY command creates an alias for a file system directory pathname. You must be a database superuser to use this command.

When the alias is specified as the appropriate parameter to the programs of the UTL_FILE package, the operating system files are created in, or accessed from the directory corresponding to the given alias.

Parameters

name

The directory alias name.

pathname

The fully-qualified directory path represented by the alias name. The CREATE DIRECTORY command does not create the operating system directory. The physical directory must be created independently using the appropriate operating system commands.

Notes

The operating system user id, enterprisedb, must have the appropriate read and/or write privileges on the directory if the UTL_FILE package is to be used to create and/or read files using the directory.

The directory alias is stored in the pg_catalog.edb_dir system catalog table. Note that edb_dir is not a table compatible with Oracle databases.

The directory alias can also be viewed from the Oracle catalog views SYS.ALL_DIRECTORIES and SYS.DBA_DIRECTORIES, which are compatible with Oracle databases.

Use the DROP DIRECTORY command to delete the directory alias. When a directory alias is deleted, the corresponding physical file system directory is not affected. The file system directory must be deleted using the appropriate operating system commands.

In a Linux system, the directory name separator is a forward slash (/).

In a Windows system, the directory name separator can be specified as a forward slash (/) or two consecutive backslashes (\\).

Examples

Create an alias named empdir for directory /tmp/empdir on Linux:

CREATE DIRECTORY empdir AS '/tmp/empdir';

Create an alias named empdir for directory C:\TEMP\EMPDIR on Windows:

CREATE DIRECTORY empdir AS 'C:/TEMP/EMPDIR';

View all of the directory aliases:

SELECT * FROM pg_catalog.edb_dir;

dirname | dirowner |    dirpath     | diracl
--------+----------+----------------+--------
 empdir |       10 | C:/TEMP/EMPDIR |
(1 row)

View the directory aliases using a view compatible with Oracle databases:

SELECT * FROM SYS.ALL_DIRECTORIES;

    owner     | directory_name | directory_path
--------------+----------------+----------------
 ENTERPRISEDB | EMPDIR         | C:/TEMP/EMPDIR
(1 row)

See Also

DROP DIRECTORY