-1-
1. selec select t * from from V$SG V$SGA; A; SQL> select * from V$SGA; NAME VALUE -------------------- ---------Fixed Size 1247924 Variable Size 62915916 Database Buffers 104857600 Redo Buffers 2945024
2. select component, component,current current_size _size from from v$sga_dynamic_c v$sga_dynamic_componen omponents; ts; SQL> select component,current_size from v$sga_dynamic_components; COMPONENT CURRENT_SIZE ---------------------------------------------------------------- -----------shared pool 54525952 large pool 4194304 java pool 4194304 streams pool 0 DEFAULT buffer cache 104857600 KEEP buffer cache 0 RECYCLE buffer cache 0 DEFAULT 2K buffer cache 0 DEFAULT 4K buffer cache 0 DEFAULT 8K buffer cache 0 DEFAULT 16K buffer cache 0 COMPONENT CURRENT_SIZE ---------------------------------------------------------------- -----------DEFAULT 32K buffer cache 0 ASM Buffer Cache 0 13 rows selected.
3. select select name name from v$con v$control trolfil file; e; SQL> select name from v$controlfile; NAME ----------------------------------------------------------------------------I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\CONTROL01.CTL I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\CONTROL02.CTL I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\CONTROL03.CTL
-2-
SQL> show sga; Total System Global Area 147615836 bytes Fixed Size 282716 bytes Variable Size 113246208 bytes Database Buffers 33554432 bytes Redo Buffers 532480 bytes SQL> alter system set shared_pool_size=20000000; System altered. SQL> alter system set db_cache_size = 50000000; System altered. SQL> show sga Total System Global Area 147615836 bytes Fixed Size 282716 bytes Variable Size 96468992 bytes Database Buffers 50331648 bytes Redo Buffers 532480 bytes SQL>
Using Oracle's SGA and PGA Advisories
SQL> select statistics_view_name from v$statistics_level; STATISTICS_VIEW_NAME --------------------------------------------V$DB_CACHE_ADVICE V$MTTR_TARGET_ADVICE /*this column is for 'timed statistics'*/ /*this column is for 'timed OS statistics'*/ V$SEGSTAT V$PGA_TARGET_ADVICE V$SQL_PLAN_STATISTICS V$SHARED_POOL_ADVICE 8 rows selected.
The Buffer Cache Advisory SQL> select size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_reads from v$db_cache_advice where name = 'DEFAULT' AND block_size = 4096;
-3The Shared Pool Advisory SQL> desc v$shared_pool_advice; Name Null? Type --------------------------------------------------------------------SHARED_POOL_SIZE_FOR_ESTIMATE NUMBER SHARED_POOL_SIZE_FACTOR NUMBER ESTD_LC_SIZE NUMBER ESTD_LC_MEMORY_OBJECTS NUMBER ESTD_LC_TIME_SAVED NUMBER ESTD_LC_TIME_SAVED_FACTOR NUMBER ESTD_LC_MEMORY_OBJECT_HITS NUMBER
The PGA Advisory SQL> desc v$pga_target_advice Name Null? Type ------------------------------------- -------- -----------------------PGA_TARGET_FOR_ESTIMATE NUMBER PGA_TARGET_FACTOR NUMBER ADVICE_STATUS VARCHAR2(3) BYTES_PROCESSED NUMBER ESTD_EXTRA_BYTES_RW NUMBER ESTD_PGA_CACHE_HIT_PERCENTAGE NUMBER ESTD_OVERALLOC_COUNT NUMBER 4. SQL> select select tablespace_name tablespace_name from from dba_tablespaces dba_tablespaces order order by tablespace_na tablespace_name; me; TABLESPACE_NAME -----------------------------EXAMPLE SYSAUX SYSTEM TEMP UNDOTBS1 USERS 6 rows selected. 5. select tablespace tablespace_name, _name, file_name file_name from dba_data_fil dba_data_files es order by by tablespace_name; 6. select group#, group#, member from from v$logfile v$logfile order order by group#; 7. select group#, group#, members, members, status status from v$log v$log order order by group#; group#; SQL> startup force pfile=I:\oracle\product\10.2.0\admin\sara\pfile\init.ora.102220109041; ORACLE instance started. Total System Global Area Fixed Size Variable Size Database Buffers Redo Buffers Database mounted. Database opened.
171966464 1247924 62915916 104857600 2945024
bytes bytes bytes bytes bytes
-4Select file_name from dba_data_files; SQL> Select file_name from dba_data_files; FILE_NAME ----------------------------------------------------------------------------I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\USERS01.DBF I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\SYSAUX01.DBF I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\UNDOTBS01.DBF I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\SYSTEM01.DBF I:\ORACLE\PRODUCT\10.2.0\ORADATA\SARA\EXAMPLE01.DBF
CREATE TABLESPACE TBS logging datafile 'I:/oracle/product/10.2.0/oradata/sara/TBS1.DBF’ SIZE 10m; SQL> CREATE TABLESPACE TBSpace datafile 'I:/oracle/product/10.2.0/oradata/sara/TBS2.DBF' SIZE 10m; Tablespace created. create tablespace sales01 logging datafile 'I:/oracle/product/10.2.0/oradata/sara/sales01_01.dbf' size 25M autoextend on next 2560k maxsize unlimited extent management local uniform size 16M; SQL> create tablespace sales01 logging datafile 2 'I:/oracle/product/10.2.0/or 'I:/oracle/product/10.2.0/oradata/sara/sales01_01.dbf' adata/sara/sales01_01.dbf' size 25M 3 autoextend on next 2560k maxsize unlimited extent management local 4 uniform size 16M; Tablespace created. create tablespace saleindx01 logging datafile 'I:/oracle/product/10.2.0/oradata/sara/saleiindx01_01.dbf' size 25M autoextend on next 2560k maxsize unlimited extent management local uniform size 16M; SQL> create tablespace saleindx01 logging 2 datafile 'I:/oracle/product/10.2. 'I:/oracle/product/10.2.0/oradata/sara/saleiindx01_0 0/oradata/sara/saleiindx01_01.dbf' 1.dbf' 3 size 25M autoextend on next 2560k maxsize unlimited 4 extent management local uniform size 16M; Tablespace created. SQL> select tablespace_name from dba_tablespaces; TABLESPACE_NAME -----------------------------SYSTEM UNDOTBS1 SYSAUX TEMP USERS EXAMPLE SALES01 SALEINDX01 8 rows selected.
-5The V$PARAMETER Table
SQL> select name,value,isdefault from v$parameter SQL> select name,value from v$parameter where name like '%dump%' SQL> show parameter dump; SQL> select * from v$version; Creating a New User
create user salapati Identified by sam1am9 Default tablespace sales01 Temporary tablespace temp; SQL> create user salapati 2 Identified by sam1am9 3 Default tablespace sales01 Temporary tablespace temp; User created. Select program ,pga_used_mem ,pga_alloc_mem ,pga_max_mem from v$process order by pga_used_mem desc;
create index employee_id on employee(employee_id) tablespace SALES01_01; SQL> begin for id in 1 to 10 loop insert into employee values(id, “sara”); end loop end; / create index employee_id on employee(employee_id) tablespace SALES01_01;
CREATE TABLE employee_new ( EMPLOYEE_ID number, DEPT_ID number, NAME varchar2(30), ADDRESS varchar2(120), CITY varchar2(30), STATE char(2), PHONE_NUMBER number, ORGANIZATION INDEX TABLESPACE SALES01_01; PCTTHRESHOLD 25 OVERFLOW TBLESPACE OVERFLOW TABLES;
-6-
select program ,pga_used_mem ,pga_alloc_mem ,pga_max_mem from v$process order by pga_used_mem desc; select * from v$pgastat;
SQL> 2 3 4 5 6 7* SQL>
select a.username, s.sql_text from v$session a,v$sqltext s where a.sql_address = s.address and a.sql_hash_value = s.hash_value AND A.STATUS='ACTIVE' order by a.username,a.sid,s.piece /
USERNAME SQL_TEXT ---------------------------------------------------------------SYSTEM select a.sid,a.username, s.sql_text from v$session a,v$sqltext s where a.sql_address = s.address and a.sql_hash_value = s.hash_v AND A.STATUS='ACTIVE' order by a.username,a.sid,s.piece SYS Select f.file#, f.block#, f.ts#, f.length from fet$ f, ts$ t where t.ts#=f.ts# and t.dflextpct!=0 and t.bitmapped=0 SQL>
create tablespace test01 datafile 'I:/oracle/product/10.2.0/oradata/sara/test01.dbf' size 100M; SQL>create tablespace test01 2 datafile 'I:/oracle/product/10.2.0/oradata/sara/test01.dbf' 3 size 100M; Tablespace created. SQL> Note: Extent allocation : autoallocate (default) Segment space : manual (default)
-7SQL> create tablespace test02 datafile 'I:/oracle/product/10.2.0/oradata/sara/test02.dbf' size 100M autoallocate; Tablespace created. SQL> Note: Extent allocation: autoallocate (explicitly chosen option) Segment space : manual (default)
SQL> create tablespace test03 datafile 'I:/oracle/product/10.2.0/oradata/sara/test03.dbf' size 100M segment space management auto; Tablespace created. SQL> Note: Extent allocation : autoallocate (default) Segment space : automatic
SQL>
create tablespace test04 datafile 'I:/oracle/product/10.2.0/oradata/sara/test04.dbf' size 100M uniform size 2m; Tablespace created. SQL> Note: Extent allocation : uniform size 2m Segment space : manual (default) SQL> create tablespace test05 datafile 'I:/oracle/product/10.2.0/oradata/sara/test05.dbf' size 100M uniform size 2m segment space management auto; Tablespace created. SQL> Note: Extent allocation : uniform size 2m Segment space : auto
SQL> select tablespace_name, initial_extent, next_extent, extent_management, allocation_type, segment_space_management from dba_tablespaces; TABLESPACE INITIAL NEXT
EXTENT
ALLOCATIO
SEGMENT
-8----------------EXTENT SYSTEM 65536 UNDOTBS 65536 TEMPTBS1 1048576 USERS 65536 TEST01 65536 TEST02 65536 TEST03 65536 TEST04 2097152 TEST05 2097152 9 rows selected.
–EXTENT
1048576
2097152 2097152
--MNAGMNT--- TYPE----LOCAL SYSTEM LOCAL SYSTEM LOCAL UNIFORM LOCAL SYSTEM LOCAL SYSTEM LOCAL SYSTEM LOCAL SYSTEM LOCAL UNIFORM LOCAL UNIFORM
-SPACEMANUAL MANUAL MANUAL MANUAL MANUAL MANUAL AUTO MANUAL AUTO
Creating Temporary Tablespaces create temporary tablespace temptbs02i tempfile 'I:/oracle/product/10.2.0/oradata/sara/temp02.dbf' size 100M; Tablespace created. SQL>create temporary tablespace temptbs02i 2 tempfile 3 'I:/oracle/product/10.2.0/oradata/sara/temp02.dbf' 4 size 100M; Tablespace created.
SQL>drop tablespace test01; Tablespace dropped. drop tablespace test02 cascade constraints; Manual: copy from 'I:/oracle/product/10.2.0/oradata/sara/test02.dbf' to 'I:/oracle/product/10.2.0/oradata/sara/test06.dbf'
alter tablespace test02 rename datafile 'I:/oracle/product/10.2.0/oradata/sara/test02.dbf' to 'I:/oracle/product/10.2.0/oradata/sara/test06.dbf'; SQL>alter tablespace test02 2 rename 3 datafile 'I:/oracle/product/10.2.0/ 'I:/oracle/product/10.2.0/oradata/sara/test02.dbf' oradata/sara/test02.dbf' 4 to 5 'I:/oracle/product/10.2.0/oradata/sara/test06.dbf'; Tablespace altered. create tablespace test01
-9datafile 'I:/oracle/product/10.2.0/oradata/sara/test07.dbf' size 100M; SQL>alter tablespace test01 read only; Tablespace altered. SQL>alter tablespace test01 read write; Tablespace altered. SQL>desc dba_data_files Name Null? Type --------------------------------------- -------- --------------------FILE_NAME VARCHAR2(513) FILE_ID NUMBER TABLESPACE_NAME VARCHAR2(30) BYTES NUMBER BLOCKS NUMBER STATUS VARCHAR2(9) RELATIVE_FNO NUMBER AUTOEXTENSIBLE VARCHAR2(3) MAXBYTES NUMBER MAXBLOCKS NUMBER INCREMENT_BY NUMBER USER_BYTES NUMBER USER_BLOCKS NUMBER ONLINE_STATUS VARCHAR2(7)
SQL>select tablespace_name,status,extent_management from dba_tablespaces; TABLESPACE_NAME -----------------------------SYSTEM UNDOTBS1 SYSAUX TEMP USERS EXAMPLE SALES01 SALEINDX01 TBS TBSPACE TEST01
STATUS --------ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE
EXTENT_MAN ---------LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL
TABLESPACE_NAME -----------------------------TEST02 TEST03 TEST04 TEST05 TEMPTBS02I
STATUS --------OFFLINE ONLINE ONLINE ONLINE ONLINE
EXTENT_MAN ---------LOCAL LOCAL LOCAL LOCAL LOCAL
16 rows selected.
- 10 CREATE TABLE emp ( empno ename job mgr hiredate sal comm deptno
NUMBER(5) PRIMARY KEY, VARCHAR2(15) NOT NULL, VARCHAR2(10), NUMBER(5), DATE DEFAULT sysdate, NUMBER(7,2), NUMBER(7,2), NUMBER(3) NOT NULL) TABLESPACE test01
; CREATE TABLE emp1 ( empno NUMBER(5) PRIMARY KEY, employee_name VARCHAR2(15) NOT NULL, job VARCHAR2(10), manager NUMBER(5), hire_date DATE DEFAULT (sysdate), salary NUMBER(7,2), commission NUMBER(7,2), department_no NUMBER(3) NOT NULL ) PCTFREE 10 PCTUSED 40 TABLESPACE users STORAGE ( INITIAL 50K NEXT 50K MAXEXTENTS 10 PCTINCREASE 25 );
Alter table emp1 move Storage (initial 2m Next extents 2m Minextents 2 Maxextents 40); CREATE GLOBAL TEMPORARY TABLE flight_status ( destination varchar2(30), startdate date, return_date date, ticket_price number ) on commit preserve rows; CREATE GLOBAL TEMPORARY TABLE sales_info ( customer_name varchar2(30), transaction_no number, transaction_date date ) on commit delete rows;
- 11 -
CREATE TABLESPACE sysaux DATAFILE '/u10/oradata/prod/sysaux01.dbf' SIZE 500M REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
CREATE TABLESPACE sysaux DATAFILE 'I:/oracle/product/10.2.0/oradata/sara/sysaux02.dbf' SIZE 500M REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
SQL> SELECT log_mode FROM v$database; LOG_MODE -----------NOARCHIVELOG SQL> archive log list; Database log mode Automatic archival Archive destination Oldest online log sequence Current log sequence SQL>
No Archive Mode Disabled USE_DB_RECOVERY_FILE_DEST 7 9
CREATE TABLE employee_new( employee_new( employee_id NUMBER, dept_id NUMBER, name VARCHAR2(30), address VARCHAR2(120), VARCHAR2(120), CONSTRAINT pk_employee_new PRIMARY KEY (employee_id)) (employee_id)) ORGANIZATION INDEX TABLESPACE test01 PCTTHRESHOLD 25 OVER FLOW TABLESPACE overflow_tables; SQL> CREATE TABLE sales_data (ticket_no NUMBER, sale_year INT NOT NULL, sale_month INT NOT NULL, sale_day INT NOT NULL) PARTITION BY RANGE (sale_year, sale_month, sale_month, sale_day) (PARTITION sales_q1 VALUES LESS THAN (2004, 04, 01) TABLESPACE test01, PARTITION sales_q2 VALUES LESS THAN (2004, 07, 01) TABLESPACE test03, PARTITION sales_q3 VALUES LESS THAN (2004, 10, 01) TABLESPACE test04, PARTITION sales_q4 VALUES LESS THAN (2005, 01, 01) TABLESPACE test05); Table created. created. SQL> Creating a New User
- 12 -
create user saran Identified by saran83 Default tablespace sales01 Temporary tablespace temp;
SQL> grant connect to saran; Grant succeeded. SQL> CREATE USER aaron IDENTIFIED BY soccer DEFAULT TABLESPACE test01 TEMPORARY TABLESPACE temp QUOTA 15m ON test01 PASSWORD EXPIRE; SQL> CREATE USER aaron IDENTIFIED BY soccer DEFAULT TABLESPACE test01 TEMPORARY TABLESPACE temp QUOTA 15m ON test01 PASSWORD EXPIRE; User created. CREATE USER aaron IDENTIFIED EXTERNALLY DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE temp QUOTA 15m ON data PASSWORD EXPIRE; SQL> ALTER USER aaron 2 QUOTA 0 ON USERS; User altered. SQL> DROP USER aaron; User dropped. SQL> DROP USER aaron CASCADE; User dropped.
SQL> CREATE USER salapati IDENTIFIED BY sammyy1; User created.
- 13 SELECT default_tablespace, temporary_tablespace FROM dba_users WHERE username='SALAPATI'; username='SALAPATI';
SQL> SELECT default_tablespace, temporary_tablespace 2 FROM dba_users 3 WHERE username='SALAPATI'; DEFAULT_TABLESPACE TEMPORARY_TABLESPACE ------------------------------ -----------------------------USERS TEMP SQL> GRANT CREATE SESSION TO salapati; Grant succeeded. SQL> GRANT CONNECT to nina IDENTIFIED BY nina1; Grant succeeded. SQL> CONNECT salapati/sammyy1 Connected. SQL> SQL> CREATE TABLE xyz (name VARCHAR2(30)); CREATE TABLE xyz (name VARCHAR2(30)) * ERROR at line 1: ORA-01031: insufficient privileges ALTER USER salapati QUOTA 100M ON test01;
create role new_dba;
SQL> grant connect to new_dba; Grant succeeded. SQL> grant select any table to new_dba; Grant succeeded. SQL> grant update any table to new_dba; Grant succeeded. SQL> grant select_catalog_role to new_dba; Grant succeeded. SQL> grant exp_full_database to new_dba; Grant succeeded. SQL> grant imp_full_database to new_dba; Grant succeeded. SQL>
- 14 -
Partial list of database components components and their related data dictionary views views Component
Data dictionary tables and views
Database
V$DATABASE, V$VERSION, V$INSTANCE
Shared server
V$QUEUE, V$DISPATCHER, V$SHARED SERVER
Tabl Tables espa pace cess
DBA_T DBA_TAB ABLE LESP SPAC ACES ES,, DBA_ DBA_DA DATA TA_FI _FILE LES, S, DBA_ DBA_FR FREE EE_S _SPAC PACE E
Control files
V$CONTROLFILE, V$PARAMETER, V$CONTROLFILE_RECORD_SECTION
Datafiles
V$DATAFILE, V$DATAFILE_HEADER, V$FILESTAT, DBA_DATA_FILES
Segments
DBA_SEGMENTS
Extents
DBA_EXTENTS
Redo threads, groups, and numbers
V$THREAD, V$LOG, V$LOGFILE
Archiving status
V$DATABASE, V$LOG, V$ARCHIVED_LOG, V$ARCHIVE_DEST
Database instance
V$INSTANCE, V$PARAMETER, V$SYSTEM_PARAMETER
Memory structure
V$SGA, V$SGASTAT, V$SGAINFO, V$SGA_DYNAMIC_COMPONENTS, V$SGA_DYNAMIC_FREE_MEMORY, V$SGA_RESIZE_OPS, V$SGA_RESIZE_CURRENT_OPS, V$DB_OBJECT_CACHE, V$SQL, V$SQLTEXT, V$SQLAREA
Work area memory
V$PGASTAT, V$SYSSTAT, V$SESSTAT
Proce ocesses
V$PRO PROCESS, V$BGPRO PROCESS, V$ V$SESS SESSIION, V$ V$LOCK
RMAN recovery
V$RECOVER_FILE
User User passwo passwords rds V$PWFIL V$PWFILE_U E_USER SERS S PGA
PGA_AGGREGATE_TARGET, PGA_AGG
- 15 -
- 16 -
The following query of USER_INDEXES shows the the new indexes on the EMP table: