dbTalk Databases Forums  

Compacting a database

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Compacting a database in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Naveen
 
Posts: n/a

Default Compacting a database - 05-30-2006 , 01:35 AM






hi,
I am using a DB_RECNO method for storing 1 million of data. So the
database size is 45Mb. After when I delete 2 Lakh record the database
size remains the same. Why is this so??

Is there any method by which I can compact this database. Please
suggest me a way with an example if possible.

I came to know about db->compact(). But when I used it I get an
error." error: 'struct __db' has no member named 'compact' ".

With Regards

Naveen Gopi


Reply With Quote
  #2  
Old   
Mike
 
Posts: n/a

Default Re: Compacting a database - 05-31-2006 , 10:48 AM






Naveen,

When a record is deleted from a database the space from that record is
generally available for use by records that would fall on the same page
as the deleted record. If all records on a page are deleted that page
is put on a free list in the file (unless it happens to be the last
page of the file, in which case it is returned to the file system).
Pages on the free list are availble to be used by any database in the
file. The DB->compact method is available in release 4.4. I suspect
you are using an eariler release.

Michael Ubell
Sleepycat Software.


Reply With Quote
  #3  
Old   
Naveen
 
Posts: n/a

Default Re: Compacting a database - 06-01-2006 , 04:18 AM




Mike wrote:
Quote:
Naveen,

When a record is deleted from a database the space from that record is
generally available for use by records that would fall on the same page
as the deleted record. If all records on a page are deleted that page
is put on a free list in the file (unless it happens to be the last
page of the file, in which case it is returned to the file system).
Pages on the free list are availble to be used by any database in the
file. The DB->compact method is available in release 4.4. I suspect
you are using an eariler release.

Michael Ubell
Sleepycat Software.
Hi Michael,
Am using the latest version of Berkeley DB 4.4.20 and
I found the compact member in the db.h header file.
I am still getting the error everytime. Why is it so??



Reply With Quote
  #4  
Old   
Florian Weimer
 
Posts: n/a

Default Re: Compacting a database - 06-01-2006 , 07:01 AM



* Naveen:

Quote:
Am using the latest version of Berkeley DB 4.4.20 and
I found the compact member in the db.h header file.
It's likely that your compiler picks up the wrong version of the file.
Try to specify "-I/opt/BerkeleyDB4.2/include" (or whatever path you
use) on the compiler command line.


Reply With Quote
  #5  
Old   
Naveen
 
Posts: n/a

Default Re: Compacting a database - 06-02-2006 , 05:22 AM




Florian Weimer wrote:
Quote:
* Naveen:

Am using the latest version of Berkeley DB 4.4.20 and
I found the compact member in the db.h header file.

It's likely that your compiler picks up the wrong version of the file.
Try to specify "-I/opt/BerkeleyDB4.2/include" (or whatever path you
use) on the compiler command line.
Thanks Florian. It worked !!!!!!!!!! But I found another problem, when
i execute the program the open database fails and shows unknown error
!!!!! But when I remove compact() function and then compile as usual(
gcc -ldb pgmname) it works. !!! Why is it like that ??

#include<assert.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<gendata.h>
#include<Tdate.h>
#include<gettime.h>
#define SIZE 15
#include "db.h"
typedef struct my_struct
{
char stored[SIZE];
char dateTime[30];
}MY_STRUCT;

int main()
{
DBT key,data;
DB *dbp;
int ret;

MY_STRUCT user;
int i=1,j,pmkey=0;
double first=0,second=0,third=0;
char **str;char *date;
str=getString(str,SIZE-1,9);

assert(db_create(&dbp,NULL,0)==0);

ret=dbp->open(dbp,NULL,"mydb.db",NULL,DB_BTREE,DB_CREATE,0 );

if(ret!=0)
{
fprintf(stderr,"Error opening database :%s\n",db_strerror(ret));
exit(-1);
}

for(i=1;i<=1000000;i++)
{
printf("i : %d\n", i);

pmkey=getNumber(1000000);
// printf("\nRandom number is :%d",pmkey);
if(pmkey !=0)
{

first=getTime();
memset(&key,0,sizeof(DBT));
memset(&data,0,sizeof(DBT));

key.data=&i;
key.size=sizeof(int);


ret=dbp->del(dbp,NULL,&key,0);
second=getTime();

if(ret!=0)
{
dbp->err(dbp,ret,"\n data already exist");
}
else
{
third+=(second-first);
// printf("\nRecord Number :%d inserted",i);
}
}
else
i--;
}

dbp->compact(dbp,NULL,NULL,NULL,NULL,0,NULL);
printf("\nTotal time elapsed for putting the record is :%lf",third);
if(dbp!=NULL)
{
dbp->close(dbp,0);
}
return 0;

}



Reply With Quote
  #6  
Old   
Florian Weimer
 
Posts: n/a

Default Re: Compacting a database - 06-02-2006 , 08:22 AM



* Naveen:

Quote:
Florian Weimer wrote:
* Naveen:

Am using the latest version of Berkeley DB 4.4.20 and
I found the compact member in the db.h header file.

It's likely that your compiler picks up the wrong version of the file.
Try to specify "-I/opt/BerkeleyDB4.2/include" (or whatever path you
use) on the compiler command line.

Thanks Florian. It worked !!!!!!!!!! But I found another problem, when
i execute the program the open database fails and shows unknown error
!!!!! But when I remove compact() function and then compile as usual(
gcc -ldb pgmname) it works. !!! Why is it like that ??
You probably need to specify the correct path to the Berkeley DB
library, using "-L/opt/BerkeleyDB4.2/lib".


Reply With Quote
  #7  
Old   
Naveen
 
Posts: n/a

Default Re: Compacting a database - 06-03-2006 , 04:02 AM




Florian Weimer wrote:
Quote:
* Naveen:

Florian Weimer wrote:
* Naveen:

Am using the latest version of Berkeley DB 4.4.20 and
I found the compact member in the db.h header file.

It's likely that your compiler picks up the wrong version of the file.
Try to specify "-I/opt/BerkeleyDB4.2/include" (or whatever path you
use) on the compiler command line.

Thanks Florian. It worked !!!!!!!!!! But I found another problem, when
i execute the program the open database fails and shows unknown error
!!!!! But when I remove compact() function and then compile as usual(
gcc -ldb pgmname) it works. !!! Why is it like that ??

You probably need to specify the correct path to the Berkeley DB
library, using "-L/opt/BerkeleyDB4.2/lib".
Yes, thats working .... But now I have found two files of db.h...One is
the older version and other is the new one.

If i compile with the latest version( compact() included in file ) its
success, but when I execute db_open() fails showing UNKNOWN ERROR.
Why is this so?? i have put the source code in earlier post.....

Please help me to find a solution



Reply With Quote
  #8  
Old   
Florian Weimer
 
Posts: n/a

Default Re: Compacting a database - 06-03-2006 , 08:30 AM



* Naveen:

Quote:
Yes, thats working .... But now I have found two files of db.h...One is
the older version and other is the new one.
You also need the correct copy of libdb.a. Usually, this means that
you need to change the linker search path with "-L".


Reply With Quote
  #9  
Old   
Naveen
 
Posts: n/a

Default Re: Compacting a database - 06-04-2006 , 02:13 AM




Florian Weimer wrote:
Quote:
* Naveen:

Yes, thats working .... But now I have found two files of db.h...One is
the older version and other is the new one.

You also need the correct copy of libdb.a. Usually, this means that
you need to change the linker search path with "-L".
Thanks Florian, its all working...........thanks a lot



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.