firebird database recovery: professional tools and ... · firebird database recovery: tools and...

29
Firebird Conference 2014 (c) IBSurgeon, 2014 1 Firebird database recovery: tools and techniques Alexey Kovyazin www.ib-aid.com www.ibase.ru

Upload: tranxuyen

Post on 22-Apr-2018

235 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 1

Firebird database recovery: tools and techniques

Alexey Kovyazin

www.ib-aid.comwww.ibase.ru

Page 2: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 2

Tools to fix corrupted Firebird database

● Standard tools: gfix + gbak● Third-party commercial tool:

IBSurgeon FirstAID: direct fix + extraction

● Let's consider details...

Page 3: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 3

Typical corruption «environment»

● No backups● No administrator● Unreliable hardware or wrong configuration of

hardware● Big database and 24/7 workmode – can’t do

backup/restore ● Corruption never happened before, or no

responsible person

Page 4: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 4

Behind the corruption

● Hardware failure● Administrators/developers failures● Server bugs● Mr. Murhy and his laws:)

Page 5: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 5

Corruption from user's point of view

● Unavailable database — i.e., cannot connect there, with various errors

● Errors while trying SELECT/UPDATE/INSERT/DELETE

● Low performance● «Something is wrong»

Page 6: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 6

Corruption from the server point of view

● Cannot build internal database image– System data lost?

– Transactions pages lost?

● Cannot read some records– Record is corrupted?

● Indices corruption

Page 7: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 7

Symptoms of corruptions

Corruptions appear at:

1.Users screen (“internal Firebird software consistency check” error message)

2.In firebird.log

Page 8: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 8

Heavy and Easy corruptions

•Easy corruptions

• Users data are corrupted (partially)

• User’s indices corrupted

•Heavy corruptions • System data are damaged (We can’t read users data!)

Page 9: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 9

Examples

● Cannot find TIP page– Lost TIP pages

– Wrong transaction number in record header

● What we can do– Recreate TIP

– Delete records

Page 10: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 10

Wrong record length

● Record length does not correspond to declared size– Must be deleted

Page 11: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 11

Attempted to read more segments..

● BLOB corruption — loss of BLOB parts● What we can do?

– Export as is

– Delete corrupted BLOB

Page 12: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 12

Cannot find record fragment

● Fragment of record disappeared– Usually on another data page

● We can only delete remained part

Page 13: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 13

Nbackup delta won't merge

● Database delta won't merge● What we can do

– Delete delta (it hurts!)

– Manual merge with special tools

– Export data

Page 14: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 14

Fixing

Page 15: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 15

Standard means

•Stop Firebird server.

•Make a copy of Firebird database.

•Start Firebird server and run the following commands:

gfix.exe -v -full

gfix.exe -mend –ig

gbak -b –g -v

•If backup completed successfully, restore database: gbak -c -v -user SYSDBA -pass masterkey path_to_backup path_to_database

Page 16: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 16

Not very well known, but still standard means

1.Run them all, even if gfix shows errors.

2.Always use switch –ig for gbak to ignore checksum errors

3.Always use switch –g for gbak to suppress garbage collection (and to workaround index errors)

4.Use –v switch to have detailed output

5. Set database to read_only with gfix -mode read_only

Page 17: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 17

Restore errors

•After fixing corruptions it's a often to see "Cannot commit index" error at restore step. •In Firebird 2.0 and later this comes as a warning and database will be not brought on-line

How to workaround

● IBDataPump

– Bug with circular links● FirstAID Extractor

Page 18: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 18

Effectiveness

Gbak+Gfix can recover almost all easy corruptions

What they cannot fix:

● Heavy corruptions with a lot of losses ● System data corruptions

Page 19: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 19

IBSurgeon Tools

Page 20: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 20

IBSurgeon Tools for Recovery and data protection

● FirstAID– Direct

– Extractor

● FBDataGuard– Protection

– Backups

Page 21: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 21

IBSurgeon FirstAID: Direct

● Scan internal structure and finds inconsistencies● Replace/restore lost system pages where it is

possible● Delete wrong pages and dead records

● Fast!● Effective for user's data corruptions

Page 22: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 22

IBSurgeon FirstAID: Extractor

● Reads metadata from database and read records bypassing server– Free preview of records is available

● Export all good records to the new database● Resolve dependencies

– Foreign Keys, Triggers, UDFs

● Speed is 1Gb/hour● Very effective

Page 23: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 23

External metadata

● Extractor can borrow metadata from good healthy database with the same structure and export data from corrupted one, even if all system data lost

Page 24: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 24

Metadata repository

Page 25: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 25

Increased recovery rate

● Metadata repository increase recovery rate up to 99%

● FBDataGuard is a tool to create metadata repository

Page 26: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 26

Better prevent when fix!

● FBDataGuard vs FirstAID?● Easy licensing options● Special offer for attendees of Firebird

Conference 2014

Page 27: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 27

Thanks to sponsors!

Page 28: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 28

About IBSurgeon

● Firebird and InterBase recovery and optimization: tools and services

● Platinum sponsor of Firebird Foundation

● Since 2002● Moscow, Russia

Page 29: Firebird database recovery: professional tools and ... · Firebird database recovery: tools and techniques Alexey Kovyazin  . ... Delete wrong pages and dead records

Firebird Conference 2014 (c) IBSurgeon, 2014 29

Thank you!

● Www.ib-aid.com● Www.ibsurgeon.com● [email protected]