Managing tablespaces and data files

30 404 0
Managing tablespaces and data files

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

8 Managing Tablespaces and Data Files Copyright © Oracle Corporation, 2002 All rights reserved Objectives After completing this lesson, you should be able to the following: • Define the purpose of tablespaces and data files • Create tablespaces • Manage tablespaces • Create and manage tablespaces using Oracle Managed Files (OMF) • Obtain tablespace information 8-2 Copyright © Oracle Corporation, 2002 All rights reserved Tablespaces and Data Files Oracle stores data logically in tablespaces and physically in data files • Tablespaces: – Can belong to only one database at a time – Consist of one or more data files – Are further divided into logical units of storage • Data files: – Can belong to only one tablespace and one database – Are a repository for schema object data 8-3 Database Tablespace Data files Copyright © Oracle Corporation, 2002 All rights reserved Types of Tablespaces • SYSTEM tablespace – Created with the database – Contains the data dictionary – Contains the SYSTEM undo segment • Non-SYSTEM tablespace – Separate segments – Eases space administration – Controls amount of space allocated to a user 8-4 Copyright © Oracle Corporation, 2002 All rights reserved Creating Tablespaces A tablespace is created using the command: CREATE TABLESPACE CREATE TABLESPACE userdata DATAFILE '/u01/oradata/userdata01.dbf' SIZE 5M; 8-5 Copyright © Oracle Corporation, 2002 All rights reserved Space Management in Tablespaces • Locally managed tablespace: – – – – Free extents are managed in the tablespace Bitmap is used to record free extents Each bit corresponds to a block or group of blocks Bit value indicates free or used • Dictionary-managed tablespace: – Free extents are managed by the data dictionary – Appropriate tables are updated when extents are allocated or deallocated 8-9 Copyright © Oracle Corporation, 2002 All rights reserved Locally Managed Tablespaces • Reduced contention on data dictionary tables • No undo generated when space allocation or deallocation occurs • No coalescing required CREATE TABLESPACE userdata DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K; 8-10 Copyright © Oracle Corporation, 2002 All rights reserved Dictionary-Managed Tablespaces • Extents are managed in the data dictionary • Each segment stored in the tablespace can have a different storage clause • Coalescing is required CREATE TABLESPACE userdata DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M EXTENT MANAGEMENT DICTIONARY DEFAULT STORAGE (initial 1M NEXT 1M PCTINCREASE 0); 8-12 Copyright © Oracle Corporation, 2002 All rights reserved Migrating a Dictionary-Managed SYSTEM Tablespace Migrate a dictionary managed SYSTEM tablespace to locally managed: DBMS_SPACE_ADMIN TABLESPACE_MIGRATE_TO_LOCAL('SYSTEM'); 8-13 Copyright © Oracle Corporation, 2002 All rights reserved Undo Tablespace • • • • Used to store undo segments Cannot contain any other objects Extents are locally managed Can only use the DATAFILE and EXTENT MANAGEMENT clauses CREATE UNDO TABLESPACE undo1 DATAFILE '/u01/oradata/undo01.dbf' SIZE 40M; 8-14 Copyright © Oracle Corporation, 2002 All rights reserved Read-Only Tablespaces • Use the following command to place a tablespace in read-only mode: ALTER TABLESPACE userdata READ ONLY; – Causes a checkpoint – Data available only for read operations – Objects can be dropped from tablespace 8-23 Copyright © Oracle Corporation, 2002 All rights reserved Taking a Tablespace Offline • Not available for data access • Tablespaces that cannot be taken offline: – SYSTEM tablespace – Tablespaces with active undo segments – Default temporary tablespace • To take a tablespace offline: ALTER TABLESPACE userdata OFFLINE; • To bring a tablespace online: ALTER TABLESPACE userdata ONLINE; 8-26 Copyright © Oracle Corporation, 2002 All rights reserved Changing Storage Settings • Using ALTER TABLESPACE command to change storage settings: ALTER TABLESPACE userdata MINIMUM EXTENT 2M; ALTER TABLESPACE userdata DEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 999); • Storage settings for locally managed tablespaces cannot be altered 8-29 Copyright © Oracle Corporation, 2002 All rights reserved Resizing a Tablespace A tablespace can be resized by: • Changing the size of a data file: – Automatically using AUTOEXTEND – Manually using ALTER DATABASE • Adding a data file using ALTER TABLESPACE 8-31 Copyright © Oracle Corporation, 2002 All rights reserved Enabling Automatic Extension of Data Files • Can be resized automatically with the following commands: – CREATE DATABASE – CREATE TABLESPACE – ALTER TABLESPACE … ADD DATAFILE • Example: CREATE TABLESPACE user_data DATAFILE '/u01/oradata/userdata01.dbf' SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE 500M; • Query the DBA_DATA_FILES view to determine whether AUTOEXTEND is enabled 8-33 Copyright © Oracle Corporation, 2002 All rights reserved Manually Resizing a Data File • Manually increase or decrease a data file size using ALTER DATABASE • Resizing a data file adds more space without adding more data files • Manual resizing of a data file reclaims unused space in database • Example: ALTER DATABASE DATAFILE '/u03/oradata/userdata02.dbf' RESIZE 200M; 8-36 Copyright © Oracle Corporation, 2002 All rights reserved Adding Data Files to a Tablespace • Increases the space allocated to a tablespace by adding additional data files • ADD DATAFILE clause is used to add a data file • Example: ALTER TABLESPACE user_data ADD DATAFILE '/u01/oradata/userdata03.dbf' SIZE 200M; 8-37 Copyright © Oracle Corporation, 2002 All rights reserved Methods for Moving Data Files • ALTER TABLESPACE – Tablespace must be offline – Target data files must exist ALTER TABLESPACE userdata RENAME DATAFILE '/u01/oradata/userdata01.dbf' TO '/u02/oradata/userdata01.dbf'; 8-39 Copyright © Oracle Corporation, 2002 All rights reserved Methods for Moving Data Files • ALTER DATABASE – Database must be mounted – Target data file must exist ALTER DATABASE RENAME FILE '/u01/oradata/system01.dbf' TO '/u03/oradata/system01.dbf'; 8-40 Copyright © Oracle Corporation, 2002 All rights reserved Dropping Tablespaces • You cannot drop a tablespace if it: – Is the SYSTEM tablespace – Has active segments • INCLUDING CONTENTS drops the segments • INCLUDING CONTENTS AND DATAFILES deletes data files • CASCADE CONSTRAINTS drops all referential integrity constraints DROP TABLESPACE userdata INCLUDING CONTENTS AND DATAFILES; 8-42 Copyright © Oracle Corporation, 2002 All rights reserved Managing Tablespaces Using OMF • Define the DB_CREATE_FILE_DEST parameter in one of the following ways: – Initialization parameter file – Set dynamically using ALTER SYSTEM command ALTER SYSTEM SET db_create_file_dest = '/u01/oradata/dba01'; • When creating the tablespace: – Data file is automatically created and located in DB_CREATE_FILE_DEST – Default size is 100 MB – AUTOEXTEND is set to UNLIMITED 8-45 Copyright © Oracle Corporation, 2002 All rights reserved Managing Tablespaces Using OMF • Creating an OMF tablespace: CREATE TABLESPACE text_data DATAFILE SIZE 20M; • Adding an OMF data file to an existing tablespace: ALTER TABLESPACE text_data ADD DATAFILE; • Dynamically changing default file location: ALTER SYSTEM SET db_create_file_dest = '/u01/oradata/dba01'; • Dropping a tablespace includes deleting OS files: 8-46 Copyright © Oracle Corporation, 2002 All rights reserved Obtaining Tablespace Information Obtaining tablespace and data file information can be obtained by querying the following: • Tablespace information: – DBA_TABLESPACES – V$TABLESPACE • Data file information: – DBA_DATA_FILES – V$DATAFILE • Temp file information: – DBA_TEMP_FILES – V$TEMPFILE 8-47 Copyright © Oracle Corporation, 2002 All rights reserved Summary In this lesson, you should have learned how to: • Use tablespaces to separate data • Create various types of tablespaces • Manage tablespaces • Manage tablespaces using OMF • Obtain tablespace information 8-48 Copyright © Oracle Corporation, 2002 All rights reserved Practice Overview This practice covers the following topics: • Creating tablespaces • Modifying tablespaces • Configuring for and creating a tablespace using OMF 8-49 Copyright © Oracle Corporation, 2002 All rights reserved [...]... Moving Data Files • ALTER TABLESPACE – Tablespace must be offline – Target data files must exist ALTER TABLESPACE userdata RENAME DATAFILE '/u01/oradata/userdata01.dbf' TO '/u02/oradata/userdata01.dbf'; 8-39 Copyright © Oracle Corporation, 2002 All rights reserved Methods for Moving Data Files • ALTER DATABASE – Database must be mounted – Target data file must exist ALTER DATABASE RENAME FILE '/u01/oradata/system01.dbf'... space in database • Example: ALTER DATABASE DATAFILE '/u03/oradata/userdata02.dbf' RESIZE 200M; 8-36 Copyright © Oracle Corporation, 2002 All rights reserved Adding Data Files to a Tablespace • Increases the space allocated to a tablespace by adding additional data files • ADD DATAFILE clause is used to add a data file • Example: ALTER TABLESPACE user _data ADD DATAFILE '/u01/oradata/userdata03.dbf'... '/u01/oradata/userdata01.dbf' SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE 500M; • Query the DBA _DATA_ FILES view to determine whether AUTOEXTEND is enabled 8-33 Copyright © Oracle Corporation, 2002 All rights reserved Manually Resizing a Data File • Manually increase or decrease a data file size using ALTER DATABASE • Resizing a data file adds more space without adding more data files • Manual resizing of a data. .. a data file: – Automatically using AUTOEXTEND – Manually using ALTER DATABASE • Adding a data file using ALTER TABLESPACE 8-31 Copyright © Oracle Corporation, 2002 All rights reserved Enabling Automatic Extension of Data Files • Can be resized automatically with the following commands: – CREATE DATABASE – CREATE TABLESPACE – ALTER TABLESPACE … ADD DATAFILE • Example: CREATE TABLESPACE user _data DATAFILE... temporary data • Can be created by using: – CREATE DATABASE – ALTER DATABASE 8-18 Copyright © Oracle Corporation, 2002 All rights reserved Creating a Default Temporary Tablespace • During database creation: CREATE DATABASE DBA01 LOGFILE GROUP 1 ('/$HOME/ORADATA/u01/redo01.log') SIZE 100M, GROUP 2 ('/$HOME/ORADATA/u02/redo02.log') SIZE 100M, MAXLOGFILES 5 MAXLOGMEMBERS 5 MAXLOGHISTORY 1 MAXDATAFILES 100... '/u03/oradata/system01.dbf'; 8-40 Copyright © Oracle Corporation, 2002 All rights reserved Dropping Tablespaces • You cannot drop a tablespace if it: – Is the SYSTEM tablespace – Has active segments • INCLUDING CONTENTS drops the segments • INCLUDING CONTENTS AND DATAFILES deletes data files • CASCADE CONSTRAINTS drops all referential integrity constraints DROP TABLESPACE userdata INCLUDING CONTENTS AND DATAFILES;... tablespace and data file information can be obtained by querying the following: • Tablespace information: – DBA _TABLESPACES – V$TABLESPACE • Data file information: – DBA _DATA_ FILES – V$DATAFILE • Temp file information: – DBA_TEMP _FILES – V$TEMPFILE 8-47 Copyright © Oracle Corporation, 2002 All rights reserved Summary In this lesson, you should have learned how to: • Use tablespaces to separate data •... 2002 All rights reserved Managing Tablespaces Using OMF • Creating an OMF tablespace: CREATE TABLESPACE text _data DATAFILE SIZE 20M; • Adding an OMF data file to an existing tablespace: ALTER TABLESPACE text _data ADD DATAFILE; • Dynamically changing default file location: ALTER SYSTEM SET db_create_file_dest = '/u01/oradata/dba01'; • Dropping a tablespace includes deleting OS files: 8-46 Copyright ©... MAXINSTANCES 1 DATAFILE '/$HOME/ORADATA/u01/system01.dbf' SIZE 325M UNDO – TABLESPACE undotbs DATAFILE '/$HOME/ORADATA/u02/undotbs01.dbf' SIZE 200 DEFAULT TEMPORARY TABLESPACE temp TEMPFILE '/$HOME/ORADATA/u03/temp01.dbf' SIZE 4M CHARACTER SET US7ASCII 8-19 Copyright © Oracle Corporation, 2002 All rights reserved Creating a Default Temporary Tablespace • After database creation: ALTER DATABASE DEFAULT... CONTENTS AND DATAFILES; 8-42 Copyright © Oracle Corporation, 2002 All rights reserved Managing Tablespaces Using OMF • Define the DB_CREATE_FILE_DEST parameter in one of the following ways: – Initialization parameter file – Set dynamically using ALTER SYSTEM command ALTER SYSTEM SET db_create_file_dest = '/u01/oradata/dba01'; • When creating the tablespace: – Data file is automatically created and located ... Tablespaces and Data Files Oracle stores data logically in tablespaces and physically in data files • Tablespaces: – Can belong to only one database at a time – Consist of one or more data files. .. Moving Data Files • ALTER TABLESPACE – Tablespace must be offline – Target data files must exist ALTER TABLESPACE userdata RENAME DATAFILE '/u01/oradata/userdata01.dbf' TO '/u02/oradata/userdata01.dbf';... DATABASE • Resizing a data file adds more space without adding more data files • Manual resizing of a data file reclaims unused space in database • Example: ALTER DATABASE DATAFILE '/u03/oradata/userdata02.dbf'

Ngày đăng: 04/12/2015, 01:11

Từ khóa liên quan

Mục lục

  • Managing Tablespaces and Data Files

  • Objectives

  • Tablespaces and Data Files

  • Types of Tablespaces

  • Creating Tablespaces

  • Space Management in Tablespaces

  • Locally Managed Tablespaces

  • Dictionary-Managed Tablespaces

  • Migrating a Dictionary-Managed SYSTEM Tablespace

  • Undo Tablespace

  • Temporary Tablespaces

  • Default Temporary Tablespace

  • Creating a Default Temporary Tablespace

  • Slide 20

  • Restrictions on Default Temporary Tablespace

  • Read-Only Tablespaces

  • Taking a Tablespace Offline

  • Changing Storage Settings

  • Resizing a Tablespace

  • Enabling Automatic Extension of Data Files

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan