免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: wf8801
打印 上一主题 下一主题

误删除日志文件的问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2006-02-17 17:26 |只看该作者
2> select * from master..sysuages where id=cwbase3
3> go
Msg 208, Level 16, State 1:
Server 'sybase1', Line 2:
master..sysuages not found. Specify owner.objectname or use sp_help to check
whether the object exists (sp_help may produce lots of output).
老大,我加入你的qq可以吗?我很着急!!!

论坛徽章:
4
2015年亚洲杯之阿联酋
日期:2015-03-10 10:32:022015年亚洲杯之阿曼
日期:2015-03-10 14:53:222015亚冠之水原三星
日期:2015-07-18 15:40:262015亚冠之塔什干棉农
日期:2015-07-27 20:52:05
12 [报告]
发表于 2006-02-17 17:44 |只看该作者
select * from master..sysusages where id=cwbase3
go
I'm sorry for make a mistake.qq can not work well in my company,so here could be more efficient.

论坛徽章:
0
13 [报告]
发表于 2006-02-17 17:46 |只看该作者
1> select * from master..sysusages where id="cwbase3"
2> go
Msg 207, Level 16, State 4:
Server 'sybase1', Line 1:
Invalid column name 'id'.
没关系,多谢了!!!

论坛徽章:
4
2015年亚洲杯之阿联酋
日期:2015-03-10 10:32:022015年亚洲杯之阿曼
日期:2015-03-10 14:53:222015亚冠之水原三星
日期:2015-07-18 15:40:262015亚冠之塔什干棉农
日期:2015-07-27 20:52:05
14 [报告]
发表于 2006-02-17 17:52 |只看该作者
select * from master..sysusages where id=db_id("cwbase3")
go

论坛徽章:
0
15 [报告]
发表于 2006-02-17 18:01 |只看该作者
输入的命令以及提示如下:
1> select * from master..sysusages where id="cwbase3"
2> go
Msg 207, Level 16, State 4:
Server 'sybase1', Line 1:
Invalid column name 'id'.
我输入的命令错了吗?如果错了,麻烦您请直接写出正确的命令可以吗?

[ 本帖最后由 wf8801 于 2006-2-17 18:05 编辑 ]

论坛徽章:
0
16 [报告]
发表于 2006-02-17 18:21 |只看该作者
1> select * from master..sysusages where dbid=8
2> go
dbid   segmap      lstart      size        vstart      pad    unreservedpgs
         crdate                     
------ ----------- ----------- ----------- ----------- ------ -------------
         --------------------------
      8           7           0      512000   587202560   NULL        509403
                Apr 28 2004  2:28PM

(1 row affected)
1> select * from master..sysusages where dbid=9
2> go
dbid   segmap      lstart      size        vstart      pad    unreservedpgs
         crdate                     
------ ----------- ----------- ----------- ----------- ------ -------------
         --------------------------
      9           7           0      512000   620756992   NULL        509403
                Apr 28 2004  2:28PM

(1 row affected)
1>
其中,8是数据库cwdata3的id;9是cwlog3

论坛徽章:
0
17 [报告]
发表于 2006-02-18 08:17 |只看该作者
1> select * from sysusages where dbid=4     
2> go
dbid   segmap      lstart      size        vstart      pad    unreservedpgs
         crdate                     
------ ----------- ----------- ----------- ----------- ------ -------------
         --------------------------
      4           3           0      256000    50331648   NULL        251119
                Jan  8 2006 10:16PM
      4           4      256000       51200    67108864   NULL         51000
                Jan  8 2006 10:16PM
      4           4      307200       51200   117440512   NULL         51000
                Feb 17 2006  6:51PM

(3 rows affected)
1> select * From sysdevices where low in (select vstart from sysusages where dbid=4)
2> go
low         high        status cntrltype name                          
         phyname                                                                                                                        
         mirrorname                                                                                                                     
