-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.在别的地方看到的 不错。