Oracle® Database PL/SQL Packages and Types Reference 11g Release 1 (11.1) Part Number B28419-01 |
|
|
View PDF |
The DBMS_FILE_TRANSFER
package provides procedures to copy a binary file within a database or to transfer a binary file between databases.
See Also:
Oracle Database Administrator's Guide for instructions about using file transfer
Oracle Streams Concepts and Administration for applications of file transfer.
This chapter contains the following topic:
Operating Notes
Caution:
DBMS_FILE_TRANSFER
supports online backup. You should therefore be careful in copying or transferring a file that is being modified by the database because this can result in an inconsistent file, and require recovery. To guarantee consistency, bring files offline when the database is in use.
If you want to use DBMS_FILE_TRANSFER
for performing backups, note that you are implementing self-managed backups, and should therefore put the files in hot backup mode.
Table 56-1 DBMS_FILE_TRANSFER Package Subprograms
Subprogram | Description |
---|---|
COPY_FILE Procedure |
Reads a file from a source directory and creates a copy of it in a destination directory. The source and destination directories can both be in a local file system, or both be in an Automatic Storage Management (ASM) disk group, or between local file system and ASM with copying in either direction. |
GET_FILE Procedure |
Contacts a remote database to read a remote file and then creates a copy of the file in the local file system or ASM |
PUT_FILE Procedure |
Reads a local file or ASM and contacts a remote database to create a copy of the file in the remote file system |
This procedure reads a file from a source directory and creates a copy of it in a destination directory. The source and destination directories can both be in a local file system, or both be in an Automatic Storage Management (ASM) disk group, or between local file system and ASM with copying in either direction.
You can copy any type of file to and from a local file system. However, you can copy only database files (such as datafiles, tempfiles, controlfiles, and so on) to and from an ASM disk group.
The destination file is not closed until the procedure completes successfully.
Syntax
DBMS_FILE_TRANSFER.COPY_FILE( source_directory_object IN VARCHAR2, source_file_name IN VARCHAR2, destination_directory_object IN VARCHAR2, destination_file_name IN VARCHAR2);
Parameters
Table 56-2 COPY_FILE Procedure Parameters
Parameter | Description |
---|---|
source_directory_object |
The directory object that designates the source directory. The directory object must already exist. (You create directory objects with the CREATE DIRECTORY command). |
source_file_name |
The name of the file to copy. This file must exist in the source directory. |
destination_directory_object |
The directory object that designates the destination directory. The directory object must already exist. If the destination is ASM, the directory object must designate either a disk group name (for example, +diskgroup1 ) or a directory created for alias names. In the case of a directory, the full path to the directory must be specified (for example: +diskgroup1/dbs/control ). |
destination_file_name |
The name to assign to the file in the destination directory. A file with the same name must not exist in the destination directory. If the destination is ASM:
The file name can be followed by an ASM template name in parentheses. The file is then given the attributes specified by the template. |
Usage Notes
To run this procedure successfully, the current user must have the following privileges:
READ
privilege on the directory object specified in the source_directory_object
parameter
WRITE
privilege on directory object specified in the destination_directory_object
parameter
This procedure converts directory object parameters to uppercase unless they are surrounded by double quotation marks, but this procedure does not convert file names to uppercase.
Also, the copied file must meet the following requirements:
The size of the copied file must be a multiple of 512 bytes.
The size of the copied file must be less than or equal to two terabytes.
Transferring the file is not transactional. The copied file is treated as a binary file, and no character set conversion is performed. To monitor the progress of a long file copy, query the V$SESSION_LONGOPS
dynamic performance view.
See Also:
Oracle Database Storage Administrator's Guide for instructions about using file transferExamples
SQL> create directory DGROUP as '+diskgroup1/dbs/backup'; Directory created. SQL> BEGIN 2 DBMS_FILE_TRANSFER.COPY_FILE('SOURCEDIR','t_xdbtmp.f', 'DGROUP', 't_xdbtmp.f'); 3 END; 4 / PL/SQL procedure successfully completed. SQL> EXIT $ASMCMD ASMCMD> ls DISKGROUP1/ ASMCMD> cd diskgroup1/dbs/backup ASMCMD> ls t_xdbtmp.f => +DISKGROUP1/ORCL/TEMPFILE/COPY_FILE.267.546546525
This procedure contacts a remote database to read a remote file and then creates a copy of the file in the local file system or ASM. The file that is copied is the source file, and the new file that results from the copy is the destination file. The destination file is not closed until the procedure completes successfully.
Syntax
DBMS_FILE_TRANSFER.GET_FILE source_directory_object IN VARCHAR2, source_file_name IN VARCHAR2, source_database IN VARCHAR2, destination_directory_object IN VARCHAR2, destination_file_name IN VARCHAR2);
Parameters
Table 56-3 GET_FILE Procedure Parameters
Parameter | Description |
---|---|
source_directory_object |
The directory object from which the file is copied at the source site. This directory object must exist at the source site. |
source_file_name |
The name of the file that is copied in the remote file system. This file must exist in the remote file system in the directory associated with the source directory object. |
source_database |
The name of a database link to the remote database where the file is located. |
destination_directory_object |
The directory object into which the file is placed at the destination site. This directory object must exist in the local file system. |
destination_file_name |
The name of the file copied to the local file system. A file with the same name must not exist in the destination directory in the local file system. |
Usage Notes
To run this procedure successfully, the following users must have the following privileges:
The connected user at the source database must have read privilege on the directory object specified in the source_directory_object
parameter.
The current user at the local database must have write privilege on the directory object specified in the destination_directory_object
parameter.
This procedure converts directory object parameters to uppercase unless they are surrounded by double quotation marks, but this procedure does not convert file names to uppercase.
Also, the copied file must meet the following requirements:
The size of the copied file must be a multiple of 512 bytes.
The size of the copied file must be less than or equal to two terabytes.
Transferring the file is not transactional. The copied file is treated as a binary file, and no character set conversion is performed. To monitor the progress of a long file transfer, query the V$SESSION_LONGOPS
dynamic performance view.
Examples
CREATE OR REPLACE DIRECTORY df AS '+datafile' ; GRANT WRITE ON DIRECTORY df TO "user"; CREATE DIRECTORY DSK_FILES AS ''^t_work^''; GRANT WRITE ON DIRECTORY dsk_files TO "user"; -- asumes that dbs2 link has been created and we are connected to the instance. -- dbs2 could be a loopback or point to another instance. BEGIN -- asm file to an os file -- get an asm file from dbs1.asm/a1 to dbs2.^t_work^/oa5.dat DBMS_FILE_TRANSFER.GET_FILE ( 'df' , 'a1' , 'dbs1', 'dsk_files' , 'oa5.dat' ); -- os file to an os file -- get an os file from dbs1.^t_work^/a2.dat to dbs2.^t_work^/a2back.dat DBMS_FILE_TRANSFER.GET_FILE ( 'dsk_files' , 'a2.dat' , 'dbs1', 'dsk_files' , 'a2back.dat' ); END ; /
This procedure reads a local file or ASM and contacts a remote database to create a copy of the file in the remote file system. The file that is copied is the source file, and the new file that results from the copy is the destination file. The destination file is not closed until the procedure completes successfully.
Syntax
DBMS_FILE_TRANSFER.PUT_FILE( source_directory_object IN VARCHAR2, source_file_name IN VARCHAR2, destination_directory_object IN VARCHAR2, destination_file_name IN VARCHAR2, destination_database IN VARCHAR2);
Parameters
Table 56-4 PUT_FILE Procedure Parameters
Parameter | Description |
---|---|
source_directory_object |
The directory object from which the file is copied at the local source site. This directory object must exist at the source site. |
source_file_name |
The name of the file that is copied from the local file system. This file must exist in the local file system in the directory associated with the source directory object. |
destination_directory_object |
The directory object into which the file is placed at the destination site. This directory object must exist in the remote file system. |
destination_file_name |
The name of the file placed in the remote file system. A file with the same name must not exist in the destination directory in the remote file system. |
destination_database |
The name of a database link to the remote database to which the file is copied. |
Usage Notes
To run this procedure successfully, the following users must have the following privileges:
The current user at the local database must have read privilege on the directory object specified in the source_directory_object
parameter.
The connected user at the destination database must have write privilege to the directory object specified in the destination_directory_object
parameter.
This procedure converts directory object parameters to uppercase unless they are surrounded by double quotation marks, but this procedure does not convert file names to uppercase.
Also, the copied file must meet the following requirements:
The size of the copied file must be a multiple of 512 bytes.
The size of the copied file must be less than or equal to two terabytes.
Transferring the file is not transactional. The copied file is treated as a binary file, and no character set conversion is performed. To monitor the progress of a long file transfer, query the V$SESSION_LONGOPS
dynamic performance view.
Examples
CREATE OR REPLACE DIRECTORY df AS '+datafile' ; GRANT WRITE ON DIRECTORY df TO "user"; CREATE OR REPLACE DIRECTORY ft1 AS '+datafile/ft1' ; GRANT READ,WRITE ON DIRECTORY ft1 TO "user"; CREATE OR REPLACE DIRECTORY ft1_1 AS '+datafile/ft1/ft1_1' ; CONNECT user/password@inst1 -- - put a1.dat to a4.dat (using dbs2 dblink) -- - level 2 sub dir to parent dir -- - user has read privs on ft1_1 at dbs1 and write on df in dbs2 BEGIN DBMS_FILE_TRANSFER.PUT_FILE ( 'ft1_1' , 'a2.dat' , 'df' , 'a4.dat' , 'dbs2' ) ; END ;