This action might not be possible to undo. Are you sure you want to continue?
As discussed in Chapter 3, Oracle assigns all of its data to tablespaces. Tablespaces are like folders that contain segments (table, index, rollback, temporary). Any object you create, such as a table, must be assigned to some existing tablespace. To Create, Alter, or Drop a tablespace, you must access an account (such as System) that has these permissions. The following statement creates a tablespace named DATA and attaches a single data file to it. The data file data_01.dbf is created in the path specified. The data file has a size of 2 Megabytes. Reuse means that Oracle will “reuse” a file that has been detached from the database if its size is exactly 2 Megabyes. Any segment created in this tablespace will be assigned the storage parameters indicted unless they are changed when the object is created. Table 1 describes the default storage parameters.
SQL> 2 3 4 5 6 Create Tablespace Data Datafile '/oraclec/data/DB08/disk1/data_01.dbf' Size 2M Reuse Default Storage ( Initial 32K Next 32K Minextents 2 Maxextents 121 PctIncrease 0);
Table 1 Default Storage Parameters
The first extent created will be of this size. It should be defined as a multiple of the db_block_size. All segments must contain at least this one extent. The second extent created will be of this size. The number of extents created when the segment is first created. For example, if this value is set to 2, an extent of the size specified in Initial plus an extent of the size specified in Next is created when the segment is created. The maximum number of extents that can be assigned to the segment. If all extents fill with data and this parameter is reached, a “cannot extend” error will be returned. If no value is specified, the default value of 121 will be enforced. If you try to provide a value greater than 121 for this parameter, it will default back to 121. Percent Increase allows your segment to grow at an increasing rate. The first two extents will be of a size determined by the Initial and Next parameters. The third extent will be 1 + PCTINCREASE/100 times the second extent. The fourth extent will be 1 + PCTINCREASE/100 times the third extent, etc. PctIncrease can be set at any integer between 0 and 100. If not specified, the default value will be 50.
Chapter 6 Tablespaces and Users
Table 2 illustrates the growth of a segment with various PctIncrease settings. Extent size means the size of each individual extent. Segment size is the total size of the segment (the sum of all the extents). The table assumes that both the Initial and Next parameters are 32K. Setting PctIncrease to zero will produce uniform extent sizes for all extents except possibly the initial extent. However, if PctIncrease is set to zero, SMON will not automatically coalesce free space. Setting the PctIncrease to any positive value in the default storage parameters of the tablespace will direct SMON to coalesce free space.
Table 2 Table Growth And PctIncrease
PctIncrease = 25
Extents First Second Third Fourth Fifth Extent Size 32K 32K 40K 50K 62.5K Segment Size 32K 64K 104K 154K 216.5K
PctIncrease = 50
Extent Size 32K 32K 48K 72K 108K Segment Size 32K 64K 112K 184K 292K
PctIncrease = 75
Extent Size 32K 32K 56K 98K 171.5K Segment Size 32K 64K 120K 218K 389.5K
Another tablespace, called INDEXES, is created below. The INDEXES tablespace is defined with two data files. Since indexes should be located on a different disk from the data, if possible, the data files for INDEXES are located on disks 3 and 4. When multiple files are defined in the Create Tablespace command, the Datafile keyword is used only once. The names of the data files are separated by commas as shown.
SQL> 2 3 4 5 Create Tablespace INDEXES Datafile '/oraclec/data/DB08/disk3/indexes_01.dbf' Size 2M Reuse, '/oraclec/data/DB08/disk4/indexes_02.dbf' Size 2M Reuse Default Storage ( Initial 32K Next 32K Minextents 2 Maxextents 121 PctIncrease 0);
You can view information concerning your tablespaces through the DBA_Tablespaces view. A description of the columns in this view not described above is shown in the table below followed by the information returned when all data are retrieved through the view. Column Name
This is the minimum extent size that may be created by any segment in the tablespace. This can be AVAILABLE or OFFLINE. There will be several situations when a tablespace would be taken offline. Note that when the tablespace is created, it is immediately brought online and is available for use.
Chapter 6 Tablespaces and Users
This can be PERMANENT or TEMPORARY. Use Temporary if the tablespace is to be used by Oracle for sorts. You can’t create objects in a temporary tablespace. LOGGING indicates that activity on the segments in this tablespace are recorded in the REDO log. NOLOGGING indicates activity is not recorded.
SQL> select * from dba_tablespaces;
TABLESPACE INITIAL NEXT MIN MAX PCT NAME EXTENT EXTENT EXTENTS EXTENTS INCREASE ---------- ------- -------- ------- ------- -------SYSTEM 10240 10240 1 121 50 RBS 131072 131072 2 50 0 TEMP 512000 512000 1 121 0 TOOLS 10240 10240 1 121 50 USERS 10240 10240 1 121 50 DATA 32768 32768 2 121 0 INDEXES 32768 32768 2 121 0 MIN EXTLEN -----0 0 0 0 0 0 0 STATUS --------ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE ONLINE CONTENTS --------PERMANENT PERMANENT PERMANENT PERMANENT PERMANENT PERMANENT PERMANENT LOGGING ------LOGGING LOGGING LOGGING LOGGING LOGGING LOGGING LOGGING
The rows highlighted in the results above show the DATA and INDEXES tablespaces that were just created. The Minextents, Maxextents, and PctIncrease parameters reflect those values identified in the DEFAULT STORAGE clause of the CREATE TABLESPACE statement. The INITIAL and NEXT parameters are doubled since the minextents was set to 2. The following view provides information on the data files that Oracle owns. These data files are associated with tablespaces and were created when the tablespace was created or altered. The result of the query below indicates the full name and path of each data file and the tablespace that owns it. The size of each data file in both bytes and blocks is provided along with the current status of the data file. The data files that were created earlier in this chapter are highlighted.
SQL> select file_name, tablespace_name, bytes, blocks, status 2 from dba_data_files 3 order by tablespace_name;
FILE_NAME -------------------------------------/oraclec/data/DB08/disk1/data_01.dbf /oraclec/data/DB08/disk3/indexes_01.dbf /oraclec/data/DB08/disk4/indexes_02.dbf /oraclec/data/DB08/disk1/indx01.dbf /oraclec/data/DB08/disk1/rbs01.dbf /oraclec/data/DB08/disk1/system01.dbf /oraclec/data/DB08/disk1/temp01.dbf /oraclec/data/DB08/disk1/tools01.dbf /oraclec/data/DB08/disk1/users01.dbf 9 rows selected. TABLESPACE_NAME BYTES BLOCKS STATUS --------------- --------- ------ --------DATA 2097152 256 AVAILABLE INDEXES 2097152 256 AVAILABLE INDEXES 2097152 256 AVAILABLE INDX 5242880 640 AVAILABLE RBS 20971520 2560 AVAILABLE SYSTEM 104857600 12800 AVAILABLE TEMP 10485760 1280 AVAILABLE TOOLS 8388608 1024 AVAILABLE USERS 5242880 640 AVAILABLE
Locally Managed Tablespaces When you create a tablespace as shown in the section above, the tablespace is dictionary-managed. All information concerning the structure and parameters of the
two extents will be acquired.Chapter 6 Tablespaces and Users Page 4 tablespace is stored in the data dictionary. Tablespace created. The statement below creates a locally managed tablespace named DATA2 and associates one file with the tablespace. In a locally managed tablespace.dbf' Size 4M Reuse 3 Extent Management Local Uniform Size 32K. especially when the tablespace contains a large number of extents and has a high level of activity. SQL> Create Tablespace DATA2 2 Datafile '/oraclec/data/DB08/disk1/data2_01. All extents will be sized at 32K. a bitmap index is created in the headers of the data files associated with the tablespace. In the example below with a 32K uniform size. if you are creating a table and enter a value of 40K for Initial. There is no need to coalesce the tablespace because the bitmap index handles the management of space. no Redo Log or Rollback information is generated for changes to the tablespace. Storage parameters such as Next. TABLESPACE_NAME -----------------------------SYSTEM TOOLS RBS EXTENT_MAN ---------DICTIONARY DICTIONARY DICTIONARY ALLOCATIO --------USER USER USER . (Redo Log and Rollback information is still generated for changes to the data in the tablespace). The extent size is determined at the time of tablespace creation and cannot be overwritten in the storage clause of the tables. Since the information on the locally managed tablespace is not stored in the data dictionary. Rollback information and Redo log information on this update are generated. and PctIncrease do not apply to any object residing in the tablespace. SQL> Select Tablespace_Name. Locally managed tablespaces are more efficient than data dictionary-managed tablespaces. Oracle uses the bitmap indexes to decide where to place the newly acquired extents. A value may be determined for Initial but it must be a multiple of the Uniform Size set for the tablespace. Oracle8i and later versions allow a tablespace to be locally managed. The data dictionary must be updated every time a segment acquires a new extent. locally managed tablespaces require uniform extent sizes. The information regarding the tablespace is not recorded in the data dictionary. Minextents. There is no default storage clause. Maxextents. 3 Allocation_Type 4 From DBA_Tablespaces. Each bit of the index is associated with a database block located in the file. The bit indicates if the block is used or free. the number of extents of the uniform size will be acquired to cover 40K. 2 Extent_Management. The query below shows that DATA2 is locally managed and that the extents are allocated in a uniform manner. For example. However.
don’t press enter in the middle of a file name or quoted string.Chapter 6 Tablespaces and Users Page 5 TEMP USERS INDX DATA INDEXES DATA2 9 rows selected. Bring the tablespace back online so its data can be accessed. Rename the data file in Oracle. Moving a data file is a four step process as outlined below. Take the tablespace offline so no one can access the data while the file is being moved. Tablespace altered.dbf' Size 2M Reuse. If you are using unix. SQL> Alter Tablespace DATA2 2 Add Datafile '/oraclec/data/DB08/disk2/data2_02. SQL> Alter Tablespace DATA 2 Add Datafile '/oraclec/data/DB08/disk1/data_02. The second example adds a 2 megabyte data file to the DATA2 tablespace and places it on disk 2. This may occur because you have more resources available to you or you believe placing the file in another location would lead to greater efficiency. Use the operating system command to move the file from one location to another. DICTIONARY DICTIONARY DICTIONARY DICTIONARY DICTIONARY LOCAL USER USER USER USER USER UNIFORM Modifying and Removing Tablespaces Use the Alter Tablespace command to add one or more data files to a tablespace.dbf' Size 4M Reuse. remember that file names are case sensitive. Also. Relocating a Data File Sometimes you may need to move a data file from one location to another. Figure 1 illustrates the commands required to move the data file added to the DATA tablespace earlier in this section to disk 2. Tablespace altered. . The first example below adds a 4 megabyte data file to the DATA tablespace and places it on disk 1.
the segments must eventually acquire new extents. When extensive activity occurs on the segments in the tablespace. if possible. Oracle next scans the disk looking for a best fit. a Cannot Extent error is generated. If the space isn’t available.Chapter 6 Tablespaces and Users Page 6 Figure 1 Moving a Tablespace’s Data File Detecting Fragmentation As data are added to segments. The Data Extents (DE) associated with the tables indicated are interrupted by segments of Free Space (FS). If Oracle doesn’t have enough contiguous space to acquire the extent. The contiguous space is acquired for the extent. The exp . fragmentation still exists after the tablespace is coalesced. the disk will become fragmented as shown in Figure 2. Figure 2 Fragmented Data File DE Emp FS DE Dept DE Emp FS FS FS DE Emp FS FS DE Dept Coalescing the tablespace will merge the contiguous segments of free space into a single segment of free space. As shown in Figure 3. Oracle places these extents at locations in the data file according to the following rules: Oracle first scans the disk and tries to find an exact fit. SMON coalesces the free space if the PctIncrease value in the tablespace’s default storage clause exceeds zero. Coalescing does not change the location of the actual data.
then the tablespace contains fragments of free space. 12.-----. Select * From DBA_Free_Space Order By Tablespace_Name. The Blocks column simply indicates the size of free space segments in database blocks instead of bytes. The following view from DBA_Free_Space shows the amount of free space that is available on each tablespace. Figure 3 Coalesced Data File DE Emp FS DE Dept DE Emp FS FS DE Emp DE Dept FS To examine the fragmentation on the tablespaces. TEMP one row.-----------DATA 7 46 1728512 211 7 DATA 7 18 98304 12 7 DATA 11 2 4186112 511 11 DATA2 12 13 1998848 244 12 DATA2 10 17 4063232 496 10 INDEXES 8 6 2056192 251 8 INDEXES 9 6 2056192 251 9 INDX 6 2 5234688 639 6 RBS 3 642 15720448 1919 3 RBS 3 450 1048576 128 3 SYSTEM 1 6979 47693824 5822 1 SYSTEM 1 6971 65536 8 1 TEMP 4 2 10477568 1279 4 TOOLS 2 18 32768 4 2 TOOLS 2 10 32768 4 2 TOOLS 2 22 8216576 1003 2 TOOLS 2 14 32768 4 2 TOOLS 2 6 32768 4 2 TOOLS 2 2 32768 4 2 USERS 5 2 5234688 639 5 20 rows selected. The sum of all of the fragments represents the total free space in the tablespace. and 511.-------. TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO ---------------.Chapter 6 Tablespaces and Users Page 7 and imp utility programs described in Chapter 10 may be used to reorganize the disk. The results provide the tablespace name along with the file identifier so one could join the tablespace (logical object) to its file(s) (physical objects). If a tablespace is listed more than once. DATA2 two rows. You can see that SYSTEM occurs in two rows. Extents of tables may be located contiguously and all segments of free space may be merged into a single large segment using exp and imp. and INDEXES two rows.---------.------. RBS two rows. . DATA three rows. use the dba_free_space view. The highlighted DATA tablespace has three fragments of free space of sizes (in blocks) 211.
TABLESPACE_NAME BYTESFREE -----------------------------. sum(bytes) as bytesfree 2 from dba_free_space 3 group by tablespace_name. SQL> select tablespace_name. Read Only Tablespaces To prevent data from being changed in any segment in a tablespace. tables in read only tablespaces cannot be updated and new rows cannot be added. SQL> Alter Tablespace DATA Coalesce. Tablespace altered. alter the tablespace to read only. . As shown in Figure 4. To remove the contiguous free space segments.Chapter 6 Tablespaces and Users Page 8 The results from the query below show the total amount of free space in each tablespace without regard to fragmentation.---------DATA 6012928 DATA2 6094848 INDEXES 4177920 INDX 5234688 RBS 16769024 TEMP 10477568 TOOLS 8380416 USERS 5234688 8 rows selected. coalesce the tablespace as shown in the example below.
To shrink a data file. Even though the file will no longer be recognized by the database. Tablespace altered. it may be dropped as shown below. the data file may be increased in size. its size may be modified with the alter database command. Database altered.dbf' Resize 8M. SQL> Alter Database DB08 2 Datafile '/oraclec/data/DB08/disk2/data_02. SQL> Alter Database DB08 2 Datafile '/oraclec/data/DB08/disk2/data2_02. and reload the objects. However. Removing Data Files and Tablespaces If a data file is no longer needed. it still exists. to shrink a data file. Database altered. SQL> Alter Tablespace DATA Read Write.Chapter 6 Tablespaces and Users Page 9 Figure 4 Read Only Tablespaces To allow modifications to data. Use the operating system command (rm in unix) to remove the file. use the following SQL command. the file must be empty. As long as disk space is available. you must temporality remove the objects from the file. The data file does not need to be empty to drop it. The command below illustrates resizing a data file. shrink the file.dbf' Offline Drop. Resizing a Data File Once a data file has been created. .
the foreign key constraints must be dropped as well with the command shown below. you must add the clause Including Contents as shown below. The TEMPORARY TABLESPACE must also exist and was likely created during initial database creation. The tablespace must exist or Oracle will generate an error. If existing tables in another tablespace reference the tables in the tablespace to be dropped. Neither the name nor the password are case sensitive. Managing Users A User account must be created for anyone who needs to access the database. Tablespace dropped. the user will be called Elaine. Elaine has a 5M quota on the DATA tablespace and an unlimited quota on the TEMP tablespace. In the example. Creating Users To create a user. The command below drops a hypothetical tablespace called Data3. . When users are created. However. In this case. SQL> Drop Tablespace Data3. Tablespace dropped. The User becomes a system object. Elaine will be able to log in as ELAINE/WELCOME or Elaine/Welcome or any other combination of upper and lower case letters. The files that have been detached should be removed with the operating system command. SQL> Drop Tablespace DATA3 Including Contents. they must be given an initial password. connect to the SYSTEM account and enter the CREATE USER command shown in Figure 5. The DEFAULT TABLESPACE is the tablespace where all of Elaines tables and indexes will be stored automatically if she doesn’t specify another tablespace. the files still exist. Normally users are assigned a default tablespace and given a quota on that tablespace. If the tablespace contains any objects. Elaine’s password will be welcome. Users may also be assigned a temporary tablespace. SQL> Drop Tablespace DATA3 Including Contents Cascade Constraints. The IDENTIFIED BY clause requires you to provide the user with a password. Remember that dropping the tablespace detaches the files from the database. Quotas may be provided on the tablespaces. The first line of the create user command requires you to define a name. Tablespace dropped.Chapter 6 Tablespaces and Users Page 10 A tablespace may be dropped with the Drop Tablespace command.
she can create tables. Figure 6 Granting Connect and Resource Roles . The roles are granted in Figure 6 and Elaine is connected. triggers. and many other objects. views.Chapter 6 Tablespaces and Users Page 11 Even though the Elaine user is created. indexes. Not only can Elaine access Oracle. procedures. she will not be allowed to access Oracle since she has no permissions on the database. Figure 5 Creating a User Granting the connect and resource roles to Elaine gives her a number of permissions on the database. We’ll examine these roles in detail in Chapter 9.
A 5M quota is placed on the tablespace DATA. Save this file. Exit from SQL and create a file in your home directory called newuser. Figure 7 Creating A User With Password Expire Creating Users Through a Script File An efficient method for creating users is to develop a script file in the operating system and access it from within SQL. Enter the command to grant connect and resource to a user again replacing the user’s name with &1. Note that the password he enters doesn’t display on the screen. PASSWORD EXPIRE will require George to change his password the first time he connects to Oracle as shown. The file should look something like the following: Create User &1 Identified By welcome Default Tablespace Data Quota 5M on Data Temporary Tablespace Temp Quota Unlimited on Temp.Chapter 6 Tablespaces and Users Page 12 In Figure 7. Resource to &1. Grant Connect. a user named George is created with a password of welcome and a default tablespace of DATA. In that file enter the commands to create a user replacing the user’s name with &1. Note that you must place a semicolon after the Quota Unlimited on Temp line and again after the Grant statement. Connect to Oracle as SYSTEM and enter the following: SQL> @newuser jerry .sql. The final line of the CREATE USER statement contains the clause PASSWORD EXPIRE.
A user. Elaine. Modifying and Removing Users It’s often necessary to change a password for a user account. and Kramer all have a password of welcome. Retrieving Information on Users You can view information on users through the dba_users view as shown below.sql but you don’t need to use the . you can create the Kramer user. created. temporary_tablespace.-----E066D214D5421CCC OPEN 092CA7BCF360A117 OPEN 666D4EF49E031243 OPEN 88F7D29BBCA21A5E OPEN 621FB93B53107919 OPEN 4A3BA55E08595C81 OPEN 42153BFAF4C2A023 OPEN D4C5016086B2DC6A OPEN D4DF7931AB130E37 OPEN F9DA8977092B7B81 OPEN PASSWORD DEFAULT TABLESPACE ---------SYSTEM DATA DATA DATA DATA SYSTEM DATA SYSTEM TOOLS SYSTEM TEMPORARY TABLESPACE ---------SYSTEM TEMP TEMP TEMP TEMP SYSTEM TEMP TEMP TEMP SYSTEM CREATED --------02-JAN-03 26-MAY-03 01-JUN-03 26-MAY-03 01-JUN-03 02-JAN-03 26-MAY-03 02-JAN-03 02-JAN-03 02-JAN-03 PROFILE ------DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT Note that the password is encrypted. A DBA may change the password for any user. We will discuss the Account Status. password. SQL> select 2 username.sql part when calling the file. You can always change your own password. profile 4 from dba_users order by username. Lock Date. expiry_date. and Profile later. By simply retyping the command above and changing the name from jerry to Kramer. Note that the file is called newuser. SQL> Alter User Superman Identified By loislane. User Altered. USERNAME USER ID -------. . The two statements shown below express quotas on the DATA2 and INDEXES tablespaces for Jerry and Elaine. lock_date. the encrypted passwords are different. Expiry Date.------.---DBSNMP 16 ELAINE 30 GEORGE 31 JERRY 27 KRAMER 32 OUTLN 11 SUPERMAN 26 SYS 0 SYSTEM 5 TRACESVR 19 ACCOUNT LOCK EXPIRY STATUS DATE DATE ----------------. The statement below illustrates changing a password to loislane. account_status. Use the Alter User command to change quotas or tablespaces or add quotas to tablespaces. A user may be granted privileges on the database to perform DBA functions. This user will be created by the script file from above and then be granted the DBA role in addition to the Connect and Resource roles. SQL> @newuser Superman SQL> Grant DBA To Superman. is created and given DBA privileges in the two statements below. user_id.---. named Superman. Even though Jerry.Chapter 6 Tablespaces and Users Page 13 Oracle will run your script file replacing &1 with jerry. 3 default_tablespace.
If you want to remove both the user Kramer and the objects he created. SQL> Alter User Kramer Account UnLock. enter the following SQL> Alter User Kramer Account Lock. SID SERIAL# USERNAME ---------. SQL> Alter User Elaine Quota 10M On DATA2 Quota Unlimited On INDEXES. The above command will drop the user Kramer but the objects he created in the database will remain. User dropped. If you want to remove a user. User altered. from the database. enter: SQL> Drop User Kramer Cascade. User altered. SQL> select 2 SID. .---------.-----------------8 54 SYSTEM 8 rows selected. User altered. User dropped. Monitoring User’s Sessions You can view the users currently connected to Oracle through the v$session view as shown below.Chapter 6 Tablespaces and Users Page 14 SQL> Alter User Jerry Quota 10M On DATA2 Quota Unlimited On INDEXES. Kramer will not be able to access Oracle through his account until you unlock it with the following statement. User altered. say Kramer. serial#. username 3 from v$session where username is not null. Locking User Accounts If you want to prevent Kramer from accessing his account but still leave his account intact. enter: SQL> Drop User Kramer.
it does NOT lock the user’s account. The general form of the Create Profile statement is shown below: CREATE PROFILE profile_name LIMIT parameter1 value parameter2 value…. If the user doesn’t enter something into SQL for this amount of time. Table 3 Profile Parameters Parameter Value Type Integer Description Sessions_Per_User Number of concurrent session the user is allowed. There is another set of parameters available that involve password management. Amount of time the user may be connected to the database during a 24 hour period. the resources that users can exhaust is limited. CPU_Per_Session Hundredths of a second Hundredths of a second Number of DB Blcoks Number of DB Blcoks Minutes CPU_Per_Call Amount of CPU time used per single SQL request. The password management parameters will be discussed with security issues in Chapter 9. If the user connects to other Oracle products such as Oracle * Forms. Number of blocks that can be read with a single SQL request. Limiting User Resources Profiles are objects that allow the DBA to set limits on various resources. this value should be set to at least 5. SQL> Alter System Kill Session (‘SID. By assigning profiles to users. Limits the size of the private memory that can be used for storing a user’s private SQL. it is assigned to a user as shown below: ALTER USER user_name PROFILE profile_name.Chapter 6 Tablespaces and Users Page 15 To force off a user. This command only terminates the session. After the profile is created. enter the following replacing the SID and serial# with values from above. Logical_Reads_Per_ Session Logical_Reads_Per_ Call Idle_Time Number of blocks that can be read during a session. Amount of CPU time used per session. A partial list of the parameters of a profile is shown in Table 3. the session will be terminated.serial#’). Connect_Time Minutes Private_SGA_ Per_Session Number of DB Blcoks .
SQL> Select * From DBA_Profiles 2 Where Resource_Type = 'KERNEL' 3 Order By 1. the number of sessions per user is limited to 10 in the USER_PROFILE. ALTER RESOURCE COST Connect_Time 10. and the number of blocks that can be read by a single SQL statement to 20. Composite_Limit can impose a limit on the total of the resources used. The PASSWORD Resource Type places restrictions on passwords and will be discussed in Chapter 9. The USER_PROFILE created and altered above limited the four parameters highlighted below. SQL> alter user jerry profile USER_PROFILE.Chapter 6 Tablespaces and Users Page 16 Composite_Limit Integer A composite of the parameters underlined. Provide a value for the Composite_Limit. the cpu that can be used in a session to ten seconds. The following example creates a profile named USER_PROFILE that sets idle time to ten minutes. If no profile is assigned to a user. Set a resource value for each parameter using ALTER RESOURCE COST. Each minute of connect time will generate a resource use of 10. SQL> Alter Profile USER_PROFILE Limit Sessions_Per_User 10. Set the resource limit for all other parameters. use the command below. The DEFAULT profile has values set to UNLIMITED. You can modify any profile with the Alter Profile command. the user will be assigned the Default Profile. The DBA_Profiles view shows the current values of the profiles’ parameters. Even though no individual resource limit is reached. To impose the limits established in the User_Profile on the Jerry account. Default will initially have all parameters set to unlimited. Profile altered. For Example. User altered. SQL> 2 3 4 Create Profile USER_PROFILE Limit Idle_Time 10 CPU_Per_Session 1000 Logical_Reads_Per_Call 20. You can alter the default profile but not drop it. The Resource Type described in this chapter is KERNEL. In the example below. PROFILE --------------DEFAULT DEFAULT DEFAULT DEFAULT RESOURCE_NAME --------------------------COMPOSITE_LIMIT SESSIONS_PER_USER CPU_PER_CALL LOGICAL_READS_PER_CALL RESOURCE -------KERNEL KERNEL KERNEL KERNEL LIMIT --------UNLIMITED UNLIMITED UNLIMITED UNLIMITED .
It places the table in the DATA tablespace created earlier in this chapter and changes the PctIncrease and Minextents parameters. the parameters defined for the tablespace will be used. If you don’t write a storage clause or don’t change some parameters. Note that you use the keyword STORAGE in line 8 since these are the actual storage values for the table and not default storage for segments in the tablespace. Minextents. 6 Hiredate Date Not Null) 7 Tablespace Data 8 Storage( 9 Minextents 1 PctIncrease 50). you can write storage parameters in the definition of the table that will replace the ones defined in the CREATE TABLESPACE statement for that table. Also. CONNECT_TIME PRIVATE_SGA IDLE_TIME LOGICAL_READS_PER_SESSION CPU_PER_SESSION COMPOSITE_LIMIT PRIVATE_SGA SESSIONS_PER_USER CPU_PER_CALL LOGICAL_READS_PER_CALL CONNECT_TIME IDLE_TIME LOGICAL_READS_PER_SESSION CPU_PER_SESSION KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL KERNEL UNLIMITED UNLIMITED UNLIMITED UNLIMITED UNLIMITED DEFAULT DEFAULT 10 DEFAULT 20 DEFAULT 10 DEFAULT 1000 Managing Segments If you have been granted permission on the tablespace. .Chapter 6 Tablespaces and Users Page 17 DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE USER_PROFILE 18 rows selected. The DEPARTMENT table will be created with two extents each of size 32K. we know the Initial and Next are both 32K and the maxextents is 121 as defined in the CREATE TABLESPACE statement. Table created. Jerry creates the DEPARTMENT table in the DATA2 tablespace changing the size of the Initial storage parameter. The user Jerry issues the following CREATE TABLE statement. Since DATA2 is a locally managed tablespace. 5 Dept Char(3). SQL> Create Table Emp 2 (ID Number(3) Primary Key. In the example below. 4 Salary Number(6) Not Null. In the above example. Maxextents. 3 Name Varchar2(20) Not Null. and PctIncrease parameter values are not used. the Next . you can create a table and assign it to that tablespace.
Each block also stores some information required by the database to associate the block with a table and store pointers to the rows contained in the block. new data are not immediately inserted into the block to replace the deleted data. The segments’ data are stored in the blocks. Figure 8 illustrates space usage within a single data block. New rows inserted into the table may now be placed in the block until the block fills as it did originally. The block is initially filled until it’s eight-five percent full (100 – (PctFree + Overhead)). there are (2M/8K) = 250 blocks available. Data are deleted from the block. When the level of data in the block falls to forty percent. Index created. Although the amount of space used by overhead may vary. That leaves 249 blocks available to store user data. One block is used by the database to store an index to the other blocks. Managing Space Usage The database block size is determined when the database is initially created and cannot be changed. The space used by the database is identified as overhead in Figure 8. PctFree and PctUsed. The database block size is known to be 8k (use show parameter db_block_size from the SYSTEM account to find this parameter’s value). When enough data have been deleted from the block so that the PctUsed threshold has been reached. it is generally considered to be about five percent of the available space in the block. the block’s id is placed on the freelist. the amount of used space in the block decreases. Values for two parameters may be set to determine how the space is used. PctUsed is the percentage of the space in a block that forms a lower threshold necessary for adding data to the block. DeptName Varchar2(40)) Tablespace DATA2 Storage( Initial 48K). When data are deleted. The example below shows the creation of an index on EMP’s Dept column. The index is located in the INDEXES tablespace. However. Table created. suppose the PctFree is ten percent and the Pctused is forty percent (the defaults). PctFree is the percent of the space in the block that will be left unused when the data for rows are placed in the block. The freelist is a list of block ids indicating the blocks that are available to accept data. the block will be placed on the freelist. .Chapter 6 Tablespaces and Users Page 18 SQL> 2 3 4 5 6 Create Table DEPARTMENT (Dept Char(3) Primary Key. As an example. Since the file owned by the DATA tablespace is 2M. SQL> Create Index EMP_DEPT_IDX On EMP(Dept) Tablespace INDEXES. The data from Chapter 2 are loaded into the EMP and DEPARTMENT tables through a script file.
Some data types. the entire row is moved to another block. the data must be stored somewhere in the block. If the table contains data that change frequently and data values usually increase. Normally the PctFree should not be set to a value greater than twenty-five percent. The data will be stored in available free space in the block referenced by a pointer in the data’s original location. The CUSTOMER table is created in the example below on Elaine’s account.Chapter 6 Tablespaces and Users Page 19 Figure 8 Space Usage in a Data Block It is necessary to leave unused space in a data block to store additional data added to the rows that exist in the block. . If a null value is later changed to a real value or the length of an existing data value is increased. Moving an entire row from one block to another because there is not enough free space to handle updates is called migration. If the table contains data that are occasionally updated. If there is not enough free space available in the block. The shaded line illustrates how to set the PctFree and PctUsed values. Note that they are not part of the Storage clause. leave the PctFree at ten percent. Setting the PctFree too high is also inefficient since the space is never used. set the PctFree to a relatively high value. The value of PctIncrease is changed to twenty-five percent and the table is located in the DATA tablespace. Because migration reduces database performance. there should be enough free space in the block to handle updates. set the PctFree to a low value such as five percent. such as Varchar2. If tables contain static data. store data in a variable length format.
Analyzing Tables You can use the Analyze Table command to compute various statistics for a table. The values of the statistics are recorded and do not change until another Analyze Table statement is run against the table. the statistics can be viewed. To save time. . However. Index created. After Elaine analyzes the table. You can choose the size of the sample used to Estimate Statistics by specifying the number of rows or the percent of rows to be used in the sample. You can use these statistics to monitor space usage of the table. SQL> Create Index CUST_REGION_IDX On CUSTOMER(Region) Tablespace INDEXES. ID Number(3)) Tablespace DATA Storage( PctIncrease 25) PctFree 15 PctUsed 50. all of the rows in the table are analyzed. The example below creates and index on the CUSTOMER’s Region column placing it in the INDEXES tablespace. you can Estimate the statistics based upon a random sample of rows selected by Oracle. the statistics are stored in that table and can be viewed through the USER_Tables or DBA_Tables views. Figure 9 below shows that initially no statistics exist in Elaine’s CUSTOMER table. The Customer table is loaded with the data from Chapter 2 through a script file. All tables can be analyzed. Primary Key. However. the cost-based optimizer described in Chapter 8 uses these statistics to calculate the resource cost of queries. Analyze Table tablename < Compute|Estimate > Statistics < Sample n < Percent|Rows > > If you Compute the statistics. Also. Not Null. This can be time consuming for tables containing a large number of rows. all of the rows in the table will be analyzed. if you specify a sample size that will cause more than fifty percent of the rows to be included in the sample. The general form of the Analyze Table command is shown below. Table created.Chapter 6 Tablespaces and Users Page 20 SQL> 2 3 4 5 6 7 8 9 Create Table CUSTOMER (CID Char(2) CName Varchar2(20) Region Char(1). The statistics are not updated dynamically. you should not analyze any of the tables owned by SYS. Once you analyze the table.
The DEPARTMENT table is analyzed using the default sample size and the EMP table is analyzed using forty percent of the rows. Figure 10 Estimating Statistics Additional statistics on the individual columns can be found in the view shown in Figure 11.Chapter 6 Tablespaces and Users Page 21 Figure 9 Computing Statistics In Figure10. . the DEPARTMENT and EMP tables are analyzed from Jerry’s account using Estimate Statistics.
Table analyzed.'SYSTEM'). 3 next_extent. InitTrans and MaxTrans. You can validate the structure of the table and its associated objects such as indexes with the following command. The results of the query below show the tables in the database not owned by SYS or SYSTEM. Two new parameters are also included. The highlighted rows indicate the tables created above. respectively. The value from MaxTrans represents the maximum number of users who can concurrently access the table’s data. Normally the structure of a block is validated when the block is read into the database buffer cache. The value for InitTrans represents the space reserved to log one user who is accessing the table’s data. pct_increase 4 from dba_tables 5 where owner not in ('SYS'. pct_free. The command below validates the structure of the EMP table. SQL> select owner. table_name.Chapter 6 Tablespaces and Users Page 22 Figure 11 Viewing Statistics on Columns The Analyze Table command can also be used to validate the structure of the blocks that contain the table’s data. min_extents. Table analyzed. . 2 pct_used. SQL> Analyze Table EMP Validate Structure. and are rarely changed. The default values for InitTrans and MaxTrans are 1 and 255. initial_extent. tablespace_name. max_extents. ini_trans. SQL> Analyze Table DEPARTMENT Validate Structure Cascade. max_trans. Retrieving Information on Tables The DBA_Tables view describes the storage parameters for each table in addition to the tablespace where the table resides and the owner of the table.
----. The Max_Bytes column indicates the quota that user has on the tablespace. SQL> Select * From DBA_TS_Quotas Order By Username.---------ELAINE 131072 5242880 16 640 ELAINE 65536 -1 8 -1 ELAINE 0 10485760 0 1280 ELAINE 0 -1 0 -1 GEORGE 0 5242880 0 640 GEORGE 0 -1 0 -1 JERRY 65536 -1 8 -1 JERRY 98304 5242880 12 640 JERRY 98304 10485760 12 1280 JERRY 0 -1 0 -1 KRAMER 0 5242880 0 640 SUPERMAN 0 -1 0 -1 SUPERMAN 0 5242880 0 640 13 rows selected. In the first row. The total number of bytes used is computed for each tablespace. The query below presents the data from the DBA_TS_Quotas in another way. Elaine has used 131. For example. divide the number of bytes by 8K to compute the last two columns of the results. The first row of the results below shows that objects residing in the DATA tablespace have used 229. The last two columns convert the bytes used and quota in bytes to database blocks. The first two columns identify a unique tablespace. Viewing Information on User Quotas The DBA_TS_Quotas view displays the allocation that each user has on each tablespace.Chapter 6 Tablespaces and Users Page 23 OWNER ------OUTLN OUTLN JERRY JERRY ELAINE TABLE NAME ----------OL$ OL$HINTS EMP DEPARTMENT CUSTOMER TABLESPACE PCT PCT INI MAX INITIAL NEXT MIN MAX PCT NAME FREE USED TRANS TRANS EXTENT EXTENT EXTENTS EXTENTS INCREASE ---------.----.880 byte (5M) quota on the DATA tablespace. TABLESPACE_NAME --------------DATA INDEXES DATA2 TEMP DATA TEMP INDEXES DATA DATA2 TEMP DATA TEMP DATA USERNAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS -------. The results of selecting all of the data from this view are shown below.-----. the first four rows identify Elaine’s allocation on the four tablespaces she can access.---.-------. user combination.------.376 bytes.------.---------. The second row of the results shows that Elaine’s quota on the INDEXES tablespace is unlimited. With a db_block_size of 8K.-------SYSTEM 10 40 1 255 16384 16384 1 505 50 SYSTEM 10 40 1 255 16384 16384 1 505 50 DATA 10 40 1 255 32768 32768 1 121 50 DATA2 10 40 1 255 49152 32768 1 2147483645 0 DATA 15 50 1 255 32768 40960 2 121 25 5 rows selected.------.072 bytes of her 5. The Bytes column indicates the number of bytes the user’s objects occupy in the tablespace.------.---. . The –1 under Max_Bytes means the quota is unlimited.242.
23 percent of the space in the DATA tablespace is being used. only 2. BYTESUSED BLOCKSUSED ---------.Bytes)+SUM(b.1372549 0 Data Dictionary Space Usage Views DBA_Segments View The results of the query below provide specific information on the segments.Bytes) As BytesUsed. SUM(Bytes) As Bytesused SUM(Blocks) As Blocksused DBA_TS_Quotas Tablespace_Name. .2257552 1. SUM(a. SQL> 2 3 4 5 6 7 8 Select a. From the results of the query below. The Elaine’s CUSTOMER table currently has two extents attached to it and it is allowed to grow to 121 extents.Tablespace_Name.Bytes)/(SUM(a.----------229376 28 98304 12 131072 16 0 0 TABLESPACE_NAME --------------DATA DATA2 INDEXES TEMP 4 rows selected.5957447 3.Tablespace_Name.Tablespace_Name a. SUM(b. DBA_TS_Quotas b a. The first row of the results shows that Elaine has created a Table named CUSTOMER in the DATA tablespace. The query below joins DBA_Free_Space and DBA_TS_Quotas to calculate the percent of available space used in each tablespace. Monitoring Space Usage Recalling that the DBA_Free_Space view described earlier in this Chapter provides information on the free space available in each tablespace.Bytes) As BytesFree.---------DATA 30228480 688128 DATA2 12124160 196608 INDEXES 8093696 262144 TEMP 41910272 0 Percent Used -----------2.Bytes)) * 100 "Percent Used" DBA_Free_Space a.Tablespace_Name = b. The segments residing on the SYSTEM and TOOLS tablespaces have been filtered out of the results for readability and because we are not interested in the SYSTEM segments at this point. As From Where Group By TABLESPACE_NAME BYTESFREE BYTESUSED -----------------------. we can combine DBA_TS_Quotas with DBA_Free_Space for some useful analysis. SUM(b.Chapter 6 Tablespaces and Users Page 24 SQL> Select 2 3 4 From 5 Group By Tablespace_Name.---------.
but adds some additional elements.’TOOLS’) Order By Owner. The query below shows each tablespace and the bytes the segments occupy. Sum(Bytes) As Bytes 2 From DBA_Segments 3 Group By Owner. Max_Extents From DBA_Segments Where Tablespace_Name NOT IN ('SYSTEM'. this view can provide us with that information. SQL> select tablespace_name. count(*) as segments. SQL> Select Owner. . The following view from DBA_Segments provides some of the same information as the previous view concerning space usage. sum(bytes) as bytes 2 from dba_segments 3 group by tablespace_name. SQL> Select 1 2 3 Owner. TABLESPACE_NAME SEGMENTS BYTES -----------------------------. SEGMENT_TYPE ------------TABLE INDEX INDEX TABLE TABLE INDEX INDEX INDEX ROLLBACK TABLESPACE_NAME --------------DATA DATA INDEXES DATA DATA2 DATA INDEXES DATA2 RBS SEGMENT_NAME EXTENTS MAX_EXTENTS ------------. If we need to know information regarding both Tables and Indexes.----------CUSTOMER 2 121 SYS_C001043 2 121 CUST_REGION_IDX 2 121 EMP 1 121 DEPARTMENT 2 2147483645 SYS_C001033 2 121 EMP_DEPT_IDX 2 121 SYS_C001034 1 2147483645 RBS0 8 4096 OWNER ------ELAINE ELAINE ELAINE JERRY JERRY JERRY JERRY JERRY SYS 9 rows selected. The RBS tablespace contains only one segment for the nonsystem rollback segment. Tablespace_Name. Segment_Type.---------. Segment_Name.---------DATA 4 262144 DATA2 2 65536 INDEXES 2 131072 RBS 1 4194304 SYSTEM 445 57090048 6 rows selected. The first row of the results below indicates that the DATA tablespace contains four segments. The follow view of DBA_Segments shows the number of segments owned by each user along with the number of bytes the segments use. Count(*) As Segments. Extents. The SYSTEM tablespace contains the 445 segments that make up the data dictionary. however it also provides information on the segments stored in each tablespace.Chapter 6 Tablespaces and Users Page 25 The DBA_Segments view is one of the most useful data dictionary views because it provides access to all of the segments on the database.------.
DBA_Extents View The DBA_Extents view contains information on each of the extents within a segment. Extent_Id. The DEPARTMENT table was created in the DATA2 tablespace using locally managed extents of a uniform 32K extent size.---------CACHE 1 8192 CLUSTER 9 2940928 INDEX 239 19488768 LOBINDEX 13 655360 LOBSEGMENT 13 688128 ROLLBACK 2 5029888 TABLE 177 32931840 7 rows selected. Tablespace_Name.------DATA 0 32768 4 DATA 1 32768 4 INDEXES 0 32768 4 INDEXES 1 32768 4 DATA 1 32768 4 DATA 0 32768 4 OWNER -------ELAINE ELAINE ELAINE ELAINE ELAINE ELAINE SEGMENT_NAME --------------CUSTOMER CUSTOMER CUST_REGION_IDX CUST_REGION_IDX SYS_C001043 SYS_C001043 . two uniform extents must be allocated.---------. Bytes DBA_Extents Where Tablespace_Name != ‘SYSTEM’ Owner. SEGMENT_TYPE SEGMENTS BYTES -----------------.---------ELAINE 3 196608 JERRY 5 262144 OUTLN 5 81920 SYS 389 57794560 SYSTEM 52 3407872 The final view from DBA_Segments shows the number of segments by type of segment and the bytes used by each type. Segment_Type. Sum(Bytes) As Bytes 2 From DBA_Segments 3 Group By Segment_Type. SQL> Select 2 3 From 4 Order By Owner. SEGMENT_ TYPE --------TABLE TABLE INDEX INDEX INDEX INDEX TABLESPACE EXTENT _NAME _ID BYTES BLOCKS ---------. SQL> Select Segment_Type.------. Segment_Name. To satisfy the Initial extent requirement. the uniform extent size cannot be changed by changing the storage parameters.---------. Count(*) As Segments. Segment_Name. The example below shows the size of each extent in a segment in both bytes and blocks. The highlighted rows depict the extents used by Jerry’s DEPARTMENT table.------.Chapter 6 Tablespaces and Users Page 26 OWNER SEGMENTS BYTES -----------------------------. DEPARTMENT was created with an Initial storage parameter of 48K. When using locally managed extents.
dbf /oraclec/data/DB08/disk1/data_01.dbf /oraclec/data/DB08/disk1/rbs01.--------------------------------------ELAINE ELAINE ELAINE ELAINE ELAINE ELAINE JERRY JERRY JERRY JERRY JERRY JERRY JERRY JERRY SYS SYS SYS SYS SYS SYS SYS SYS CUSTOMER CUSTOMER SYS_C001043 SYS_C001043 CUST_REGION_IDX CUST_REGION_IDX EMP DEPARTMENT DEPARTMENT EMP_DEPT_IDX EMP_DEPT_IDX SYS_C001054 SYS_C001054 SYS_C001055 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 2 3 4 5 6 7 TABLE TABLE INDEX INDEX INDEX INDEX TABLE TABLE TABLE INDEX INDEX INDEX INDEX INDEX ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK /oraclec/data/DB08/disk1/data_01. The highlighted rows in the results below show that the CUSTOMER and DEPARTMENT tables have each acquired two extents and the file where each extent is located.dbf /oraclec/data/DB08/disk4/indexes_02.dbf /oraclec/data/DB08/disk1/rbs01.Chapter 6 Tablespaces and Users Page 27 JERRY JERRY JERRY JERRY JERRY JERRY JERRY JERRY SYS SYS SYS SYS SYS SYS SYS SYS EMP SYS_C001054 DEPARTMENT DEPARTMENT EMP_DEPT_IDX EMP_DEPT_IDX SYS_C001055 SYS_C001054 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 RBS0 TABLE INDEX TABLE TABLE INDEX INDEX INDEX INDEX ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK ROLLBACK DATA DATA DATA2 DATA2 INDEXES INDEXES DATA2 DATA RBS RBS RBS RBS RBS RBS RBS RBS 0 1 0 1 0 1 0 0 0 1 2 3 4 5 6 7 32768 32768 32768 32768 32768 32768 32768 32768 524288 524288 524288 524288 524288 524288 524288 524288 4 4 4 4 4 4 4 4 64 64 64 64 64 64 64 64 22 rows selected.dbf /oraclec/data/DB08/disk1/rbs01.dbf /oraclec/data/DB08/disk1/data_01.dbf /oraclec/data/DB08/disk1/rbs01.File_ID a.dbf /oraclec/data/DB08/disk1/data_01.File_ID = b. Extent_ID.dbf /oraclec/data/DB08/disk1/data_02. Segment_Type.dbf /oraclec/data/DB08/disk1/data_01.dbf /oraclec/data/DB08/disk2/data2_02. Segment_Name.Tablespace_Name != 'SYSTEM' Owner.--------. DBA_Data_Files b a. The example below illustrates joining DBA_Extents with DBA_Data_Files to identify the file where each extent is stored.-----. EXTENT SEGMENT OWNER SEGMENT_NAME _ID _TYPE FILE_NAME --------.dbf /oraclec/data/DB08/disk1/rbs01.dbf /oraclec/data/DB08/disk1/rbs01.File_Name DBA_Extents a. .dbf 22 rows selected.dbf /oraclec/data/DB08/disk1/data_01.dbf /oraclec/data/DB08/disk1/data2_01. SQL> 2 3 4 5 Select From Where And Order By Owner.dbf /oraclec/data/DB08/disk4/indexes_02.dbf /oraclec/data/DB08/disk1/rbs01.dbf /oraclec/data/DB08/disk3/indexes_01.--------------.dbf /oraclec/data/DB08/disk1/rbs01.dbf /oraclec/data/DB08/disk3/indexes_01. Segment_Type.dbf /oraclec/data/DB08/disk1/data2_01.
The owner. Using Alter Table to add columns or modify existing columns was discussed in Chapter 2. The following query against the DBA_Objects view returns information on the objects that users have created. SQL> Select Owner.'DBSNMP') OWNER ------JERRY JERRY JERRY JERRY JERRY JERRY JERRY ELAINE ELAINE ELAINE OBJECT_NAME ---------------DEPARTMENT EMP EMP_DEPT_IDX EMP_DEPT_SAL EMP_SALARY SYS_C00996 SYS_C00997 CUSTOMER CUST_REGION_IDX SYS_C001001 OBJECT_TYPE ----------TABLE TABLE INDEX VIEW VIEW INDEX INDEX TABLE INDEX INDEX CREATED ---------06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 01-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 LAST DDL_TIME ------------06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 01-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 06-JUN-03 Modifying and Removing Tables The Alter Table command is used to modify the structure of the table. In addition to segments. Last_DDL_Time 2 From DBA_Objects 3 Where Owner Not In ('SYS'. . name and type of object are displayed along with the date on which the object was created. SQL> 2 3 4 5 6 7 Create View EMP_DEPT_SAL As Select Dept. The view below shows the tables and indexes that were displayed in the prior views in this section.Chapter 6 Tablespaces and Users Page 28 DBA_Objects View The DBA_Objects view retrieves information on all objects in the database.'SYSTEM'. The Last_DDL_Time is the date the last DDL statement was issued against the object. View created. information on objects such as Views and Database Links are retrieved. Created. The highlighted rows show the SQL view that was created above as well as an SQL view that was created in Chapter 2. SUM(SALARY) As TotalSal. Object_Type. The Alter Table command may also be used to add or modify integrity constraints as explained in Chapter 9. Object_Name. COUNT(*) As NDepts.'PUBLIC'. Before examining the results from DBA_Objects.'OUTLN'. AVG(SALARY) As AvgSal From EMP Group By Dept. Jerry creates a View on his EMP table as shown below.
The sizes of existing extents are not modified because of the new values. The new values apply prospectively. Table altered.Chapter 6 Tablespaces and Users Page 29 Modifying Storage Parameters You can change the storage parameters of a table as well as the PctFree and PctUsed. You can allocate an extent to a table specifying the size of the extent and the data file in which the file should be located. Table altered. they must be deallocated using the statement shown below. Table altered. SQL> Alter Table EMP Deallocate Unused. SQL> Alter Table EMP 2 Storage (Next 16K PctIncrease 40) 3 PctUsed 60. the extents are not automatically deallocated from the table. If you anticipate that data may be added to a table in the future. Once extents have been allocated. SQL> Alter Table EMP Deallocate Unused Keep 24K. . The extent will be sized according to the rules described earlier in this chapter for a new extent. The example below shows an extent being added to the CUSTOMER table. Deallocating Unused Extents If many rows are deleted from a table that has acquired several extents. The following example changes the Next and PctIncrease parameters for the EMP table as well as increasing the PctUsed to sixty percent. In the example below. SQL> Alter Table CUSTOMER Allocate Extent.dbf file. an extent is added to the EMP table with a size of 16K and is placed in the data_02. Table altered. Allocating New Extents You can explicitly allocate an extent to a table. you may deallocate extents but require that the table be no smaller that a specified size. The statement below will deallocate unneeded extents but leave the size of the table at least 24K.
Chapter 6 Tablespaces and Users Page 30 SQL> Alter Table EMP 2 Allocate Extent 3 (Size 16K Datafile '/oraclec/data/DB08/disk2/data_02. The following command run from the SYSTEM account will remove Elaine’s CUSTOMER table. Table altered. SQL> Drop Table EMP. you can drop the table and remove the constraint from the referencing table. If you have DBA privileges. Drop Table EMP * ERROR at line 1: ORA-02449: unique/primary keys in table referenced by foreign keys By using the cascade constraints clause. Table dropped.dbf'). Table dropped.CUSTOMER. . The Drop Table command cannot be rolled back so be sure you want to remove the table before issuing the command. SQL> Drop Table Elaine. you can drop a table of another user. you will receive the error shown below when you try to drop the table. Removing Tables Use the Drop Table command to remove the structure of a table and all of its data from the database. SQL> Drop Table EMP Cascade Constraints. Table dropped. The EMP table is dropped from Jerry’s account in the example below. If EMP is referenced as a foreign key in another table. SQL> Drop Table EMP.