Oracle 10g Database Administrator: Implementation and Administration Chapter 8 Advanced Table Management.

Slides:



Advertisements
Similar presentations
CHAPTER 4 Tablespaces and Datafiles. Introduction After installing the binaries, creating a database, and configuring your environment, the next logical.
Advertisements

11 Copyright © Oracle Corporation, All rights reserved. Managing Tables.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
The Architecture of Oracle
Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.
Basic Storage Concepts and Settings
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Harvard University Oracle Database Administration Session 2 System Level.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Harvard University Oracle Database Administration Session 5 Data Storage.
Introduction to Structured Query Language (SQL)
Oracle Database Administration Database files Logical database structures.
CHAPTER 11 Large Objects. Need for Large Objects Data type to store objects that contain large amount of text, log, image, video, or audio data. Most.
IT Database Administration Section 03. Tablespaces and the DBA  Important for DBAs – logical units of database storage Made up of physical operating-system.
Oracle for Software Developers. What is a relational database? Data is represented as a set of two- dimensional tables. (rows and columns) One or more.
9/11/2015ISYS366 - Week051 ISYS366 – Week 5-6 Database Tuning - User and Rollback Data Spaces, Recovery, Backup.
Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
Cao Tiến Đức. Outline What is TDE How TDE works Basic TDE operations Tablespace encryption HSM Reference.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
1 Oracle Database 11g – Flashback Data Archive. 2 Data History and Retention Data retention and change control requirements are growing Regulatory oversight.
7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.
Extents, segments and blocks in detail. Database structure Database Table spaces Segment Extent Oracle block O/S block Data file logical physical.
Architecture Rajesh. Components of Database Engine.
9 Storage Structure and Relationships. 9-2 Objectives Listing the different segment types and their uses Controlling the use of extents by segments Stating.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 7 Basic Table Management.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Oracle 10g Database Administrator: Implementation and Administration Chapter 7 Basic Table Management.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
6 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Week 3 Lecture 2 Basic Storage Concepts and Settings.
14 Copyright © 2006, Oracle. All rights reserved. Tuning Block Space Usage.
IT Database Administration Section 09. Backup and Recovery Backup: The available options Full Consistent (cold) Backup Database shutdown, all files.
Week 4 Lecture 2 Advanced Table Management. Learning Objectives  Create tables with large object (LOB) columns and tables that are index-organized 
Harvard University Oracle Database Administration Session 6 Object Storage.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
1 Chapter 2: Creating and Modifying Database Objects.
Oracle 10g Database Administrator: Implementation and Administration Chapter 5 Basic Storage Concepts and Settings.
2 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.
Managing Schema Objects
Chapter 5 Index and Clustering
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Unit 6 Seminar. Indexed Organized Tables Definition: Index Organized Tables are tables that, unlike heap tables, are organized like B*Tree indexes.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Chapter 3 Table Creation and Management Oracle 10g: SQL.
1 Part IV: Object-Relational Databases  Ch. 30: Types, Object Views, Methods  Ch. 31: Nested Tables and Varying Arrays  Ch. 32: Large Objects  Ch.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
What is the Flashback Database? Improves a database’s availability Useful alternative to traditional restoration methods Contains Flashback logs Archived.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects.
23 Copyright © 2004, Oracle. All rights reserved. Preferring the Past: Flashback.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
1 Chapters 19 and 20  Ch. 19: By What Authority? Users Roles Grant and revoke Synonyms  Ch. 20: Changing the Oracle Surroundings Indexes Clusters Sequences.
Fundamentals of DBMS Notes-1.
Database structure and space Management
Oracle 10g Database Administrator: Implementation and Administration
DATABASE MANAGEMENT SYSTEM
SQL data definition using Oracle
Managing Tables.
Database administration
Presentation transcript:

Oracle 10g Database Administrator: Implementation and Administration Chapter 8 Advanced Table Management

Oracle 10g Database Administrator: Implementation and Administration 2 Objectives Create tables with large object (LOB) columns Create index-organized tables Analyze tables to collect statistics of data in a table Understand the tasks involved in table management including table storage structure Changing table columns

Oracle 10g Database Administrator: Implementation and Administration 3 Objectives (continued) Redefine a table when the table is online Specialized table changes including flashback and transparent encryption Understand the tasks involved in table management Use data dictionary views to find information about tables and underlying structures

Oracle 10g Database Administrator: Implementation and Administration 4 Advanced Table Structure Two table types use unusual methods of storing data –Tables with LOB columns Can store huge amounts of data in a single column –E.g., the digital audio file for one song on a CD –Index-organized tables Help you query table rows more quickly by reducing the number of times a process must read either memory or disk to retrieve the row data, when rows are read according to the primary key –E.g., a table used to look up the population of a city by its state, county, and municipal code

Oracle 10g Database Administrator: Implementation and Administration 5 Tables with LOB Columns LOB datatypes –BLOB: binary large object –CLOB: character large object (for storing text strings) –NCLOB: as for CLOB but using Unicode –BFILE: a pointer to externally stored multimedia file Two groups –Internal LOB (BLOB, CLOB, and NCLOB) Have their data stored inside the database Use copy semantics –External LOB (BFILE) Data is stored outside the database in an OS file Reference semantics

Oracle 10g Database Administrator: Implementation and Administration 6 Tables with LOB Columns (continued) Example: CREATE TABLE SOUNDBYTES (ALBUM_ID VARCHAR2(20), ARTIST VARCHAR2(40), CD_MUSIC BFILE, POSTER_SHOT BLOB); PL/SQL package called DBMS_LOB is used to simplify the manipulation of data in LOB columns –OPEN (, ) –CLOSE ( ) –ISOPEN ( ) –READ (,,, ) –WRITE (,,, ) –GETLENGTH ( ) –…

Oracle 10g Database Administrator: Implementation and Administration 7 LOB Storage

Oracle 10g Database Administrator: Implementation and Administration 8 LOB Storage (continued) When an internal LOB is stored out of line, a separate LOB data segment is created –You can specify that all LOB data is to be stored out of line CREATE TABLE (, ) LOB ( ) STORE AS (TABLESPACE ENABLE STORAGE IN ROW|DISABLE STORAGE IN ROW CHUNK STORAGE (INITIAL NEXT MAXEXTENTS UNLIMITED| ) PCTVERSION |RETENTION LOGGING|NOLOGGING CACHE|NOCACHE); max 32 KB

Oracle 10g Database Administrator: Implementation and Administration 9 LOB Storage (continued) You can define attributes with LOB datatypes in object types for use in object tables or user-defined datatype columns in relational tables LOB data segments can be used to store VARRAYs –VARRAYs LOB cannot be in a different tablespace than the table CREATE TYPE RACE_ARRAY AS VARRAY (1500) OF CHAR (25); / CREATE TABLE HORSERACE (HORSE_NAME VARCHAR2(50), RACE_LIST RACE_ARRAY) VARRAY RACE_LIST STORE AS LOB RACEARRAYLOB (CHUNK STORAGE (INITIAL 20M NEXT 40M MAXEXTENTS 100)) STORAGE (INITIAL 80M);

Oracle 10g Database Administrator: Implementation and Administration 10 LOB Storage (continued)

Oracle 10g Database Administrator: Implementation and Administration 11 Index-Organized Tables

Oracle 10g Database Administrator: Implementation and Administration 12 Index-Organized Tables (continued) A relational table with a primary key constraint has a unique index associated with the primary key –Index is stored in primary key order in a BTree –The index stores the primary key columns and the ROWID of the associated row –The actual data is stored in the data block An index-organized table does not have an index –Entire table becomes an index –Primary advantage of index-organized tables is that queries based on primary key are faster But, inserts, updates, and deletes are slower Additionally, continual change activity will eventually deteriorate the BTree structure

Oracle 10g Database Administrator: Implementation and Administration 13 Index-Organized Tables (continued)

