From Firebird 1.5 to 2.5How to migrate 75Gb database, with 564 tables, 5000+ stored procedures, 813 triggers, which is working 24x7, with ~400 users in less than 4 months
About IBSurgeonTools and consultingPlatinum Sponsor of FirebirdFounded in 2002: 9 years of Firebird recoveries and consultingBased in Moscow, RussiaIn Brazil – Firebase.com.brwww.ib-aid.comwww.ibsurgeon.com
TeamOur chiefsOur consultantsYemanovPeshkoffKhorsun
About Profitmedhttp://www.profitmed.net/Pharmaceutical distributor Russia24x7 work mode for 2 warehouses (16000 sqm + 7000 sqm) 12x7 work mode for office400 peak users  75 Gb database size64 Gb RAM, RAID 10 (Dell Storage), Xeon 4x6 cores
Why to migrate?From Firebird 1.5Old (2004), no professional supportBad memory management for huge queriesSlow garbage collection (1.5 hour+)Slow backup (2 hours)Firebird Classic 1.5 [actually] does not use more than 6 CPU coresAll together = SLOW.
Simple approach is impossibleThe only available timeframe for switch to the new version – Christmas & New Year Eve
Special approach needed
Infrastructure for migration2 servers (similar)Production is 64Gb RAM, Dell StorageTest is 32Gb RAM, RAID1Tools to verify the migrationSQL queries compatibilitySQL queries plans - performance
StepsPrepare metadataTest convert data to 2.5Application migrationCheck SQL queries in applications for compatibility, Change SQLs if necessaryCheck execution plans of SQL queriesChange plans if necessaryTest runFinal run
Step 1: Prepare metadataExtract metadata from Firebird 1.5 to scriptIsql –x  (or using GUI tools)Run metadata script in Firebird 2.5 Get output as “errors.txt” and analyze itPatch 1.5 database (should be compatible with 1.5 and 2.5), and external scriptFb15DbFb25DbMetadataTEXTFileApply MetadataExtract MetadataExport ErrorsErrors LogTEXT File
Errors in pure metadata – part 1Ambiguous field name between table X and table Y (need to use aliases!)Data type unknown. Blob sub_types bigger than 1 (text) are for internal use only. (wrong sub_type in BLOB definitions)Attempt to update read-only column (changes in AFTER UPDATE/AFTER DELETE triggers)~40%~10%~7%
Errors in pure metadata – part 2In 1.5 – function TRIM was in UDF, now it’s embedded function with different parametersExpression evaluation not supported. Strings cannot be multiplied in dialect 3 (explicit casting needed).New Keywords (GLOBAL)Other errors~5%~1%~1%
800+ errors2 weeks to fix Scripts:Fixes in existing Firebird 1.5 database Patch25.sql - External script to patch 2.5 database Next: we are ready to convert data to Firebird 2.5Summary of Step 1
Step 2: Test convert data to 2.5Backup patched 1.5 databaseRestore with –fix_fss_metadataand –fix_fss_data optionsApply Patch25.sql script to restored databaseBackup/restore under 2.5Backup – 2 hours, restore - 6 hours.
Summary of step 22 daysWe have database in 100% Firebird 2.5 compatible formatNext: need to check and change SQL queries in all our applications
Step 3: Application migrationCheck SQL queries in applications for compatibility, Change SQLs if necessaryCheck execution plans of SQL queriesChange plans if necessaryThis is the most complex step!
How to check SQL queries for compatibilityWe needed to log all SQL queries from all applicationsOwn-written applicationsClosed-source application
Tip: logging is complicatedMON$ tables does not help – they are snapshots (and in 2.1+ only) and make the heavy loadFBTrace API is 2.5+ only and it also loads the serverFBScanner is IBSurgeon’s commercial tool which analyze the network traffic and stores the full log, it’s the only true logging solution
FBScanner logged SQL queries Computer1FBScanner3050   ServerFirebird clients (applications), connected through TCPFirebird 3050Several workstations were run through FBScanner one by one to reduce performance impact and make log more “linear”.
All SQL queries were stored to the logFBScanner   Log databaseComplete SQL texts with parameters and (optionally) plans!
SQL log
To find incompatible SQLsWe need to “play” log to the copy of 2.5 databaseMake prepareTry to executeCatch exceptions/errors if anyLog SQL execution plansLog SQL execution timesFind the differences in plans and delays
FBScanner played the logFBScanner  Log databaseCopy of database (in 2.5 format)
Differences in plans and execution times between 1.5 and 2.5 are highlighted
Play log resultsWe had ~55000 queries to analyzeOnly 280 has different plans~400 has slower Execution time at 2.5 than 1.5~50 queries raised exceptionsOnly ~750 queries from 55000 required investigation.
Sorted log was exported to Excel
Plan problem example (simplified)select agb.eid, agb.kollast, agb.eid5, agb.first_eid, agb.did3, agb.did4, agb.marker, agb.place, agb.mnpfrom p101_ant_goods_balance agbwhere agb.ddate <= :i$ddate and agb.l800 = :i$l800 and agb.did3 = rf2_abs(3409) and agb.marker = :i$marker and agb.did <> :i$did2.5 PLAN (AGB INDEX (IDX$AGB_L800_DDDATE_ECON_EMP)) 1.5 PLAN (AGB INDEX (IDX$AGB_L800_DDDATE_ECON_EMP, IX$AGB_DID3))
Another problemsNew Firebird keywords in closed-sourced software	Was hacked UDF rFunc for 64-bit Windows and Linux
Results of migrationAt Firebird 2.5Better performance in queriesFast garbage collection (20 minutes instead of 1.5 hours)Backup time reduced (1.5 hour instead of 2 hours)Better use of multi-CPU hardware 64 bit version of Firebird availableEXECUTION STATEMENT and other SQL features
Optimization Pack “Rodizio” offerTo optimize databases we offer 1 year subscription to install as many as you need FBScanner+IBAnalyst+IBTM instancesThis instances will run indefinitely (no restrictions)Should be activatedSilent bundle is also possible, requires signing VAR agreementToday - R$800 (reg US$1800)
Thanks and ContactsQuestions?  Ask support@ib-aid.comBloghttp://FirebirdSurgeon.blogspot.comTwitterhttp://Twitter.com/ibsurgeonWebhttp://www.ib-aid.com

