常用sql語句記錄 持續更新

2021-09-21 13:50:44 字數 3939 閱讀 2636

常規表空間使用率查詢

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss' ) from dual ;

prompt ##########tablespace

set linesize 120

set pagesize 10000

col tablespace format a20

select a.tablespace,a.total,a.total-b.free,b.free,round((b.free/a.total)*100,2)

from ( select tablespace_name tablespace,sum(bytes/1024/1024) total

from dba_data_files

where tablespace_name not in ('undotbs1','undotbs2')

and tablespace_name not like 'temp%' --add by lj

group by tablespace_name ) a,

( select tablespace_name tablespace,round(sum(bytes/1024/1024)) free

from dba_free_space

group by tablespace_name ) b

where a.tablespace = b.tablespace(+)

-- and round((b.free/a.total)*100) <11

order by 5 asc;

臨時表空間使用率查詢

select d.tablespace_name,space "sum_space(m)",blocks sum_blocks, 

used_space "used_space(m)",round(nvl(used_space, 0) / space * 100, 2) "used_rate(%)",

space - used_space "free_space(m)"

from (select tablespace_name, round(sum(bytes) / (1024 * 1024), 2) space,

sum(blocks) blocks

from dba_temp_files

group by tablespace_name) d,

(select tablespace,

round(sum(blocks * 8192) / (1024 * 1024), 2) used_space

from v$sort_usage

group by tablespace) f

where d.tablespace_name = f.tablespace(+)

order by "used_rate(%)" desc;

會話資訊查詢

select status,count(*) from **$session group by status;
失效物件

select owner, object_name, object_type

from dba_objects

where status = 'invalid'

and owner not in ('sys', 'system')

等待事件資訊查詢

select

ash.event,

sum(ash.wait_time +

ash.time_waited) ttl_wait_time

from

v$active_session_history ash

where

ash.sample_time between sysdate - 60/1440 and sysdate

group by

ash.event

order by 2;

事務top cpu sql

select * from 

(select sql_text,

round(cpu_time/1000000) cpu_time,

round(elapsed_time/1000000) elapsed_time,

disk_reads,

buffer_gets,

rows_processed

from v$sqlarea

order by cpu_time desc, disk_reads desc

) where rownum < 10;

exit ;

查詢job資訊:

select job,log_user, next_date, next_sec, failures, broken from dba_jobs;
最後蒐集統計資訊的時間

select owner,table_name,num_rows,last_analyzed from dba_tables where table_name='aptjrntran';

select owner,index_name,num_rows,last_analyzed,pct_free,status from dba_indexes where index_name='pk_aptjrntran';

表,索引大小

select segment_name, bytes/1024/1024

from dba_segments

where segment_type = 'table'

and segment_name='aptjrntran'

/select segment_name, bytes/1024/1024

from dba_segments

where segment_type = 'index'

and segment_name='pk_aptjrntran'

/

表和索引的元資料

set long 99999

select dbms_metadata.get_ddl('index','pk_aptjrntran','owner') from dual;

set long 99999

select dbms_metadata.get_ddl('table','aptjrntran','owner') from dual;

檢視表的統計資訊(包含時間間隔)

col  owner for a20

col partition_name for a25

col subpartition_name for a25

col stats_update_time for a40

col interval for a40

select owner,

table_name,

partition_name,

subpartition_name,

stats_update_time,

stats_update_time - lag(stats_update_time, 1, null) over(partition by owner, table_name order by stats_update_time) interval

from dba_tab_stats_history

where owner = '&user_name'

and table_name = '&table_name'

order by owner, table_name, stats_update_time desc;

mysql 常用SQL語句介紹(持續更新)

個人總結更新,mysql 常用sql語句介紹 博主習慣小寫 test table 資料庫表 column name 字段 str 字串等型別資料 1 建立庫表 create table test table colnum name1 varchar 50 colnum name2 datatime ...

精妙SQL語句介紹 持續更新

說明 複製表 只複製結構,源表名 a 新錶名 b sql select into b from a where 1 1 說明 拷貝表 拷貝資料,源表名 a 目標表名 b sql insert into b a,b,c select d,e,f from b sql select a.title,a....

SQL語句小tips(持續更新)

判斷people id是否是32為字母組成的,統計不滿足要求的資料 select count if binary people id not regexp 0 9a z true,null as people id illegality cnt from people day if expr1 ex...