--oracle監控函式
--檢視所有表空間利用率
select
a.a1 表空間名稱, c.c2 型別, c.c3 區管理,
b.b2/1024/1024 表空間大小m, (b.b2-a.a2)/1024/1024 已使用m,
substr((b.b2-a.a2)/b.b2*100,1,5) 利用率
from
(select tablespace_name a1, sum(nvl(bytes,0)) a2 from dba_free_space group by tablespace_name) a,
(select tablespace_name b1,sum(bytes) b2 from dba_data_files group by tablespace_name) b,
(select tablespace_name c1,contents c2,extent_management c3 from dba_tablespaces) c
where a.a1=b.b1 and c.c1=b.b1;
--檢視所有自建使用者
select username,default_tablespace from dba_users where account_status='open';
--檢視所有表空間
select tablespace_name, sum(bytes)/(1024*1024) as mbytes, sum(blocks) from dba_segments group by tablespace_name;
--檢視所有空閒表空間
select tablespace_name, sum(bytes)/(1024*1024) as freembytes, sum(blocks) from dba_free_space group by tablespace_name;
--檢視所有表空間是否自動擴充套件
select file_name,bytes/1024/1024 mb,autoextensible,tablespace_name from dba_data_files;
--查詢所有使用者及建立時間
select * from all_users;
--檢視當前使用者連線
select * from v$session where status='active' and schemaname!='sys';
--檢視當前使用者許可權
select * from session_privs;
--查詢當前使用者函式和儲存過程
select * from user_source;
--查詢當前使用者哪個表的記錄數最多
select table_name, tablespace_name, num_rows, blocks from user_all_tables order by num_rows desc;
--檢視當前使用者哪個表佔的空間最大
select segment_name,tablespace_name,bytes/1024/1024 as mbytes,blocks from user_segments where segment_type='table' order by mbytes desc;
--檢視座標投影系
select * from sde.spatial_references;
--刪除空間索引
drop index tablename_spatial_idx;
--select * from user_sdo_geom_metadata
--刪除註冊空間資訊
delete from user_sdo_geom_metadata where table_name='tablename';
--刪除sde註冊空間資訊
--echo y | sdelayer -o delete -l tablename,spatialcolumn -u usr -p pwd
delete from sde.table_registry t where t.owner=='username'
delete from sde.column_registry t1 where t1.owner=='username'
delete from sde.geometry_columns t2 where t2.f_table_schema=='username'
delete from sde.gdb_usermetadata t3 where t3.owner=='username'
delete from sde.layers t4 where t4.owner=='username'
--清空指定名稱的表交釋放空間
begin
for t in (select table_name from user_tables where upper(table_name) like 'smr_%'or upper(table_name) like 'tmp_%'or upper(table_name) like 'temp_%') loop
execute immediate 'truncate table ' || t.table_name;
end loop;
end;
truncate table smr_ecable_count
commit;
--檢視被鎖的表
select p.spid, a.serial#, c.object_name, b.session_id, b.oracle_username, b.os_user_name
from v$process p, v$session a, v$locked_object b, all_objects c
where p.addr=a.paddr and a.process=b.process and c.object_id=b.object_id
--檢視連線的程序
select sid, serial#, username, osuser from v$session;
--殺掉程序
alter system kill session 'sid,serial#';
操作命令:
sql> alter tablespace users offline;
tablespace altered.
sql> alter tablespace users online;
tablespace altered.
將表空間置為唯讀模式和讀寫模式:
sql> alter tablespace users read only;
tablespace altered.
sql> alter tablespace users read write;
tablespace altered.
刪除表空間:
sql> drop tablespace users including contents and datafiles;
tablespace dropped.
create tablespace fjng090930 datafile 'd:\oracle\fjng090930.dbf' size 500m;
alter database datafile 'd:\oracle\fjng090930.dbf' autoextend on next 500m maxsize unlimited;
create user fjng090930 identified by fjng090930;
grant connect,resource,dba to fjng090930;
imp fjng090930/fjng090930@ora fromuser=fj090930 touser=fjng090930 file=d:\fjng090930.dmp
Oracle常用SQl整理
檢視新執行sql select from v sqlarea t where t.first load time like 2011 11 04 11 order by t.first load time desc 1.檢視oracle資料庫表是否被鎖住 select a.b.sid,b.seria...
oracle實踐常用SQL
tablea columna columnb a 1 2 sss select from a where columna like 1 2 提示輸入變數。如果想要根據clomna值,查詢sss,怎麼辦?分析 由於 是oracle中的變數字元 特殊字元 因此需要將 設定為非特殊字元才能正常查詢。解決 ...
oracle常用sql語句
1.解鎖oracle使用者下某個使用者 以內建的scott使用者為例 sql conn as sysdba sql alter user scott account unlock identified by tiger 解釋 首先要切換到sysdba使用者下,否則會提示 許可權不足 error at...