I have a 200 GB Firebird database (created with Firebird 2.1.3, currently running 2.1.5), and it appears to be corrupted. When I try to do a backup I get:
database file appears corrupt <>
wrong page type
page 0 is wrong type (expected 0 found 1)
gds_get_segment failed
wrong page type
page 0 is wrong type (expected 0 found 1)
gds_get_segment failed
Recover a Corrupt Database. The option required to fix a corrupted database is the gfix -mend command. However, it cannot fix all problems and may result in a loss of data. It all depends on the level of corruption detected. The command is: gfix -mend databasename. This causes the corruptions in data records to be ignored. I have a 200 GB Firebird database (created with Firebird 2.1.3, currently running 2.1.5), and it appears to be corrupted. When I try to do a backup I get: database file appears corrupt wrong page type page 0 is wrong type (expected 0 found 1) gdsgetsegment failed. Gfix ends with a. How can I fix it?
gfix
ends with adeadlock
How can I fix it?
UPDATE
While this particular database wasn't fixed, i guess the solution is try IB FirstAID.
Recommended reading:
Sergei Ousynin
Sergei OusyninSergei Ousynin
2 Answers
Here's a short step-by-step walkthrough:
- disconnect users and disable incoming connections to the database
- make a copy of database file (or two copies) and work on that
- use GFIX with -v option to validate the database file
- use GFIX with -v and -f to do full validation
If problem is not too serious, you can try to backup the broken db and restore under a new name:
- use GFIX -mend to prepare corrupt database for backup
- use GBAK -b -g to backup the database. -g disables garbage collection
- use GBAK -c to restore backup to a new database.
If you succeed, you have fixed the problem and have a functional database. If not, you can try to create an empty database with the same structure and pump the data to it .
One of the reasons why backup or restore can fail is if some broken database triggers exist, and prevent connection to the database. For example, a database trigger might use some table which has a broken index, etc. To work around this, connect to database with isql tool using -nodbtriggers option and then disable those triggers. You can enable them later when you fix other problems and get a working database again.
Another reason restore might fail is when you have broken data, so some of validity constraints (check constraints, etc.) cannot be satisfied. In this case, you can try to restore your database using -N[O_VALIDITY] command switch to gbak.
If you're interested in a more detailed information of the process of fixing the database, as well as explanation of some types of corruption, take a look at the following page:
If all fails, you can try IBSurgeon tool, which is able to fix most problems and extract data. Also, IBSurgeon's website has a detailedexplanation of causes of database corruption and ways to fix it:
check this guide http://www.firebirdfaq.org/faq324/
Shimon Gb GibraltarShimon Gb Gibraltar
You can open the database file with a hex editor and fix the wrong page type from 0 to 1 as explained below. It worked for me.http://forums.devshed.com/firebird-sql-development-61/corrupt-database-gifix-doesnt-fix-948653.html
Victor IonescuVictor Ionescu