Oracle tablespace operations

Source: Internet
Author: User
1. View tablespace Information Java Code
  1. Select F. tablespace_name, A. Total, U. Used, F. Free, round (U. Used/a. Total )*100)"% Used",
  2. Round (f. Free/a. Total )*100)"% Free"
  3. From
  4. (Select tablespace_name, sum (Bytes /(1024*1024) Total
  5. From dba_data_files group by tablespace_name),
  6. (Select tablespace_name, round (sum (Bytes /(1024*1024) Used
  7. From dba_extents group by tablespace_name) U,
  8. (Select tablespace_name, round (sum (Bytes /(1024*1024) Free
  9. From dba_free_space group by tablespace_name) f
  10. Where a. tablespace_name = f. tablespace_name
  11. And a. tablespace_name = U. tablespace_name;
Select F. tablespace_name,. total, U. used, F. free, round (U. used/. total) * 100) "% used", round (f. free/. total) * 100) "% free" from (select tablespace_name, sum (Bytes/(1024*1024) Total from dba_data_files group by tablespace_name) A, (select tablespace_name, round (sum (Bytes/(1024*1024) used from dba_extents group by tablespace_name) U, (select tablespace_name, round (sum (Bytes/(1024*1024 ))) free from dba_free_space group by tablespace_name) fwhere. tablespace_name = f. tablespace_nameand. tablespace_name = u. tablespace_name;

2. Create a tablespaceJava code

    1. SQL> Create tablespace testspace
    2. Datafile'D:/oracletest/test001.dbf'Size 10 m autoextend on next 5 m maxsize Unlimited
    3. Extent management local;
 
SQL> Create tablespace testspace datafile 'd:/oracletest/test001.dbf 'size 10 m autoextend on next 5 m maxsize unlimited extent management local;

2. Add data files to the tablespace

Java code
    1. SQL> alter tablespace testspace add datafile 'd: /oracletest/test002.dbf' size 5 m
    2. autoextend on next 3 m maxsize 50 m;
    3. SQL> alter tablespace testspace add datafile 'd: /oracletest/test002.dbf' size 5 m
    4. autoextend on next 3 m maxsize 50 m;
SQL> alter tablespace testspace add datafile 'd:/oracletest/test002.dbf 'size 5 m autoextend on next 3 m maxsize 50 m; SQL> alter tablespace testspace add datafile 'd: /oracletest/test002.dbf 'size 5 m autoextend on next 3 m maxsize 50 m;

3. Delete the data files in the tablespace.Java code

    1. SQL> alter tablespace testspace drop datafile'D:/oracletest/test002.dbf';
    2. SQL> alter tablespace testspace drop datafile'D:/oracletest/test002.dbf';
SQL> alter tablespace testspace drop datafile 'd:/oracletest/test002.dbf '; SQL> alter tablespace testspace drop datafile 'd:/oracletest/test002.dbf ';

4. Modify the data file size of the tablespace File

Java code
    1. SQL> alter database datafile'D:/oracletest/test001.dbf'Resize 10 m;
    2. SQL> alter database datafile'D:/oracletest/test001.dbf'Resize 10 m;
 
SQL> alter database datafile 'd:/oracletest/test001.dbf 'resize 10 m; SQL> alter database datafile 'd:/oracletest/test001.dbf' resize 10 m;

5. Modify the automatic growth attribute of the tablespace Data File

Java code
    1. SQL> alter database datafile'D:/oracletest/test001.dbf'Autoextend off;
    2. SQL> alter database datafile'D:/oracletest/test001.dbf'Autoextend off;
 
SQL> alter database datafile 'd:/oracletest/test001.dbf 'autoextend off; SQL> alter database datafile 'd:/oracletest/test001.dbf' autoextend off;

6. Modify the read/write attributes of a tablespace.

Java code
    1. SQL> alter tablespace testspace read only; (read-only)
    2. SQL> alter tablespace testspace read write; (read/write)
    3. SQL> alter tablespace testspace read only; (read-only)
    4. SQL> alter tablespace testspace read write; (read/write)
 
SQL> alter tablespace testspace read only; (read-only) SQL> alter tablespace testspace read write; (read and write) SQL> alter tablespace testspace read only; (read-only) SQL> alter tablespace testspace read write; (read/write)

7. Set tablespace disconnection/online

Java code
    1. SQL> alter tablespace testspace offline;
    2. SQL> alter tablespace testspace online;
    3. SQL> alter tablespace testspace offline;
    4. SQL> alter tablespace testspace online;
 
SQL> alter tablespace testspace offline; SQL> alter tablespace testspace online;

8. Transfer physical file paths

Java code
  1. (1) Set the offline alter tablespac testspace offline for the tablespace;
  2. (2) Physically transfers the tablespace file, that is, transfers the physical file of your tablespace to the path you want to move.
  3. (3) Logical transfer: Alter tablespace testspace rename datafile'D:/oracletest/test001.dbf'To'E:/test001.dbf';
  4. (4) Set online alter tablespace testspace online for the tablespace;
  5. (1) Set the offline alter tablespac testspace offline for the tablespace;
  6. (2) Physically transfers the tablespace file, that is, transfers the physical file of your tablespace to the path you want to move.
  7. (3) Logical transfer: Alter tablespace testspace rename datafile'D:/oracletest/test001.dbf'To'E:/test001.dbf';
  8. (4) Set online alter tablespace testspace online for the tablespace;
 
(1) set the tablespace offline alter tablespac testspace offline; (2) physical transfer tablespace file; that is, transfer your tablespace physical file to the path you want to move (3) logical transfer: alter tablespace testspace rename datafile 'd:/oracletest/test001.dbf 'to 'e:/test001.dbf'; (4) set online alter tablespace testspace online; (1) set the tablespace offline alter tablespac testspace offline; (2) physical transfer tablespace file; that is, transfer your tablespace physical file to the path you want to move (3) logical transfer: alter tablespace testspace rename datafile 'd:/oracletest/test001.dbf 'to 'e:/test001.dbf'; (4) set online alter tablespace testspace online;

9. delete a tablespace

Java code
    1. ( 1 ) do not delete the file drop tablespace testspace;
    2. ( 2 ) Drop tablespace testspace including contents and datafiles;
    3. ( 1 ) do not delete the file drop tablespace testspace;
    4. ( 2 ) Drop tablespace testspace including contents and datafiles;
(1) do not delete the file drop tablespace testspace; (2) delete the file drop tablespace testspace including contents and datafiles; (1) do not delete the file drop tablespace testspace; (2) delete the file drop tablespace testspace including contents and datafiles;

10. How do I start a database when a physical file is deleted illegally?

Java code
    1. (1) Shut down the database service.
    2. (2) Alter database datafile'D:/test001.dbf'Offline drop;
    3. (3) Alter database open;
    4. (4) Enable the Database Service Startup;
 
(1) shutdown the Database Service (2) alter database datafile 'd:/test001.dbf' offline drop; (3) alter database open; (4) Enable the Database Service Startup;

11. view the tablespace name

SQL code

    1. Select DistinctTablespace_nameFromTabs;
    2. SelectTablespace_nameFromUser_tablespaces;
 
Select distinct tablespace_name from tabs; select tablespace_name from user_tablespaces;

Example: Join table space Java code when creating a table

  1. -- Create tablespace
  2. Create tablespace tab_news datafile'F: \ oradata \ NPMs \ tab_news.dbf'Size 5 m autoextend on next 2 m maxsize unlimited extent management local;
  3. Autoextend on next 2 m represents auto-increment in 2 m size
  4. -- Create Table
  5. Create Table news_bbs
  6. (
  7. Bbsid number (10) NotNull,
  8. Project varchar2 (128) NotNull,
  9. Userid number (10),
  10. Content clob,
  11. Answerid number (10),
  12. Answercount number (10),
  13. Publishtime date
  14. )
  15. Tablespace news_tab
  16. Pctfree10
  17. Initrans1
  18. Maxtrans255
  19. Storage
  20. (
  21. Initial64
  22. Minextents1
  23. Maxextents Unlimited
  24. );
  25. -- Create/recreate primary, unique and foreign key constraints
  26. Alter table news_bbs
  27. Add constraint pk_news_bbs primary key (bbsid)
  28. Using Index
  29. Tablespace et_tab
  30. Pctfree10
  31. Initrans2
  32. Maxtrans255
  33. Storage
  34. (
  35. Initial 64 K
  36. Minextents1
  37. Maxextents Unlimited
  38. );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.