Tim_Odom has asked for the wisdom of the Perl Monks concerning the following question:

Several years ago I wrote a script that used DB_File to manipulate a small database. The only reason I really did this was to simplify things rather than using a flat file. It has however come back to bite me. The server the script was hosted on got upgraded and now when trying to tie the database I get the error "File Exists". Here's how I'm trying to tie it:
tie (%DATABASE, "DB_File", "$OPTIONS{database_dir}/database.db", O_RDW +R|O_CREAT, 0755, $DB_BTREE) || die "Cannot open database: $!\n";
Can anyone tell me why this is happening? I've got a lot of data in these databases that unfortunately is not backed up in an alternate form and would like to recover it. Any suggestions would be appreciated.

Replies are listed 'Best First'.
Re: Problem Tieing a database created with DB_File
by tilly (Archbishop) on Jun 28, 2003 at 04:31 UTC
    It might be a BTREE. It might be a hash. You might have used another dbm than BerkeleyDB.

    I would make a copy of the file. Then on the copy try DB_File with different options, then SDBM_File, then start looking for more esoteric possibilities. The list of common ones is fairly short, with some experiment you should find it.

    And then when you do..make sure that you have a text backup!

      Looking at that code there, I remember that it was a BTREE and I could almost swear it was using BerkeleyDB... I'm thinking that the BerkeleyDB verson changed and that's why I can't access the file... Unfortunately, I'm not sure how to go about checking any of the other options mentioned above...
Re: Problem Tieing a database created with DB_File
by Zaxo (Archbishop) on Jun 28, 2003 at 05:03 UTC

    Do you recall which dbm the files were created for? It sounds like the new DB_File is linked to one which imposes O_EXCL. Try to find out which dbm you had, and try the explicit dbm module to read and translate to the new regime.

    After Compline,
    Zaxo

Re: Problem Tieing a database created with DB_File
by PodMaster (Abbot) on Jun 29, 2003 at 02:13 UTC
    What OS are you on? Did you change the BTREE sort order?

    I suggest you acquire berkeley db (sleepycat.com), or at least the following utilities that come with it

     db_archive.exe
     db_checkpoint.exe
     db_deadlock.exe
     db_dump.exe
     db_load.exe
     db_printlog.exe
     db_recover.exe
     db_stat.exe
     db_upgrade.exe
     db_verify.exe
    
    and try them out. Like I quote in Re: Re: DBM Portability?:
    Note: The database file format has changed multiple times in Berkeley DB version 2, 3 and 4. If you cannot recreate your databases, you must dump any existing databases with either the db_dump or the db_dump185 utility that comes with Berkeley DB. Once you have rebuilt DB_File to use Berkeley DB version 2 or greater, your databases can be recreated using db_load. Refer to the Berkeley DB documentation for further details.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      And if you can't get this to work for you, Sleepycat is a company, and will certainly be willing to try variations out and return it to you in a more readable format for an appropriate (I will bet fairly reasonable) fee.
Re: Problem Tieing a database created with DB_File
by Anonymous Monk on Jun 28, 2003 at 20:44 UTC
    I had a similar problem uploading a pre-made berkeley DB (created locally using Macperl) to my web site. Same program on both platforms, but I suspect different versions of perl and or DB_File module. I suggest finding someone with this earlier combination and installing it there (maybe your webhost can tell you what the previous version was). My solution was to convert the DB to flat-file, upload it, and then convert to DB_File on the server. Maybe the reverse will work for you? Tod.