----------- ----------- ------ --------- ------------------------------
         -------------------------------------------------------------------------------------------------------------------------------
         -------------------------------------------------------------------------------------------------------------------------------
    50331648    50587647  16386         0 test_data                     
         /syb_devices/test.dat                                                                                       
         NULL                                                                                                                           
    67108864    67160063  16386         0 test_log                       
         /syb_devices/test.log                                                                                       
         NULL                                                                                                                           
   117440512   117491711  16386         0 test_log1                     
         /syb_devices/test1.log                                                                                       
(3 rows affected)

The test db has two log devices and I deleted test.log from os, then made the following changes to system tables, it seems  everything is fine, you may lose some transactions.

1> begin tran
2> go
1> delete from sysusages where dbid=4 and vstart=(select low from sysdevices where name='test_log')
2> go
(1 row affected)
1> delete from sysdevices where name='test_log'
2> go
(1 row affected)
1> commit
2> go

论坛徽章:
0
18 [报告]
发表于 2006-02-18 15:52 |只看该作者
原帖由 2BeSybPro 于 2006-2-18 08:17 发表
1> select * from sysusages where dbid=4     
2> go
dbid   segmap      lstart      size        vstart      pad    unreservedpgs
         crdate                     
------ ----------- -- ...



首先向您表示衷心的感谢!!!
事关重大,我没敢轻易作!有几个问题向您咨询:
1、dbid=4,其中的4,是我误删除了日志文件的数据库的id吗?
2、如果是,是否是在用sp_helpdb查询出来的结果?
3、我查询的结果是7。
4、如果是7,我按您的提示,做了前两步,显示结果如下:
1>
2> select * from sysusages where dbid=7
3> go
dbid   segmap      lstart      size        vstart      pad    unreservedpgs
         crdate                     
------ ----------- ----------- ----------- ----------- ------ -------------
         --------------------------
      7           3           0     3840000   134217728   NULL       1354765
                Nov 30 2005 11:30AM
      7           4     3840000      768000   141897728   NULL        765000
                Nov 30 2005 11:30AM
      7           4     4608000     1536000   150994944   NULL       1530000
                Nov 30 2005 11:30AM
      7           4     6144000      512000   201326592   NULL        510000
                Nov 30 2005 11:30AM
      7           4     6656000     2048000   100663296   NULL       2040000
                Feb 17 2006  3:21PM

(5 rows affected)
1> select * From sysdevices where low in (select vstart from sysusages where dbid=7)
2> go
low         high        status cntrltype name                          
         phyname                                                                                                                        
         mirrorname                                                                                                                     
----------- ----------- ------ --------- ------------------------------
         -------------------------------------------------------------------------------------------------------------------------------
         -------------------------------------------------------------------------------------------------------------------------------
   134217728   143433727      2         0 cwdata3                       
         /data/cwdata/cwdata3.dat                                                                                                      
         NULL                                                                                                                           
   150994944   154066943      2         0 cwlog3                        
         /data/cwdata/cwlog3.dat                                                                                                        
         NULL                                                                                                                           
   201326592   202350591      2         0 cwlog3a1                     
         /data/cwdata/cwlog3a1.dat                                                                                                      
         NULL                                                                                                                           
   100663296   104759295      2         0 cwlog3a2                     
         /data/cwdata/cwlog3a2.dat                                                                                                      
         NULL                                                                                                                           

(4 rows affected)
1>
其中,cwlog3a2是我在误删除了cwlog3.dat文件后,马上扩充的日志空间。我可以接着做下去吗?对我的数据库会后影响吗?
还有,为什么你的数据库日志文件显示的是*.log,而我的显示的是*.dat?

[ 本帖最后由 wf8801 于 2006-2-18 15:58 编辑 ]

论坛徽章:
0
19 [报告]
发表于 2006-02-19 01:36 |只看该作者
设备文件的后缀取什么都可以.
我想问一下你是在数据库运行的时候能删除日志设备文件吗?能删的掉吗?

