Search This Blog

Showing posts with label Tablespaces. Show all posts
Showing posts with label Tablespaces. Show all posts

Thursday, October 25, 2007

ORA-02449


ORA-02449: unique/primary keys in table referenced by foreign keys


SQL> drop tablespace users including contents and datafiles ;
drop tablespace users including contents and datafiles
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys


Whenever get ORA-02449 error during drop tablespace then just use CASCADE CONSTRAINTS cluase with DROP TABLESPACE statement.



SQL> drop tablespace users including contents and datafiles cascade constraints;


Tablespace dropped.

Saturday, September 8, 2007

Renaming Tablespaces


Renaming Tablespaces



Using the RENAME TO clause of the ALTER TABLESPACE, you can rename a permanent or temporary tablespace.


SQL> alter tablespace users RENAME TO userts;

Tablespace altered.


When you rename a tablespace the database updates all references to the tablespace name in the data dictionary, control file, and (online) datafile headers. The database does not change the tablespace ID so if this tablespace were, for example, the default tablespace for a user, then the renamed tablespace would show as the default tablespace for the user in the DBA_USERS view.



The following affect the operation of this statement:

The COMPATIBLE parameter must be set to 10.0 or higher.

If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace, then it will not be renamed and an error is raised.


SQL> alter tablespace system RENAME TO system1;
alter tablespace system RENAME TO system1
*
ERROR at line 1:
ORA-00712: cannot rename system tablespace


SQL> alter tablespace sysaux RENAME TO system1;
alter tablespace sysaux RENAME TO system1
*
ERROR at line 1:
ORA-13502: Cannot rename SYSAUX tablespace


If any datafile in the tablespace is offline, or if the tablespace is offline, then the tablespace is not renamed and an error is raised.


SQL> alter tablespace userts RENAME TO users;
alter tablespace userts RENAME TO users
*
ERROR at line 1:
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: 'C:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\USERS01.DBF'


If the tablespace is read only, then datafile headers are not updated. This should not be regarded as corruption; instead, it causes a message to be written to the alert log indicating that datafile headers have not been renamed. The data dictionary and control file are updated.


SQL> alter tablespace userts read only;

Tablespace altered.

SQL> alter tablespace userts RENAME TO users;

Tablespace altered.
alert_orcl.log
Sat Sep 08 19:52:42 2007
alter tablespace userts RENAME TO users
Tablespace 'USERTS' is renamed to 'USERS'.
Tablespace name change is not propagated to file headers because the tablespace is read only.

If the tablespace is the default temporary tablespace, then the corresponding entry in the database properties table is updated and the DATABASE_PROPERTIES view shows the new name.

SQL> select property_value
2 from database_properties
3 where property_name like '%TEMP%';

PROPERTY_VALUE
------------------------------------------------

TEMP2

SQL> alter tablespace temp2 rename to temp;

Tablespace altered.

SQL> select property_value
2 from database_properties
3 where property_name like '%TEMP%';

PROPERTY_VALUE
------------------------------------------------

TEMP


If a traditional initialization parameter file (PFILE) is being used then a message is written to the alert file stating that the initialization parameter file must be manually changed.


SQL> --when we rename undo tablespace and instance is startup with PFILE then
SQL> --rename entry is recorded in alert_sid.log file.
SQL> show parameter spfile

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL> --database is startup from pfile
SQL> alter tablespace undotbs1 rename to undotbs;

Tablespace altered.

Sat Sep 08 20:14:52 2007
Tablespace 'UNDOTBS1' is renamed to 'UNDOTBS'.
PFILE is being used. It must be manually modified to reflect the new tablespace name if the old tablespace name is specified as UNDO_TABLESPACE in the PFILE.

Multiple Temporary Tablespaces: Using Tablespace Groups


Multiple Temporary Tablespaces: Using Tablespace Groups



You can create a temporary tablespace group that can be specifically assigned to users in the same way that a single temporary tablespace is assigned. A tablespace group can also be specified as the default temporary tablespace for the database.


A tablespace group has the following characteristics:

1. It contains at least one tablespace. There is no explicit limit on the maximum number of tablespaces that are contained in a group.

2. It shares the namespace of tablespaces, so its name cannot be the same as any tablespace.

3. You can specify a tablespace group name wherever a tablespace name would appear when you assign a default temporary tablespace for the database or a temporary tablespace for a user.


How to create temporary tablespace group

Note: You do not explicitly create a tablespace group. Rather, it is created implicitly when you assign the first temporary tablespace to the group. The group is deleted when the last temporary tablespace it contains is removed from it.

SQL> ALTER TABLESPACE temp TABLESPACE GROUP group1;

Tablespace altered.

SQL> CREATE TEMPORARY TABLESPACE temp1
2 TEMPFILE 'c:\oracle\product\10.1.0\oradata\temp02.dbf' size 5m
3 TABLESPACE GROUP group2;

Tablespace created.