Oracle 10g Database Administrator: Implementation and Administration 14 Index-Organized Tables (continued) Here are some additional points about index- organized tables: –You can include LOB columns –You can partition index-organized tables, but only using hash or range partitioning In addition, the partition key must be all or a subset of the primary key –You can add secondary indexes; however, they should be rebuilt if the table is updated often, so that the physical guess stored in the index is accurate –Inaccurate physical guesses cause extra I/O

Oracle 10g Database Administrator: Implementation and Administration 15 Overview of Table Management Change the storage setting –Adjust the size of the next extent, maximum extents, percent free, and most of the other storage settings Reorganize the table online –Rearrange/add/delete columns, change column names or datatypes while table remains online Drop columns –Mark a column as unavailable, or drop it immediately Truncate or drop the table –TRUNCATE removes all rows in table without generating redo log entries –DROP removes the rows and the table structure

Oracle 10g Database Administrator: Implementation and Administration 16 Analyzing a Table Analyze tables in schema to give optimizer up-to- date info for optimizing queries and SQL commands –To analyze a table, you issue a command that causes Oracle 10g to read the table’s structure and update the table’s metadata with current information –Provides accurate statistics for cost-based optimizer Optimizer: process that decides the most efficient method of executing a query; creates a query plan –Rule-based (no longer available) –Cost-based –Gives DBA in-depth information, helping decide which storage or column settings to change (if any)

Oracle 10g Database Administrator: Implementation and Administration 17 Analyzing a Table (continued) Use ANALYZE or the DBMS_STATS package –ANALYZE TABLE CUSTOMER COMPUTE STATISTICS; –ANALYZE TABLE CUSTOMER ESTIMATE STATISTICS SAMPLE 1000 ROWS; –EXECUTE DBMS_STATS.GATHER_TABLE_STATS ('CLASSMATE','CUSTOMER'); –BEGIN DBMS_STATS.GATHER_TABLE_STATS ('CLASSMATE','CUSTOMER'); END; –EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS('CLASSMATE');

Oracle 10g Database Administrator: Implementation and Administration 18 Adjusting Table Storage Structure Many portions of the storage structure of a table can be modified after the table is created ALTER TABLE. PCTFREE PCTUSED INITTRANS MAXTRANS STORAGE (NEXT PCTINCREASE MAXEXTENTS |UNLIMITED) ALLOCATE EXTENT SIZE DATAFILE DEALLOCATE UNUSED KEEP COMPRESS|NOCOMPRESS SHRINK SPACE [COMPACT] [CASCADE] MOVE TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MAXEXTENTS |UNLIMITED) COMPRESS|NOCOMPRESS ONLINE

Oracle 10g Database Administrator: Implementation and Administration 19 Adjusting Table Storage Structure (continued) DEALLOCATE UNUSED: releases unused data blocks above the high watermark of the table –High watermark: boundary between used data blocks and unused data blocks in a table ALTER TABLE HORSERACE DEALLOCATE UNUSED KEEP 50K; You can change the size of subsequent extents by changing the NEXT parameter to a smaller size ALTER TABLE CLASSIFIED_AD MOVE TABLESPACE USERS STORAGE (NEXT 56K);

Oracle 10g Database Administrator: Implementation and Administration 20 Redefining Tables Online Oracle’s online table redefinition allows you to make nearly any change to a table, while keeping table available for inserts/updates most of the time Phases: –Creation of an interim table –Redefinition of a table –Application of the redefinition back to original table PL/SQL package called DBMS_REDEFINITION –Must have several DBA-level privileges to use it

Oracle 10g Database Administrator: Implementation and Administration 21 Redefining Tables Online (continued) 1.CONNECT 2.GRANT EXECUTE_CATALOG_ROLE TO SYSTEM; 3.BEGIN DBMS_REDEFINITION.CAN_REDEF_TABLE ('CLASSMATE','CLASSIFIED_AD'); END; 4.BEGIN DBMS_REDEFINITION.CAN_REDEF_TABLE ('CLASSMATE','CLIENT'); END; 5.CREATE TABLE CLASSMATE.CLIENT1 (CLIENT_ID NUMBER(10) NOT NULL, FIRST_NAME VARCHAR2(10) NOT NULL, LAST_NAME VARCHAR2(20) NOT NULL, FULLNAME VARCHAR2(32), CONTACT_PHONE VARCHAR2(15), CONTACT_ VARCHAR2(30), CONSTRAINT CLIENT_PK1 PRIMARY KEY(CLIENT_ID)) TABLESPACE USERS PCTFREE 0 STORAGE (INITIAL 64K NEXT 8K MINEXTENTS 1 MAXEXTENTS 10);

Oracle 10g Database Administrator: Implementation and Administration 22 Redefining Tables Online (continued) 6.BEGIN DBMS_REDEFINITION.START_REDEF_TABLE ('CLASSMATE', 'CLIENT', 'CLIENT1', 'CLIENT_ID CLIENT_ID, FIRST_NAME FIRST_NAME, LAST_NAME LAST_NAME, SUBSTR(CONCAT(RPAD(FIRST_NAME,LENGTH(FIRST_NAME)+1), LAST_NAME),1,32) FULLNAME, CONTACT_PHONE CONTACT_PHONE, CONTACT_ CONTACT_ '); END; 7.BEGIN DBMS_REDEFINITION.ABORT_REDEF_TABLE ('CLASSMATE', 'CLIENT', 'CLIENT1'); END; 8.BEGIN DBMS_REDEFINITION.FINISH_REDEF_TABLE ('CLASSMATE','CLIENT', 'CLIENT1'); END; 9.SELECT * FROM CLASSMATE.CLIENT;

Oracle 10g Database Administrator: Implementation and Administration 23 Redefining Tables Online (continued)

Oracle 10g Database Administrator: Implementation and Administration 24 Redefining Tables Online (continued) You can use ALTER TABLE with object tables and relational tables, with object-type columns –Object tables and object-type columns are based on the definition of an object type On definition change, tables in which object type is used don’t change automatically; you must upgrade structure –Upgrading table structure causes object types used in table to be updated with most recent version of the object type definition ALTER TABLE CUSTOMER UPGRADE INCLUDING DATA;

Oracle 10g Database Administrator: Implementation and Administration 25 Dropping, Adding, or Modifying a Column in a Table ALTER TABLE. RENAME COLUMN TO ADD (,... ) MODIFY (,... ) DROP (,,...)|COLUMN CASCADE CONSTRAINTS SET UNUSED (,,...)|COLUMN CASCADE CONSTRAINTS DROP UNUSED COLUMNS –ALTER TABLE CH08SURGERY RENAME COLUMN PATIENT_FISRT_NAME TO PATIENT_FIRST_NAME; –ALTER TABLE CH08SURGERY ADD (OUTCOME VARCHAR2(40), OPERATING_ROOM_NO CHAR(4)); –ALTER TABLE CH08SURGERY MODIFY (DOCTOR_NAME VARCHAR2(20)); –ALTER TABLE CH08SURGERY MODIFY (DOCTOR_NAME VARCHAR2(25)); –ALTER TABLE CH08SURGERY SET UNUSED (PROCEDURES, OUTCOME); –ALTER TABLE CH08SURGERY ADD (PROCEDURES PROCEDURES_ARRAY, OUTCOME NUMBER(2,0)); –ALTER TABLE CH08SURGERY DROP UNUSED COLUMNS;

Oracle 10g Database Administrator: Implementation and Administration 26 Dropping, Adding, or Modifying a Column in a Table (continued)

Oracle 10g Database Administrator: Implementation and Administration 27 Truncating and Dropping a Table DELETE FROM ; –Oracle 10g background processes to write undo records and redo log entries for each row deleted This can be reversed by executing a ROLLBACK, but takes time TRUNCATE TABLE. DROP STORAGE|REUSE STORAGE –Does not generate undo records or redo log entries –DROP STORAGE (default) frees up all but the space allocated to the table except space required by the MINEXTENTS setting of the table or tablespace Use DROP TABLE to remove rows and table structure