Firebird migration: from Firebird 1.5 to Firebird 2.5

  • 1.
    From Firebird 1.5to 2.5How to migrate 75Gb database, with 564 tables, 5000+ stored procedures, 813 triggers, which is working 24x7, with ~400 users in less than 4 months
  • 2.
    About IBSurgeonTools andconsultingPlatinum Sponsor of FirebirdFounded in 2002: 9 years of Firebird recoveries and consultingBased in Moscow, RussiaIn Brazil – Firebase.com.brwww.ib-aid.comwww.ibsurgeon.com
  • 3.
  • 4.
    About Profitmedhttp://www.profitmed.net/Pharmaceutical distributorRussia24x7 work mode for 2 warehouses (16000 sqm + 7000 sqm) 12x7 work mode for office400 peak users 75 Gb database size64 Gb RAM, RAID 10 (Dell Storage), Xeon 4x6 cores
  • 5.
    Why to migrate?FromFirebird 1.5Old (2004), no professional supportBad memory management for huge queriesSlow garbage collection (1.5 hour+)Slow backup (2 hours)Firebird Classic 1.5 [actually] does not use more than 6 CPU coresAll together = SLOW.
  • 6.
    Simple approach isimpossibleThe only available timeframe for switch to the new version – Christmas & New Year Eve
  • 7.
  • 8.
    Infrastructure for migration2servers (similar)Production is 64Gb RAM, Dell StorageTest is 32Gb RAM, RAID1Tools to verify the migrationSQL queries compatibilitySQL queries plans - performance
  • 9.
    StepsPrepare metadataTest convertdata to 2.5Application migrationCheck SQL queries in applications for compatibility, Change SQLs if necessaryCheck execution plans of SQL queriesChange plans if necessaryTest runFinal run
  • 10.
    Step 1: PreparemetadataExtract metadata from Firebird 1.5 to scriptIsql –x (or using GUI tools)Run metadata script in Firebird 2.5 Get output as “errors.txt” and analyze itPatch 1.5 database (should be compatible with 1.5 and 2.5), and external scriptFb15DbFb25DbMetadataTEXTFileApply MetadataExtract MetadataExport ErrorsErrors LogTEXT File
  • 11.
    Errors in puremetadata – part 1Ambiguous field name between table X and table Y (need to use aliases!)Data type unknown. Blob sub_types bigger than 1 (text) are for internal use only. (wrong sub_type in BLOB definitions)Attempt to update read-only column (changes in AFTER UPDATE/AFTER DELETE triggers)~40%~10%~7%
  • 12.
    Errors in puremetadata – part 2In 1.5 – function TRIM was in UDF, now it’s embedded function with different parametersExpression evaluation not supported. Strings cannot be multiplied in dialect 3 (explicit casting needed).New Keywords (GLOBAL)Other errors~5%~1%~1%
  • 13.
    800+ errors2 weeksto fix Scripts:Fixes in existing Firebird 1.5 database Patch25.sql - External script to patch 2.5 database Next: we are ready to convert data to Firebird 2.5Summary of Step 1
  • 14.
    Step 2: Testconvert data to 2.5Backup patched 1.5 databaseRestore with –fix_fss_metadataand –fix_fss_data optionsApply Patch25.sql script to restored databaseBackup/restore under 2.5Backup – 2 hours, restore - 6 hours.
  • 15.
    Summary of step22 daysWe have database in 100% Firebird 2.5 compatible formatNext: need to check and change SQL queries in all our applications
  • 16.
    Step 3: ApplicationmigrationCheck SQL queries in applications for compatibility, Change SQLs if necessaryCheck execution plans of SQL queriesChange plans if necessaryThis is the most complex step!
  • 17.
    How to checkSQL queries for compatibilityWe needed to log all SQL queries from all applicationsOwn-written applicationsClosed-source application
  • 18.
    Tip: logging iscomplicatedMON$ tables does not help – they are snapshots (and in 2.1+ only) and make the heavy loadFBTrace API is 2.5+ only and it also loads the serverFBScanner is IBSurgeon’s commercial tool which analyze the network traffic and stores the full log, it’s the only true logging solution
  • 19.
    FBScanner logged SQLqueries Computer1FBScanner3050   ServerFirebird clients (applications), connected through TCPFirebird 3050Several workstations were run through FBScanner one by one to reduce performance impact and make log more “linear”.
  • 20.
    All SQL querieswere stored to the logFBScanner   Log databaseComplete SQL texts with parameters and (optionally) plans!
  • 21.
  • 22.
    To find incompatibleSQLsWe need to “play” log to the copy of 2.5 databaseMake prepareTry to executeCatch exceptions/errors if anyLog SQL execution plansLog SQL execution timesFind the differences in plans and delays
  • 23.
    FBScanner played thelogFBScanner  Log databaseCopy of database (in 2.5 format)
  • 24.
    Differences in plansand execution times between 1.5 and 2.5 are highlighted
  • 25.
    Play log resultsWehad ~55000 queries to analyzeOnly 280 has different plans~400 has slower Execution time at 2.5 than 1.5~50 queries raised exceptionsOnly ~750 queries from 55000 required investigation.
  • 26.
    Sorted log wasexported to Excel
  • 27.
    Plan problem example(simplified)select agb.eid, agb.kollast, agb.eid5, agb.first_eid, agb.did3, agb.did4, agb.marker, agb.place, agb.mnpfrom p101_ant_goods_balance agbwhere agb.ddate <= :i$ddate and agb.l800 = :i$l800 and agb.did3 = rf2_abs(3409) and agb.marker = :i$marker and agb.did <> :i$did2.5 PLAN (AGB INDEX (IDX$AGB_L800_DDDATE_ECON_EMP)) 1.5 PLAN (AGB INDEX (IDX$AGB_L800_DDDATE_ECON_EMP, IX$AGB_DID3))
  • 28.
    Another problemsNew Firebirdkeywords in closed-sourced software Was hacked UDF rFunc for 64-bit Windows and Linux
  • 29.
    Results of migrationAtFirebird 2.5Better performance in queriesFast garbage collection (20 minutes instead of 1.5 hours)Backup time reduced (1.5 hour instead of 2 hours)Better use of multi-CPU hardware 64 bit version of Firebird availableEXECUTION STATEMENT and other SQL features
  • 30.
    Optimization Pack “Rodizio”offerTo optimize databases we offer 1 year subscription to install as many as you need FBScanner+IBAnalyst+IBTM instancesThis instances will run indefinitely (no restrictions)Should be activatedSilent bundle is also possible, requires signing VAR agreementToday - R$800 (reg US$1800)
  • 31.
    Thanks and ContactsQuestions? Ask support@ib-aid.comBloghttp://FirebirdSurgeon.blogspot.comTwitterhttp://Twitter.com/ibsurgeonWebhttp://www.ib-aid.com