oracle千萬級資料量的表關聯更新

2021-08-19 11:18:36 字數 2008 閱讀 2454

查詢資料庫中的鎖:

select sess.sid, 

sess.serial

#, lo.oracle_username,

lo.os_user_name,

ao.object_name,

lo.locked_mode

from v$locked_object lo,

dba_objects ao,

v$session sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid

;

刪除鎖:

alter system kill session

'114,63072';

其中114對應上一條sql中的sid,63072對應上一條sql中的serial

如果刪除不了,可以執行下列的sql

select spid, osuser, s.program 

from v$session s,v$process p

where s.paddr=p.addr and s.sid=114

獲取程序號,然後進入資料庫的服務端,執行命令:

windows版:

c:\users\administrator>orakill orcl 2400

kill

of thread id 2400

ininstance orcl successfully signalled.

其中:orcl:表示要殺死的程序屬於的例項名

2400:是要殺掉的執行緒號

linux版:

kill -9

2400(查詢出的spid)

目前資料庫中有兩張表,根據主鍵id進行關聯,每張表都有2000+萬的資料,其中一張表儲存了大文字欄位clob欄位。現在要在這張大表中根據另一張表更新其中的乙個時間字段,採用的方式為:

declare

cursor cur is

select

t2.rowid as rid, t1.zzrq as rq

from cpws_temp_cly t1 ,cpws_temp_wc t2

where t1.id=t2.id and t2.new_date is

not null

order

by t2.rowid;

v_counter number;

begin

v_counter := 0;

for row in cur loop

update cpws_temp_wc

set new_date=row.rq

where rowid = row.rid;

v_counter := v_counter + 1;

if (v_counter >= 5000) then

commit;

v_counter := 0;

endif; end

loop;

commit;

end;

採用臨時表的形式也可以:

update (

select

cpws_temp_wc.new_date a1,

cpws_temp_cly.zzrq b1

from

cpws_temp_wc,

cpws_temp_cly

where

cpws_temp_wc.id = cpws_temp_cly.id and cpws_temp_wc.new_date is

notnull

)set a1 = b1;

還有是可以新建一張表進行批量插入操作,no logging插入,速度也很快。但我這個測試伺服器硬碟大小不夠了,就沒有嘗試。

mysql千萬級資料量優化(詳)

1 查詢語句where 子句使用時候優化或者需要注意的 2 like語句使用時候需要注意 3 in語句代替語句 4 索引使用或是建立需要注意 假設使用者表有一百萬使用者量。也就是1000000.num是主鍵 1 對查詢進行優化,應盡量避免全表掃瞄,首先應考慮在where及order by 涉及的列上...

千萬級資料量怎麼做分頁查詢

隨著資料量的增長,分頁數量自然也越來越多,可以通過子查詢的方式提公升分頁效率。在基本查詢的基礎上,先通過乙個子查詢檢索出該頁的起始主鍵id,然後作為主查詢where語句條件進行再次檢索。select from table where id select id from table limit off...

mysql千萬級資料量根據索引優化查詢速度

一 索引的作用 索引通俗來講就相當於書的目錄,當我們根據條件查詢的時候,沒有索引,便需要全表掃瞄,資料量少還可以,一旦資料量超過百萬甚至千萬,一條查詢sql執行往往需要幾十秒甚至更多,5秒以上就已經讓人難以忍受了。提公升查詢速度的方向一是提公升硬體 記憶體 cpu 硬碟 二是在軟體上優化 加索引 優...