如果能用bcp的话先用bcp把所有的数据先导出来再做其它操作.

论坛徽章:
0
20 [报告]
发表于 2006-02-19 03:35 |只看该作者
The dbid 4 was the db for my testing purpose, you can find your dbid:
select db_id('your_db_name')

You better rebuild your db, please bcp out all your data and extract your db schema through DBArtisan before you shutdown your server!!!
There's problem after I reboot server in my test environment:
1> use testdb
2> go
Msg 921, Level 14, State 1:
Server 'HERO', Line 1:
Database 'testdb' has not been recovered yet - please wait and try again

Please see below the steps for reference, or seek help from Sybase.
1. Save old *.dat files and for raw devices save device file using dd command.
2. Create a new server.
3. Save master.dat.
4. Load old master.
5. bcp out syslogins, sysloginroles, sysservers.
6. Run select * from sysusages where dbid = <dbid> order by lstart. Execute sp_helpdevice and get the device name,physical name and size.
7. Create database ddl for this database.
8. shutdown server.
9. Replace master.dat file from step3
10. Restart server. This will start server with a fresh master device.
11. Create a new devices same as found in step 6.
12 Using ddl from step7 create database
13. Shutdown server.
14. Replace *.dat files for this database ( as Log.dat file is not available from old so keep this one as it is).
15. restart server.
16. If there is no error then goto step 24.
17. Else update sysdatabases set status = -32768 where name = "<dbname>"
18. execute sp_role "grant","sybase_ts_role",sa
19 . shutdown and restart server.
20. execute dbcc traceon(3604)
21. execute dbcc rebuild_log(dbid,1,1)
22. update sysdatabases set status = 0 where name = "<dbname>"
23. shutdown and restart server.
24. edit syslogins.bcp file and remove the first line and bcp into master..syslogins table.
25 edit sysloginroles.bcp file and remove all tile having first column = 1 and bcp into master..sysloginroles table.
26. If sysservers.bcp file has more server than select * from master..sysservers then add remaining server using sp_addserver command.
27. Shutdown and restart server.
28. For this database then run dbcc checkdb/checkalloc/checkcatalog and fix other error.
29. If your application still needs old dbid the you may need to update sysdatabases set dbid = <old_dbid> where name = "dbname" also update sysusages set dbid = <old_dbid> where dbid = <current_dbid> and then shutdown and recycle server. This is an optional step only required if necessary for the application otherwise ignore this step.


Procedure - 2
=============

If you have enough additional disk space and master device is fine and able to start server.
Start server in single user mode.

First bcp out sysdatabases and sysusages using -c option of bcp.

1. select name,dbid,status from sysdatabases. -- save this result.
2. Create a new database exactly same as the one having problem.
3. select name,dbid from sysdatabases where name = "newdb"
4. delete sysdatabases where name = "newdb"
5. delete sysusages where dbid = <dbid for newdb> and segmap != 4 -- Basically remove all entries for data and keep entries for logs from sysusages for this newdb.
6. delete sysusages where dbid = <dbid for bad_dbname> and segmap = 4 -- Remove entries for bad logs for bad_dbname
7. update sysusages set dbid = <dbid for bad_dbname> where dbid = <dbid for newdb> -- This would map to new good log device.
8. Shutdown and restart server.
9. If there is no error then goto step 17.
10. Else update sysdatabases set status = -32768 where name = "<bad_dbname>"
11. execute sp_role "grant","sybase_ts_role",sa
12. shutdown and restart server.
13. execute dbcc traceon(3604)
14. execute dbcc rebuild_log(dbid,1,1)
15. update sysdatabases set status = < old_status from step 1 > where name = "<bad_dbname>"
16. Shutdown and restart server.
17. For this database run dbcc checkdb/checkalloc/checkcatalog and fix other error.
18. You may remove unused devices using sp_dropdevice command.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP