Forum Stats

  • 3,768,730 Users
  • 2,252,841 Discussions


How to delete jdb files at runtime?

527078 Member Posts: 33
edited Aug 31, 2006 8:47AM in Berkeley DB Java Edition
My problem description is, i have to do complete index will be performed by creating a new empty index and adding content data to that (working index). Searches will continue to use the old (active) index. Once the index process is complete, the working and active indexes are swapped and the working index can be removed in preparation for the next complete analysis.

How can i remove jdb files at runtime without using ? [ According to the ejb specs an ejb should not try to use package to attempt to access a file ].




  • Hi Katta,

    The *.jdb files contain the environment (that is, multiple databases including the JE internal databases) and the cleaner will delete them automatically. So you shouldn't really think about deleting those. Rather, I think you should approach the problem by putting the new index in a separate JE Database and then deleting the old JE Database once the new one is populated.

    Does that make sense?

    Charles Lamb
  • 527078
    527078 Member Posts: 33
    Hi Charles ,

    I have implemented as your suggested way. I removed the old JE Database once new index (separate JE Database) created using env.removeDatabase() method. It's deleted the databse but *.bdb files not deleted(How can i reclaim the disk space). The cleaner is not deleting the files. Is cleaner will work without closing Environment. Do I need to use any methods to delete *.bdb files?

    JEConnection jeConnection = null;
    Environment env=null;
    jeConnection = getConnection(OldJEEnvHome);

    env = jeConnection.getEnvironment();

    Database index, blocks;

    index = jeConnection.openDatabase("__index__", null);
    blocks = jeConnection.openDatabase("__blocks__", null);

    String dbName1 = index.getDatabaseName();
    String dbName2 = blocks.getDatabaseName();

    Directory indexDir = new JEDirectory(null, index, blocks);


    env.removeDatabase(null, dbName1);
    env.removeDatabase(null, dbName2);

    } catch (Exception e)
    { // TODO: handle exception

    public JEConnection getConnection(String dbEnvHome)
    throws NamingException, JEException

    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setConfigParam("je.cleaner.expunge", "true");

    InitialContext iniCtx = new InitialContext();
    Context enc = (Context) iniCtx.lookup("java:comp/env");
    Object ref = enc.lookup("ra/JEConnectionFactory");
    JEConnectionFactory dcf = (JEConnectionFactory) ref;
    JEConnection dc = dcf.getConnection(dbEnvHome, envConfig);
    return dc;


  • Charles Lamb
    Charles Lamb Member Posts: 836
    Hi Katta,

    The log files will eventually be cleaned. Here is an FAQ entry that may be useful. Note that a checkpoint must occur before the log files are actually deleted.

    You can also invoke the cleaner manually to force immediate cleaning. See the javadoc for cleanLog here:


    Charles Lamb
This discussion has been closed.