Oracle Datafiles

原创 2004年08月12日 10:08:00

Oracle Datafiles

Version 9.2

General Information
Data Dictionary Objects Related To Data Files file$

dba_data_files
dba_free_space
Notes:
  • x
  • x
  • x
 
Create Data Files
   
 
   
 
   
 
   
 
Alter Data Files
Resize An Existing Tablespace Datafile ALTER DATABASE DATAFILE '<data_file_name>'
RESIZE <n> K|M;

Beware that you can only decrease the size of the datafile with the space that is free between highest used block of the datafile and the last block of the file. If the tablespace is fragmented, the free spaces between extents cannot be deallocated this way. Check dba_free_space for details.
ALTER DATABASE DATAFILE 'c:/oracle/oradata/orabase/tools02.tom' RESIZE 50M;

ALTER DATABASE DATAFILE 'c:/oracle/oradata/orabase/tools03.dan' RESIZE 50M;
Add A Datafile To An Existing Tablespace ALTER TABLESPACE <tablespace_name>
ADD DATAFILE '<path_and_file_name>' SIZE <n>K|M;
ALTER TABLESPACE tools
ADD DATAFILE 'c:/oracle/oradata/orabase/tools02.tom' SIZE 20M;
Move Tablespace Datafile SHUTDOWN

STARTUP MOUNT

Copy the datafile to it's new location

ALTER DATABASE RENAME FILE
'<old_full_path>' TO '<new_full_path>';

then

ALTER DATABASE OPEN;

After that, you can safely delete the old datafile.
SQL> CONN / AS SYSDBA

SQL> SHUTDOWN

SQL> STARTUP MOUNT

SQL> HOST

$ cp /u01/oradata/tools01.dbf /u06/oradata/tools01.dbf

$ EXIT

SQL> ALTER DATABASE RENAME FILE '/u01/oradata/tools01.dbf'
     TO '/u06/oradata/tools01.dbf';

SQL> ALTER DATABASE OPEN;

SQL> HOST

$ rm /u01/oradata/tools.01.dbf

$ EXIT
Move System Tablespace Datafile The data dictionary can never be offline, with the rest of the database operational. Moving the SYSTEM tablespace's datafiles requires a different technique because 'alter
database' generally means you are modifying the controlfile.
All 'RENAME datafile 'x' to 'y' command does is to reset the pointers to the datafiles stored in the Control File which SMON reads at startup)
conn / AS SYSDBA

SHUTDOWN

copy the datafile to its new location with operating system commands.

STARTUP NOMOUNT

ALTER DATABASE MOUNT;

ALTER DATABASE RENAME FILE 'c:/oracle/oradata/system01.dbf' TO 'd:/oracle/oradata/system01.dbf';

ALTER DATABASE OPEN;
 
Alter Temp Files
Resize alter database tempfile <temp file name>
resize <integer> M;
ALTER DATABASE TEMPFILE 'temp01.dbf'
RESIZE 100M;
Drop alter database tempfile <temp file name>
drop including datafiles;
ALTER DATABASE TEMPFILE 'temp01.dbf'
DROP INCLUDING DATAFILES;
 
Drop Data File
Drop A Datafile:
Works only on tablespaces consisting of a single datafile
ALTER DATABASE DATAFILE '<file_name>' [offline] DROP;
ALTER DATABASE DATAFILE   'C:/ORACLE/ORADATA/ORABASE/TOOLS02.TOM'
OFFLINE DROP;
 
Data File Related Queries
  SELECT file_name, tablespace_name,
       bytes/1024/1024 MB, blocks
FROM dba_data_files
UNION ALL
SELECT file_name, tablespace_name,
       bytes/1024/1024 MB, blocks
FROM dba_temp_files
ORDER BY tablespace_name, file_name;
Uneven Datafile Usage Within A Tablespace CREATE TABLESPACE bowie_data
DATAFILE 'c:/bowie/bowie_data01.dbf' size 10m,
'c:/bowie/bowie_data02.dbf' size 10m,
'c:/bowie/bowie_data03.dbf' size 10m
uniform size 64;

col segment_name format a30

SELECT file_id, file_name
FROM dba_data_files
WHERE tablespace_name = 'BOWIE_DATA';

CREATE TABLE one (x NUMBER) TABLESPACE bowie_data;
CREATE TABLE two (x NUMBER) TABLESPACE bowie_data;
CREATE TABLE three (x NUMBER) TABLESPACE bowie_data;
CREATE TABLE four (x NUMBER) TABLESPACE bowie_data;

Now we've create 4 tables in this tablespace. Let's see which data file they were placed in ...

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA';

Note that *all* tables have their first extent created in the *first* data file defined to the tablespace.

Now lets grow these tables and see what happens next.

ALTER TABLE one ALLOCATE EXTENT;
ALTER TABLE two ALLOCATE EXTENT;
ALTER TABLE three ALLOCATE EXTENT;
ALTER TABLE four ALLOCATE EXTENT;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

... and the second extent of each table has been created in the second data file of the tablespace.

If a particular table were to keep growing ...

ALTER TABLE four ALLOCATE EXTENT;
ALTER TABLE four ALLOCATE EXTENT;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

you can see how the extents get allocated to the data files in a round robin fashion. But the first extent is allocate to the first data file (providing it has sufficent space) ...

CREATE TABLE five (x NUMBER) TABLESPACE bowie_data;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

Let's add a new data file. What happens now ...

ALTER TABLESPACE bowie_data
ADD DATAFILE 'c:/bowie/bowie_data04.dbf' SIZE 10M;

ALTER TABLE four ALLOCATE EXTENT;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

A new extent is added to table four. And uses the new datafile.

ALTER TABLE four ALLOCATE EXTENT;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

ALTER TABLE four ALLOCATE EXTENT;

SELECT segment_name, file_id
FROM dba_extents
WHERE tablespace_name = 'BOWIE_DATA'
ORDER BY segment_name;

... and now the new file is used. The files are still used in a round robin fashion with the new file slipping in.

Note how file 16 is the *most* used file and file 19 is the least. If I were to allocate several new tables that were only 1 or 2 extents in size, see how file 16 would be the one to be most "filled".

Related Topics
 

收藏助手
不良信息举报
您举报文章:Oracle Datafiles
举报原因:
原因补充:

(最多只允许输入30个字)