SQL> desc dba_tablespace_groups;
Name Null? Type
----------------------------------------- -------- ----------------------------

GROUP_NAME NOT NULL VARCHAR2(30)
TABLESPACE_NAME NOT NULL VARCHAR2(30)

SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP
GROUP2 TEMP1


How to change TABLESPACE GROUP


SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP
GROUP2 TEMP1

SQL> ALTER TABLESPACE temp1 TABLESPACE GROUP group1;

Tablespace altered.

SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP
GROUP1 TEMP1


How to assign TABLESPACE GROUP to particular user.


SQL> select temporary_tablespace
2 from dba_users
3 where username = 'SCOTT';

TEMPORARY_TABLESPACE
------------------------------
GROUP1

SQL> alter user scott temporary tablespace group2;


How to delete temporary tablespace groups


SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP
GROUP2 TEMP1

SQL> alter tablespace temp1 tablespace group '';

Tablespace altered.

SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP


How to Assigning a Tablespace Group as the Default Temporary Tablespace


SQL> select * from dba_tablespace_groups;

GROUP_NAME TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1 TEMP
GROUP1 TEMP1

SQL> alter database ORCL default temporary tablespace group1;

Database altered.


Using a tablespace group, rather than a single temporary tablespace, can alleviate problems caused where one tablespace is inadequate to hold the results of a sort, particularly on a table that has many partitions. A tablespace group enables parallel execution servers in a single parallel operation to use multiple temporary tablespaces.

Saturday, January 20, 2007

Temporary Tablespace

Temporary Tablespace

A temporary tablespace contains transient data that persists only for the duration of the session. Temporary tablespaces can improve the concurrence of multiple sort operations, reduce their overhead, and avoid Oracle Database space management operations
You can view the allocation and deallocation of space in a temporary tablespace sort segment

1.V$sort_segment
2.V$tempseg_usage
3.V$tempfile
4.dba_temp_files
5.V$temp_space_header



Creating a Locally Managed Temporary Tablespace



create temporary tablespace TEMP1
tempfile 'c:\oracle\product\10.1.0\oradata\catdb\temp02.dbf' size 3m reuse
autoextend off
uniform size 50k;



The AUTOALLOCATE clause is not allowed for temporary tablespaces


The following statement drops a temporary file and deletes the operating system file:


ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf' DROP
INCLUDING DATAFILES;

Monday, January 15, 2007

Dictionary Tablespace

Dictionary Managed Tablespace

SQL> create tablespace DICTBS
2 datafile 'c:\oracle\product\10.1.0\oradata\db02\dictbs01.dbf' size 1m
3 extent management DICTIONARY
4 DEFAULT STORAGE (
5 INITIAL 50K
6 NEXT 100K
7 MINEXTENTS 1
8 MAXEXTENTS 100
9 PCTINCREASE 0);

For Coalesce tablespace.
SQL>alter tablespace &tablespace_name COALESCE;


Note:

The ALTER TABLESPACE ... COALESCE statement does not coalesce free extents that are separated by data extents. If you observe many free extents located between data extents, you must reorganize the tablespace (for example, by exporting and importing its data) to create useful free space extents.
Monitoring Free Space
DBA_FREE_SPACE

Example:
select block_id, bytes,blocks
from dba_free_space
where tablespace_name = '&tbs_name'
order by block_id;

Statistics for coalescing activity
DBA_FREE_SPACE_COALESCED

BIGFILE TABLESPACE

Bigfile Tablespace.
If tablespace with 8k blocks can cantain a 32 tb datafile.
if tablespace with 32k blocks can cantain a 128 tb datafile.

Bigfile only supported Locally Managed tablespace with three exception.
Bigfile also supported below three tbs is extent management is local or segment space management is manual;

Undo Tbs
Temp Tbs + Extent Management LOCAL + Segment Space management MANUAL
SYSTEM tbs

Create Statement for Bigfile tablespace.
1.You have to specify "BIGFILE" keyword in create tablespace statement.
2.No need to specify "EXTENT MANAGEMENT" or "SEGMENT MANAGEMENT" clause.
3.If you specify extent management "DICTIONARY" or segment management "AUTO" database return error.
4.You can only specify one datafile.
5.If default tablespace type was set to "BIGFILE" at database creation time then no need to specify
"BIGFILE" keyword at create tablespace statement.
.But if you want to create smallfile datafile you have to specify "SMALLFILE" keyword at create tablespace statement

SQL> create BIGFILE tablespace BIGTBS
2 datafile 'c:\oracle\product\10.1.0\oradata\db02\bigtbs01.dbf' size 10m
3 autoextend on next 1m maxsize 50m
4 autoallocate;

Tablespace created.

SQL> select extent_management, segment_space_management
2 from dba_tablespaces
3 where tablespace_name = 'BIGTBS';

EXTENT_MAN SEGMEN
---------- ------
LOCAL AUTO

Sunday, January 14, 2007

Locally Managed Tablespace