Oracle 10g Database Administrator: Implementation and Administration 28 The Recycle Bin DROP TABLE. [ CASCADE CONSTRAINTS ] [ PURGE ] By default, the CASCADE CONSTRAINTS and PURGE options are not included in a DROP TABLE –When dropping a table, it will automatically be saved in the Oracle 10g database recycle bin A table in the recycle bin can be recovered to its prior state using FLASHBACK TABLE FLASHBACK TABLE. TO BEFORE DROP [ RENAME TO, tablename> ] –Example: FLASHBACK TABLE COPCAR TO BEFORE DROP RENAME TO COPCARS;

Oracle 10g Database Administrator: Implementation and Administration 29 Making Other More Specialized Table Changes You can make several other specialized table changes using the ALTER TABLE command ALTER TABLE. RENAME TO LOGGING|NOLOGGING ENABLE|DISABLE ROW MOVEMENT CACHE|NOCACHE For example: –ALTER TABLE EMPLOYEE CACHE;

Oracle 10g Database Administrator: Implementation and Administration 30 Table Flashback Recovery Syntax for the FLASHBACK TABLE command: FLASHBACK TABLE. [ {TO SCN | TIMESTAMP} ] [ {ENABLE | DISABLE} TRIGGERS ] [ TO RESTORE POINT ] [ { ENABLE | DISABLE } TRIGGERS ] [ BEFORE DROP [ RENAME TO ] ] TO RESTORE POINT is used to restore a table to a previously set restore point –A restore point must have been created with the CREATE RESTORE POINT command Using BEFORE DROP can allow the recovery of a previously dropped table from the recycle bin, where a new copy of the table already exists

Oracle 10g Database Administrator: Implementation and Administration 31 Transparent Table Encryption Oracle 10g has introduced encryption of data within the confines of an Oracle database, preventing potential snooping into datafiles from outside the confines of Oracle database software { CREATE | ALTER } TABLE. ENCRYPT [ USING 'encryption algorithm' ] [ IDENTIFIED BY ] [ [NO] SALT ] All subsequent use of encryption is automated, or transparent

Oracle 10g Database Administrator: Implementation and Administration 32 Querying Data Dictionary Views for Tables and Other Objects

Oracle 10g Database Administrator: Implementation and Administration 33 Summary LOB datatypes are internal (stored within the DB) or external (stored outside the DB) –Oracle 10g contains a package called DBMS_LOB, used to manage and access LOB objects –By default, internal LOB values are stored inline (if less than 4000 bytes long); larger internal LOB values are stored out of line in a LOB data segment –Oracle 10g works with LOBs by reading and writing one chunk at a time –LOB segment and table storage settings are similar –LOB datatypes can be part of partitioned tables, index- organized tables, and object tables –LOB data segments can be used for VARRAY data

Oracle 10g Database Administrator: Implementation and Administration 34 Summary (continued) Index-organized tables require a primary key, and store data in order –Can split column data in main and overflow segments ANALYZE gathers statistics on a table’s size, number of rows, column distribution, and free space –DBMS_STATS package is a better option Changing a table’s storage parameters involves using the ALTER TABLE command DBMS_REDEFINITION package can help restructure a table while keeping it online most of the time Upgrading object/relational table with object columns redefines their object types with latest definition

Oracle 10g Database Administrator: Implementation and Administration 35 Summary (continued) Rename a table with ALTER TABLE... RENAME –Modifying columns also uses ALTER TABLE To a drop column involved in another table’s foreign key constraint, specify CASCADE CONSTRAINTS –SET UNUSED marks column for dropping later If you truncate a table, you cannot undo the transaction with a ROLLBACK command Use DROP TABLE... CASCADE CONSTRAINTS if table is named in foreign keys in other related tables Data dictionary views store table, segment, extent, column, and LOB segment information