oracle10g_create tablespace_測試_1

wisdomone1發表於2009-09-12
SQL> create user test identified by system account unlock;

User created.

SQL> grant resource,connect to test;

Grant succeeded.

SQL> create tablespace test datafile '/oracle/db/test01.dbf' size 10m;

Tablespace created.

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 file_name,tablespace_name,bytes/1024/1024 mb,autoextensible from dba_data_files where tablespace_name='TEST';

FILE_NAME
--------------------------------------------------
TABLESPACE_NAME                        MB AUT
------------------------------ ---------- ---
/oracle/db/test01.dbf
TEST                                   10 NO


FILE_NAME                      TABLESPACE         MB AUT
------------------------------ ---------- ---------- ---
/oracle/db/test01.dbf          TEST               10 NO

SQL> select dbms_metadata.get_ddl('TABLESPACE','TEST') from dual;---檢視錶空間的定義語句


SQL> set long 99999
SQL> /

DBMS_METADATA.GET_DDL('TABLESPACE','TEST')
--------------------------------------------------------------------------------

  CREATE TABLESPACE "TEST" DATAFILE
  '/oracle/db/test01.dbf' SIZE 10485760
  LOGGING ONLINE PERMANENT BLOCKSIZE 8192
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO



SQL> conn test/system      --如果一般使用者要建立/刪除表空間,要給許可權create|drop tablespace         
Connected.
SQL> create tablespace own datafile '/oracle/db/own01.dbf' size 10m;
create tablespace own datafile '/oracle/db/own01.dbf' size 10m
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn /as sysdba
Connected.
SQL> grant create tablespace to test;

Grant succeeded.

SQL> conn test/system
Connected.
SQL> create tablespace own datafile '/oracle/db/own01.dbf' size 10m;

Tablespace created.

SQL> drop tablespace own including contents and datafiles;
drop tablespace own including contents and datafiles
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn /as sysdba
Connected.
SQL> grant drop tablespace to test;

Grant succeeded.

SQL> conn test/system
Connected.
SQL> drop tablespace own including contents and datafiles;--刪除表空間及其資料檔案

Tablespace dropped.

SQL> conn /as sysdba
Connected.
SQL> desc dba_tablespaces;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
 BLOCK_SIZE                                NOT NULL NUMBER
 INITIAL_EXTENT                                     NUMBER
 NEXT_EXTENT                                        NUMBER
 MIN_EXTENTS                               NOT NULL NUMBER
 MAX_EXTENTS                                        NUMBER
 PCT_INCREASE                                       NUMBER
 MIN_EXTLEN                                         NUMBER
 STATUS                                             VARCHAR2(9)
 CONTENTS                                           VARCHAR2(9)
 LOGGING                                            VARCHAR2(9)
 FORCE_LOGGING                                      VARCHAR2(3)
 EXTENT_MANAGEMENT                                  VARCHAR2(10)
 ALLOCATION_TYPE                                    VARCHAR2(9)
 PLUGGED_IN                                         VARCHAR2(3)
 SEGMENT_SPACE_MANAGEMENT                           VARCHAR2(6)
 DEF_TAB_COMPRESSION                                VARCHAR2(8)
 RETENTION                                          VARCHAR2(11)
 BIGFILE                                            VARCHAR2(3)


--檢視錶空間相關屬性:塊大小,是否大檔案(大檔案表空間就是一個表空間只能有一個資料檔案,此檔案大小可達
 -- 資料檔案或者檔案為128 terabytes (TB) 對於塊大小為 32K blocks ,對於塊大小為8k資料檔案或臨時檔案大小為32TB
 --我們一般的業務不可能用哪麼大,當然預設是smallfile,它最大檔案數為1022
 

SQL> select tablespace_name,block_size,logging,allocation_type,bigfile from dba_tablespaces where tablespace_name='TEST';

TABLESPACE BLOCK_SIZE LOGGING   ALLOCATIO BIG
---------- ---------- --------- --------- ---
TEST             8192 LOGGING   SYSTEM    NO

SQL> create bigfile tablespace bigtbs datafile '/oracle/db/bigtbs01.dbf' size 10m;

Tablespace created.

SQL> select tablespace_name,block_size,logging,allocation_type,bigfile from dba_tablespaces where tablespace_name='BIGTBS';

TABLESPACE BLOCK_SIZE LOGGING   ALLOCATIO BIG
---------- ---------- --------- --------- ---
BIGTBS           8192 LOGGING   SYSTEM    YES

SQL> drop tablespace bigtbs including contents and datafiles;

Tablespace dropped.

SQL> create smallfile tablespace smalltbs datafile '/oracle/db/smalltbs01.dbf' size 10m;

Tablespace created.

SQL> select tablespace_name,block_size,logging,allocation_type,bigfile from dba_tablespaces where tablespace_name='SMALLTBS';

TABLESPACE BLOCK_SIZE LOGGING   ALLOCATIO BIG
---------- ---------- --------- --------- ---
SMALLTBS         8192 LOGGING   SYSTEM    NO

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';---檢視錶空間是否線上,下線(就是此表空間可否讀寫)

TABLESPACE STATUS
---------- ---------
TEST       ONLINE

SQL> alter tablespace test offline;--此表空間下線

Tablespace altered.

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';

TABLESPACE STATUS
---------- ---------
TEST       OFFLINE

SQL> alter tablespace test online;                                                  

Tablespace altered.

SQL> select tablespace_name,min_extents,max_extents from dba_tablespaces where tablespace_name='TEST';

TABLESPACE MIN_EXTENTS MAX_EXTENTS
---------- ----------- -----------
TEST                 1  2147483645

SQL> show user  
USER is "SYS"
SQL> create tablespace minextent datafile '/oracle/db/minextent01.dbf' size 10m  minimum extent 10 nologging offline
  2  default compress;

Tablespace created.

SQL> select tablespace_name,min_extents,max_extents from dba_tablespaces where tablespace_name='MINEXTENT';

TABLESPACE MIN_EXTENTS MAX_EXTENTS
---------- ----------- -----------
MINEXTENT            1  2147483645


---表空間所屬表是否壓縮
SQL> select tablespace_name,logging,status,min_extlen,def_tab_compression from dba_tablespaces where tablespace_name='MINEXTENT';

TABLESPACE LOGGING   STATUS    MIN_EXTLEN DEF_TAB_
---------- --------- --------- ---------- --------
MINEXTENT  NOLOGGING OFFLINE        65536 ENABLED



SQL> alter tablespace minextent default nocompress;

Tablespace altered.

SQL>  select tablespace_name,logging,status,min_extlen,def_tab_compression from dba_tablespaces where tablespace_name='MINEXTENT';

TABLESPACE LOGGING   STATUS    MIN_EXTLEN DEF_TAB_
---------- --------- --------- ---------- --------
MINEXTENT  NOLOGGING OFFLINE        65536 DISABLED

SQL> alter tablespace minextent online;

Tablespace altered.

SQL> select tablespace_name,extent_management,segment_space_management from dba_tablespaces where tablespace_name='MINEXTENT';

TABLESPACE EXTENT_MAN SEGMEN
---------- ---------- ------
MINEXTENT  LOCAL      AUTO

SQL> alter tablespace minextent extent management dictionary;--10g不能用dictionary管理方式了,太多的字典表競爭
alter tablespace minextent extent management dictionary
                           *
ERROR at line 1:
ORA-02142: missing or invalid ALTER TABLESPACE option


SQL> drop tablespace test including contents and datafiles;

Tablespace dropped.



SQL> create tablespace test datafile '/oracle/db/test01.dbf' size 10m extent management dictionary segment space management manual;
create tablespace test datafile '/oracle/db/test01.dbf' size 10m extent management dictionary segment space management manual
*
ERROR at line 1:
ORA-12913: Cannot create dictionary managed tablespace


SQL> create tablespace test datafile '/oracle/db/test01.dbf' size 10m extent management dictionary;
create tablespace test datafile '/oracle/db/test01.dbf' size 10m extent management dictionary
*
ERROR at line 1:
ORA-12913: Cannot create dictionary managed tablespace


SQL> create tablespace test datafile '/oracle/db/test01.dbf' size 10m extent management local uniform. size 1m;

Tablespace created.



SQL> drop tablespace test including contents and datafiles;

Tablespace dropped.

SQL> create tablespace test datafile '/oracle/db/test01.dbf' size 10m flashback off;--開啟此表空間是否可以閃回,10g新特性

Tablespace created.

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> desc v$tablespace;---閃回列,對應上面
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 TS#                                                NUMBER
 NAME                                               VARCHAR2(30)
 INCLUDED_IN_DATABASE_BACKUP                        VARCHAR2(3)
 BIGFILE                                            VARCHAR2(3)
 FLASHBACK_ON                                       VARCHAR2(3)
 ENCRYPT_IN_BACKUP                                  VARCHAR2(3)

SQL> select name,included_in_database_backup,bigfile,flashback_on from v$tablespace where name='TEST';

NAME                           INC BIG FLA
------------------------------ --- --- ---
TEST                           YES NO  NO

SQL> alter tablespace test flashback on;
alter tablespace test flashback on
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any
instance


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  314572800 bytes
Fixed Size                  1279964 bytes
Variable Size              79693860 bytes
Database Buffers          230686720 bytes
Redo Buffers                2912256 bytes
Database mounted.
SQL> alter tablespace test flashback on;--變更表空間為閃回,在database mount狀態下

Tablespace altered.

SQL> alter database open;

Database altered.

SQL> select name,included_in_database_backup,bigfile,flashback_on from v$tablespace where name='TEST';

NAME                           INC BIG FLA
------------------------------ --- --- ---
TEST                           YES NO  YES

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-614492/,如需轉載,請註明出處,否則將追究法律責任。

相關文章