網(wǎng)站首頁 編程語言 正文
查詢 Oracle
數(shù)據(jù)庫表空間的大小以及每個表所占空間的大小,在網(wǎng)上搜索了一些查詢語句,在此記錄一下:
1、查詢數(shù)據(jù)庫中所有的表空間以及表空間所占空間的大小,直接執(zhí)行語句就可以了
SELECT tablespace_name, sum( bytes ) / 1024 / 1024 FROM dba_data_files GROUP BY tablespace_name;
2、查看表空間物理文件的名稱及大小
SELECT tablespace_name, file_id, file_name, round( bytes / ( 1024 * 1024 ), 0 ) total_space FROM dba_data_files ORDER BY tablespace_name;
3、查詢所有表空間以及每個表空間的大小,已用空間,剩余空間,使用率和空閑率,直接執(zhí)行語句就可以了
SELECT a.tablespace_name, total, free, total - free AS used, substr( free / total * 100, 1, 5 ) AS "FREE%", substr( ( total - free ) / total * 100, 1, 5 ) AS "USED%" FROM (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS total FROM dba_data_files GROUP BY tablespace_name) a, (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS free FROM dba_free_space GROUP BY tablespace_name) b WHERE a.tablespace_name = b.tablespace_name ORDER BY a.tablespace_name;
4、查詢某個具體的表所占空間的大小,把 TABLE_NAME 換成具體要查詢的表的名稱就可以了
SELECT t.segment_name, t.segment_type, sum( t.bytes / 1024 / 1024 ) "占用空間(M)" FROM dba_segments t WHERE t.segment_type = 'TABLE' AND t.segment_name = 'TABLE_NAME' GROUP BY OWNER, t.segment_name, t.segment_type;
一些 Oracle
基礎(chǔ)語句
在邏輯結(jié)構(gòu)中, Oracle
從大到下,分別是如下的結(jié)構(gòu):數(shù)據(jù)庫實例 -> 表空間 -> 數(shù)據(jù)段(表) -> 區(qū) -> 塊。
也就是說當(dāng)我們要使用 Oracle
作為項目的數(shù)據(jù)庫時,我們需要先創(chuàng)建數(shù)據(jù)庫實例,之后創(chuàng)建表空間,再創(chuàng)建相對應(yīng)的表(也就是邏輯結(jié)構(gòu)中的數(shù)據(jù)段)。
5、創(chuàng)建數(shù)據(jù)庫實例
創(chuàng)建數(shù)據(jù)庫實例一般使用 配置移植工具 -> Database Configuration Assistant
來創(chuàng)建。
6、創(chuàng)建表空間
創(chuàng)建名為 animal
的表空間,數(shù)據(jù)文件為 animal.dbf
create user csy identified by csy default tablespace ANIMAL;
查詢當(dāng)前用戶擁有的所的有表空間:
select tablespace_name from user_tablespaces;
7、創(chuàng)建用戶并指定默認(rèn)表空間,并為其授予權(quán)限
創(chuàng)建用戶:
注意:這里的 ANIMAL(表空間)
必須大寫(因為 Oracle
自動將表空間名字全部轉(zhuǎn)為大寫)
create user csy identified by csy default tablespace ANIMAL;
最后,賦予用戶 DBA
權(quán)限:
grant connect, resource, dba to csy;
8、創(chuàng)建表(數(shù)據(jù)段)
下面的語句在 animal
表控件下創(chuàng)建一個名為 dog
的表:
create table dog ( name varchar(12), age varchar(12) ) tablespace animal;
使用下面的語句查看是否添加成功。查看 ANIMAL
表空間下的所有表:
SELECT tablespace_name, table_name FROM user_tables WHERE tablespace_name = 'ANIMAL';
注意:上面的 ANIMAL
一定要大寫。即使你在創(chuàng)建表空間的時候輸入的表空間名是小寫的,也還是要大寫。
因為 Oracle
在存儲表空間的時候自動將名字轉(zhuǎn)化成大寫了。
9、刪除表空間
drop tablespace ANIMAL including contents and datafiles;
10、刪除用戶
drop user user_name cascade;
總結(jié)
原文鏈接:https://blog.csdn.net/qq_45083975/article/details/128292583
相關(guān)推薦
- 2024-01-15 idea 折疊代碼塊技巧 關(guān)于<editor-fold>
- 2022-11-27 C語言三種函數(shù)調(diào)用約定_cdecl與_stdcall及_fastcall詳細(xì)講解_C 語言
- 2022-08-06 QT生成隨機驗證碼的方法_C 語言
- 2023-07-05 【nacos優(yōu)化】定時刪除access日志
- 2023-04-01 一文初探?Goroutine?與?channel基本用法_Golang
- 2022-03-20 基于ABP框架實現(xiàn)數(shù)據(jù)字典開發(fā)_實用技巧
- 2023-11-12 python 列表、字典、元組與集合的特點以及對比
- 2022-09-27 Python?Matplotlib繪制扇形圖標(biāo)簽重疊問題解決過程_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支