《sqlite数据修复.docx》由会员分享,可在线阅读,更多相关《sqlite数据修复.docx(7页珍藏版)》请在三一办公上搜索。
1、sqlite数据修复一SQLite打开提示database disk image is malformed 网上说产生这种错误的原因有很多种,磁盘空间不足,还有就是写入数据过程中突然掉电等。 这种情况,如果数据还可以导出,那么就可以修复 sqlite Database_1.db SQLite version 3.6.2 Enter .help for instructions Enter SQL statements terminated with a ; sqlite .output “_temp.tmp” sqlite .dump sqlite .quit sqlite Database_
2、1.new.db SQLite version 3.6.2 Enter .help for instructions Enter SQL statements terminated with a ; sqlite .read “_temp.tmp” sqlite .quit 还有更快的方法,我还没用过: 另一种更快的修复方法 $echo “.dump” | sqlite3 old.db | sqlite3 new.db /直接将old.db修复为new.db 或者 sqlite3 newsfeed.db .dump newsfeed.sql sqlite3 newsfeed.dbPRAGMA
3、integrity_check; 获得提示 * in database main * Page 1518: btreeInitPage returns error code 11 On tree page 1566 cell 2: Child page depth differs On tree page 1566 cell 3: Child page depth differs SQL error: database disk image is malformed 可以尝试通过简单的导出导入方式对损坏的库文件作回复。 首先导出数据 sqlite3 my.sqlite3 sqlite.outp
4、ut tmp.sql sqlite.dump sqlite.quit 再倒入到一个新库中 sqlite3 mynew.sqlite3 sqlite.read tmp.sql sqlite.quit 这时新建的mynew.sqlite3一般可用。 三Sqlite数据库出现错误:database disk image is malformed 修复方法如下: D:workspacectrguangfadbsqlite3 ctrgf.db3 SQLite version 3.4.0 Enter .help for instructions sqlite .output _abctemp.tmp sq
5、lite .dump sqlite .quit D:workspacectrguangfadbsqlite3 abc.db3 SQLite version 3.4.0 Enter .help for instructions sqlite .read _abctemp.tmp sqlite .quit 四现象:我的程序负责写数据库,如果遇到断电或者突发情况导致数据没有写入完成,就会在数据库同目录下留下一个临时文件,用来保存数据库的状态,但是另一个人Java写的程序每次读的时候就会导致数据库损坏: sqlite Error: database disk image is malformed 原因
6、:因为他的程序使用的操作数据库的驱动版本太低,导致数据库损坏,更新驱动后问题解决。 =以下是网上搜的= 一般有几种原因: 1. sqlite数据库在写入时断点等,导致数据库里的结果被破坏。 2. sqlite数据库所存的磁盘空间不够。 3. 磁盘有坏磁道等 后来通过沟通发现服务器通过ulimit设置文件大小上限是400M,出问题时数据库大小刚好超过400M,所以应该是这个导致数据库写入失败,从而导致数据库损坏,用ulimit设置文件大小上限为4G,测试进行中。 sqlite初始化时设置 PRAGMA auto_vacuum = 1;删除记录后,数据库所占空间缩小; # SQLite有一个很严重
7、的缺点就是不提供Repair命令。 导致死亡提示database disk image is malformed 它的产生有很多种可能,比如,磁盘空间不足,还有就是写入数据过程中突然掉电等。 官方对产生原因的一些说明: http:/www.sqlite.org/lockingv3.html#how_to_corrupt sqlite my.sqlite3 sqlitePRAGMA integrity_check; 获得提示 * in database main * Page 1518: btreeInitPage returns error code 11 On tree page 1566
8、cell 2: Child page depth differs On tree page 1566 cell 3: Child page depth differs SQL error: database disk image is malformed 可以尝试通过简单的导出导入方式对损坏的库文件作回复。 首先导出数据 sqlite3 my.sqlite3 sqlite.output tmp.sql /有的是 .output “tmp.sql” sqlite.dump sqlite.quit 再倒入到一个新库中 sqlite3 mynew.sqlite3 sqlite.read tmp.sq
9、l /有的是 .read “tmp.sql” sqlite.quit 这时新建的mynew.sqlite3一般可用。 # 最近研究发现,当磁盘空间写满或写入了格式不正确的数据或在操作db过程中内存溢出,那么.db文件的镜像就会被破坏,这种情况下再去执行有关此db的操作,android就会把该db文件删除掉,如果db文件损坏了,可在adb shell下恢复其数据,做法如下: sqlite3 old.db(注:损坏的db文件) .output tmp.sql .dump .quit 然后读取数据到新的db sqlite3 new.db .read tmp.sql .quit # http:/www
10、.sqlite.org/faq.html#q21 (21) What is an SQLITE_CORRUPT error? What does it mean for the database to be malformed? Why am I getting this error? An SQLITE_CORRUPT error is returned when SQLite detects an error in the structure, format, or other control elements of the database file. SQLite does not c
11、orrupt database files, except in the case of very rare bugs (see DatabaseCorruption) and even then the bugs are normally difficult to reproduce. Even if your application crashes in the middle of an update, your database is safe. The database is safe even if your OS crashes or takes a power loss. The
12、 crash-resistance of SQLite has been extensively studied and tested and is attested by years of real-world experience by millions of users. That said, there are a number of things that external programs or bugs in your hardware or OS can do to corrupt a database file. Details can be found in the dis
13、cussions on the atomic commit and locking support in SQLite as well as in the mailing list archives. Your can use PRAGMA integrity_check to do a thorough but time intensive test of the database integrity. Your can use PRAGMA quick_check to do a faster but less thorough test of the database integrity
14、. Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate. Unfortunately, once humpty-dumpty falls off the wall, it is generally not possible to put him back together again. # PRAGMA comm
15、and 是一个特殊的命令。它用于修改 SQLite 库操作或查询库以取得内部数据 ? auto_vacuum ? automatic_index ? cache_size ? case_sensitive_like ? checkpoint_fullfsync ? collation_list ? compile_options ? database_list ? encoding ? foreign_key_list ? foreign_keys ? freelist_count ? fullfsync ? ignore_check_constraints ? incremental_vac
16、uum ? index_info ? index_list ? integrity_check ? journal_mode ? journal_size_limit ? legacy_file_format ? locking_mode ? max_page_count ? page_count ? page_size ? parser_trace ? quick_check ? read_uncommitted ? recursive_triggers ? reverse_unordered_selects ? schema_version ? secure_delete ? synchronous ? table_info ? temp_store ? user_version ? vdbe_listing ? vdbe_trace ? wal_autocheckpoint ? wal_checkpoint ? writable_schema sqlite pragma integrity_check; SQL error: database disk image is malformed