進入Oracle用戶
su - oracle
以dba身份進入sql語句
sqlplus / as sysdba
啓動數據庫相關命令
啓動數據庫
startup
啓動監聽(關閉監聽的命令lsnrctl stop),退出sql編寫界面
lsnrctl start
關閉數據庫服務,在sql編寫界面
shutdown immediate
常看當前連接用戶的信息
select * from user_users;
查看數據庫的啓動狀態 (查看進程裏面有沒 有Oracle數據庫這個進程)
ps -ef|grep oracle
表空間相關命令
Sql語句執行的時候要加上分號
創建表空間:
SQL> create tablespace test_work
2 datafile'/u01/app/oracle/oradata/abc.dbf'
3 size 10M AUTOEXTEND ON;
查詢當前所有的表空間:
select *from DBA_TABLESPACES
分類別查看當前的表空間:
SQL> select tablespace_name,
2 file_name,
3 round(bytes / (1024 * 1024), 0) total_space(顯示出來的數字是以M爲單位的)
4 from dba_data_files
5 order by tablespace_name;
刪除相應的表空間
drop tablespace xxx including contents and datafiles;
查看詳細數據文件:
SQL> select file_name,tablespace_name from dba_data_files;
擴展表空間
alter database datafile '/u01/app/oracle/oradata/abc.dbf' resize 20M;
查看錶空間的名字及文件所在位置
select tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
from sys.dba_data_files
order by tablespace_name
-查詢當前表空間下使用情況
select a.tablespace_name,
a.bytes / 1024 / 1024 "sum MB",
(a.bytes - b.bytes) / 1024 / 1024 "used MB",
b.bytes / 1024 / 1024 "free MB",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "used%"
from (select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes, max(bytes) largest
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.bytes) desc;