As new versions of Oracle are released, we are less
likely to access the operating system. The ability to move data files from
within Oracle is just one more great hook to the operating system that aids DBAs
in their daily tasks.
Within Oracle 10g we are given the opportunity to move
operating system files without ever ‘physically’ logging into the operating
system itself. This in itself provides us, as DBAs, many options when doing common
database administrative tasks that we will typically do. These tasks range from
simple storage management, where we need to free up space on a disk, to
allowing us to move tablespaces and associated data files to other databases.
If you have any scripts lying around that do file movement such as backups or
cloning of databases this option should spark some interest from you.
DBMS_FILE_TRANSFER
As this package suggests it provides you the ability to move
(transfer) operating system files from one location to another. The beauty of
this package is that it allows you to move these operating system files either
within the current database host environment or between database hosts. Table A
gives you a brief description of the procedures that are included in this
package and what they do.
DBMS_FILE_TRANSFER Procedures
Here are the current three procedures that are packaged in
the DBMS_FILE_TRANSFER package and the associated definition.
COPY_FILE Procedure
Allows you to read an operating system file (source_file_name)
within a directory (source_directory_object) on the local database host
environment and create a copy (destination_file_name) in another directory (destination_directory_object)
on the same local host system.
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);
GET_FILE Procedure
Allows you to read in a file (source_file_name) within a
directory (source_directory_object) from a remote database host system (source_database)
and create a copy of that data file (destination_file_name) in a directory (destination_directory_object)
on the current local host database system
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);
PUT_FILE Procedure
Allows you to read in a file (source_file_name) within a
directory (source_directory_object) from the current local database host system
and create a copy of that data file (destination_file_name) in a directory (destination_directory_object)
on a remote database host system (desination_database).
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);
Input Definitions
Here is a brief definition of the input for each of the
procedures within the DBMS_FILE_TRANSFER package.
source_directory_object |
This is a created directory object where a file resides from which you wish to copy a file. This is done through the CREATE DIRECTORY command and then read privileges must be granted to the user on this directory. |
source_file_name |
This |
|
This |
destination_directory_object |
A |
destination_file_name |
This |
|
This |
Privileges Required
In order to read and write to the directories on the source and destination hosts you must grant the following to the users that will be executing the DBMS_FILE_TRANSFER procedures. If you are worried about giving someone complete access to the operating system files that might have sensitive information you will need to create extra directory structures and then grant privileges according to the type of information stored in those directories.
-
You must grant READ privileges for users on the
DIRECTORY used in the source_directory_object if you wish them to copy files
from this directory. -
You must grant WRITE privileges for users on the
DIRECTORY used in the destination_directory_object if you wish them to copy
files into this directory.
Considerations
When using the DBMS_FILE_TRANSFER package there are a couple of considerations and usage notes of which you should be aware.
- The procedures contained within the DBMS_FILE_TRANSFER package will convert the parameters to uppercase unless you use double quotes around the variable.
- Not to worry, the file names are not converted to uppercase.
- When a file is copied, it is treated as a binary file.
- No character conversions are performed when copying files.
- File size must be a multiple of 512 bytes.
- File size cannot exceed 2 terabytes.