简体   繁体   English

为什么Derby数据库占用这么多空间?

[英]Why does a Derby database take up so much space?

I am new to databases and I love how easy it is to get data from a relational database (such as a Derby database). 我是数据库新手,我喜欢从关系数据库(例如Derby数据库)中获取数据有多么容易。 What I don't like is how much data one takes up; 我不喜欢一个人要占用多少数据。 I have made a database with two tables, written a total of 130 records to these tables (each table has 6 columns), and the whole relational database gets saved in the system directory as a folder that houses a total of approximately 1914014 bytes! 我已经建立了一个包含两个表的数据库,向这些表总共写入了130条记录(每个表有6列),并且整个关系数据库都保存在系统目录中,作为一个文件夹,总共可以容纳1914014个字节! (Assuming that I did the arithmetic right....) What the heck is going on to cause such a huge request of memory?! (假设我正确地执行了算术运算……。)到底是什么引起了如此巨大的内存请求? //I also notice that there is a log1.dat file in log folder that takes up exactly 1MB of data. //我还注意到, log文件夹中有一个log1.dat文件,该文件恰好占用1MB的数据。 I looked into this file via Notepad++, and saw that it was mostly NULL characters. 我通过Notepad ++查看了此文件,发现它主要是NULL字符。 What is that all about? 这是怎么回事?

Derby need to keep track on your database data, the redo logs and transactions so your database is in a consistent state and can recover even from pc crashes. Derby需要跟踪数据库数据,重做日志和事务,以便数据库处于一致状态,甚至可以从PC崩溃中恢复。 Also he creates most files with a fixed size (like 1MB) to ensure he did not need to increase the file size later on (performance issues and to not fragment his files to much). 此外,他还创建了大多数具有固定大小(例如1MB)的文件,以确保以后不需要增加文件大小(性能问题并且不会将文件分割成很多)。

Over the runtime or when stopping, Derby will clean up some of this files or regroup them and free space. 在运行时或停止时,Derby将清除其中一些文件或将它们重新组合并释放空间。

So overall the space and the files are the trade offs you get for using a database. 因此,总体而言,空间和文件是您使用数据库时所要权衡的。

Maybe you can change some of this behaviour via some Derby configs (I did not find any one suitable in the doc :(). 也许您可以通过一些Derby配置更改某些这种行为(我在doc :()中找不到适合的任何一种)。

When last checked in 2011, an empty Derby database takes about 770 K of disk space: http://apache-database.10148.n7.nabble.com/Database-size-larger-than-expected-td104630.html 在2011年进行最后一次检查时,一个空的Derby数据库大约需要770 K的磁盘空间: http : //apache-database.10148.n7.nabble.com/Database-size-larger-than-expected-td104630.html

The log1.dat file is your transaction log, and records database changes so that the database can be recovered if there is a crash (or if your program calls ROLLBACK). log1.dat文件是您的事务日志,它记录数据库更改,以便在发生崩溃(或程序调用ROLLBACK)时可以恢复数据库。

Note that log1.dat is disk space , not memory . 请注意,log1.dat是磁盘空间 ,而不是内存

If you'd like to learn about the basics of Derby's transaction log, start here: http://db.apache.org/derby/papers/recovery.html 如果您想了解Derby交易日志的基础知识,请从这里开始: http : //db.apache.org/derby/papers/recovery.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM