1. 程式人生 > >Sybase 資料庫日誌滿 原因及解決方案

Sybase 資料庫日誌滿 原因及解決方案

一、sybase資料庫事務日誌滿的原因主要是
(1)open事務未結束,從未結束的open事務之後的日誌都不會被截斷
(2)大事務,從其之後的日誌都不會被截斷
(3)如果存在複製伺服器也會出現該問題,可以加資料庫引數解決
dbcc checktable(syslogs) 最新日誌剩餘空間

-T 7408(重新計算各個計數器)

二、故障查詢定位辦法
(1)定位open事務所在的dbid和程序號spid,通過如下命令
    select * from syslogshold
    例如:假設當天時間為12月31日,
    1> select * from syslogshold
    2> go
 dbid   reserved    spid   page        xactid         masterxactid   starttime                  name                                                                xloid      
 ------ ----------- ------ ----------- -------------- -------------- -------------------------- ------------------------------------------------------------------- -----------
      5           0    125     1451121 0x001624710002 0x000000000000        Dec 12 2007  9:08AM rt.dbo.a04_xuchang                                                          250
      2           0     70     3717615 0x0038b9ef0000 0x000000000000        Dec 17 2007  9:13AM $ins                                                                        140

(2 rows affected)
Execution Time (ms.):      0            Clock Time (ms.):      0

    spid為125的程序執行時間過長,存在異常;
   
   
    查記錄對應的dbid和程序號(spid),蒐集該程序資訊(或者用後續2、3的處理辦法),以便後續處理,
    sp_who "spid" 檢視該程序有關資訊
    sp_lock spid  檢視該程序有關資訊
   
    以spid為125的程序為例:
    1> sp_who "125"
    2> go
 fid    spid   status       loginame     origname     hostname   blk_spid dbname     cmd              block_xloid
 ------ ------ ------------ ------------ ------------ ---------- -------- ---------- ---------------- -----------
      0    125 recv sleep   nvbridge     nvbridge     nvbrg1     0        rt         BULK INSERT                0

(1 row affected)
(return status = 0)
Execution Time (ms.):      0            Clock Time (ms.):      0


3> sp_lock 125
4> go
The class column will display the cursor name for locks associated with a cursor for the current user and the cursor id for other users.
 fid    spid   loid        locktype                     table_id    page        row    dbname          class                          context                     
 ------ ------ ----------- ---------------------------- ----------- ----------- ------ --------------- ------------------------------ ----------------------------
      0    125         250 Ex_intent                     1216004332           0      0 rt              Non Cursor Lock                                            
      0    125         250 Ex_page                       1216004332      736727      0 rt              Non Cursor Lock                                            
      0    125         250 Ex_page                       1216004332      736729      0 rt              Non Cursor Lock                                            
      0    125         250 Ex_page                       1216004332      375328      0 rt              Non Cursor Lock                Ind pg                      
      0    125         250 Ex_page                       1216004332      736096      0 rt              Non Cursor Lock                Ind pg                      
      0    125         250 Ex_page-blk                   1216004332      736680      0 rt              Non Cursor Lock                Ind pg                      

(6 rows affected)
(return status = 0)
Execution Time (ms.):      0            Clock Time (ms.):      0
 
(2)開啟dbcc顯示,預設不顯示
     dbcc traceon(3604)
     將dbcc顯示輸出到螢幕上,預設不顯示(3605是輸入到錯誤日誌檔案中)
(3)查詢對應spid語句內容,找出open事務未結束原因
     dbcc sqltext(spid)
     可以輸出該spid對應的語句和它之前的語句,有些時間spid對應內容是看不到的(由於堆疊容量有限,因此,如果程序執行時間過長,堆疊中可能已沒有該語句的訊息,它對應的語句是看不到的)

三、可清除日誌也可擴增日誌檔案的空間

解決辦法:

1、馬上增加日誌裝置,並把裝置分配給資料庫。

alter database name log on device=200;

go

2、把資料庫置於-32768狀態,再把日誌清除。

sp_configure "allow update",1

go

update master..sysdatabases set status=-32768 where name='database_name'

go

shutdown with nowait  (注意:可能會延長啟動SYBASE資料庫時間,若確認沒有使用者在用,請使用shutdown with wait)

GO

cmd進入MSDOS方式,在進入cd c:\sybase\ASE-12_0\install\目錄下,執行RUN_SERVERNAME

啟動資料庫後,

isql -Usa -P -Sservername

1>dump tran database_name with truncate_only

2>go

3>sp_configure "allow update",1

4>go

5>update master..sysdatabases set status=0 where name='database_name'

6>go

7>shutdown with wait

8>go

重啟SYBASE後,日誌滿報錯資料庫正常了。

====================================================================================================================================

1.開啟查詢分析器,輸入命令
DUMP TRANSACTION 資料庫名 WITH NO_LOG
2.再開啟企業管理器--右鍵你要壓縮的資料庫--所有任務--收縮資料庫--收縮檔案--選擇日誌檔案--在收縮方式裡選擇收縮至XXM,這裡會給出一個允許收縮到的最小M數,直接輸入這個數,確定就可以了。

清除Log有兩種方法:

  1.自動清除法

  開放資料庫選項 Trunc Log on Chkpt,使資料庫系統每隔一段時間自動清除Log。此方法的優點是無須人工干預,由SQL Server自動執行,並且一般不會出現Log溢滿的情況;缺點是隻清除Log而不做備份。

  2.手動清除法

  執行命令“dump transaction”來清除Log。以下兩條命令都可以清除日誌:

dump transaction with truncate_only
dump transaction with no_log

  通常刪除事務日誌中不活躍的部分可使用“dump transaction with trancate_only”命令,這條命令寫進事務日誌時,還要做必要的併發性檢查。SYBASE提供“dump transaction with no_log”來處理某些非常緊迫的情況,使用這條命令有很大的危險性,SQL Server會彈出一條警告資訊。為了儘量確保資料庫的一致性,你應將它作為“最後一招”。

  以上兩種方法只??清除日誌,而不做日誌備份,若想備份日誌,應執行“dump transaction database_name to dumpdevice”命令。

PS:附一個更好的方法

先分離資料庫後,直接刪除日誌以後,再在查詢分析器裡用

exec sp_attach_single_file_db '資料庫名', '.mdf檔案路徑'
命令附加資料庫。 OVER.在別的地方看到的 不錯。