Oracle Version : 10.1.0.2.0
OS Platform : WinXP sp2
-------------------------------------------------------------------------------------
Locally Managed Tablespace
Benefits
1.Readable standby databases are allowed, because locally managed temporary tablespaces (used, for example, for sorts) are locally managed and thus do not generate any undo or redo.

2.Coalescing free extents is unnecessary for locally managed tablespaces
-------------------------------------------------------------------------------------
1.We can create Locally Managed Tbs specify "LOCAL" extent management clause.
create tablespace &tablespace_name
datafile 'path' size xxxk
EXTENT MANAGEMENT LOCAL;

2.If we want database extent manage automatically we should choose "AUTOALLOCATE" clause. It is default.
create tablespace &tablespace_name
datafile 'path' size xxxk
extent management LOCAL
AUTOALLOCATE;

3.If we want exact control on unused space and we can predict allocation for objects then "UNIFORM" size is best.This setting ensures that you will never have unusable space in your tablespace.
create tablespace &tablespace_name
datafile 'path' size xxxk
UNIFORM SIZE XXXK;
Note: If you omit SIZE clause with UNIFORM, then the default size is 1M

4.When we not specify explicity "EXTENT MANAGEMENT CLAUSE" then database determines extent management as fellows.
1.If we omit DEFAULT storage clause in create tablespace statement then database create tablespace in "Locally Managaned + Autoallocated".
create tablespace &tablespace
datafile 'path' size xxxk;

2.If we specify DEFAULT storage clause then
1.If MINIMUN EXTENT + INITIAL + NEXT are EQUAL AND PCTINCREASE is 0.then database create "Locally Managed + Uniform".

SQL> create tablespace TEST
2 datafile 'c:\test.dbf' size 2m
3 default storage (
4 initial 100k
5 next 100k
6 pctincrease 0);


Tablespace created.
SQL> create table scott.f as select * from all_objects where rownum <= 9000;

Table created.

SQL> select extent_id,block_id,bytes,blocks
2 from dba_extents
3 where owner = 'SCOTT' and segment_name = 'F';

EXTENT_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ----------
0 9 106496 13
1 22 106496 13
2 35 106496 13
3 48 106496 13
4 61 106496 13
5 74 106496 13
6 87 106496 13
7 100 106496 13
8 113 106496 13

9 rows selected.

SQL> alter database default tablespace test;


2.if MINIMUN EXTENT + INITIAL + NEXT are NOT EQUAL OR PCTINCREASE is 0.then database create "Locally Managed + Autoallocated".ignore any storage settings.

SQL> create tablespace TEST
2 datafile 'c:\test.dbf' size 7m
3 default storage (
4 initial 100k
5 next 200k
6 pctincrease 0);


Tablespace created.

SQL> alter database default tablespace test;

Database altered.

SQL> select extent_id,block_id,bytes,blocks
2 from dba_extents
3 where owner = 'SCOTT' and segment_name

EXTENT_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ----------
0 9 65536 8
1 17 65536 8
2 25 65536 8
3 33 65536 8
4 41 65536 8
5 49 65536 8
6 57 65536 8
7 65 65536 8
8 73 65536 8
9 81 65536 8
10 89 65536 8

EXTENT_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ----------
11 97 65536 8
12 105 65536 8
13 113 65536 8
14 121 65536 8
15 129 65536 8
16 137 1048576 128
17 265 1048576 128
18 393 1048576 128
19 521 1048576 128
20 649 1048576 128

21 rows selected.


5.Segment Space Management
Two option
1.Manual ( default)
Manual segment-space management uses free lists to manage free space within segments.
you must specify and tune the PCTUSED, FREELISTS, and FREELIST GROUPS storage parameters for schema objects created in the tablespace

2.Auto
Automatic segment-space management uses bitmaps to manage the free space within segments.
You can specify automatic segment-space management only for permanent, locally managed tablespaces

Note :
The segment-space management you specify at tablespace creation time applies to all segments subsequently created in the tablespace. You cannot subsequently change the segment-space management mode of a tablespace.

Sunday, November 12, 2006

Tablespace Size

SQL> select tablespace_name, 'Mb'||' '||round(sum(bytes/1024/1024)) "Used_Size"

2 from dba_data_files
3 group by tablespace_name;

TABLESPACE_NAME Used_Size
------------------------------ -------------------------------------------
DENI Mb 3
EXAMPLE Mb 150
SYSAUX Mb 310
SYSTEM Mb 450
UNDOTBS1 Mb 875
USERS1 Mb 3629

6 rows selected.

SQL> select tablespace_name, 'Mb'||' '||round(sum(bytes/1024/1024)) "Free_Size"

2 from dba_free_space
3 group by tablespace_name;

TABLESPACE_NAME Free_Size
------------------------------ -------------------------------------------
DENI Mb 3
EXAMPLE Mb 70
SYSAUX Mb 19
SYSTEM Mb 4
UNDOTBS1 Mb 867
USERS1 Mb 1

6 rows selected.