简体   繁体   English

当表包含 900 万条记录时,H2 数据库无法使用

[英]H2 database unuseable when table contains 9 million records

I am using H2 as an embedded database started with AUTO_SERVER=TRUE .我使用 H2 作为以AUTO_SERVER=TRUE的嵌入式数据库。

At the very start I had only a few records and performance wasn't an issue even with no indexes defined.一开始我只有几条记录,即使没有定义索引,性能也不是问题。

When the table had more records performance seriously degraded and this was resolved by adding an index.当表有更多记录时,性能严重下降,通过添加索引解决了这个问题。

The db then performed very well until recently when the no.然后数据库表现得非常好,直到最近没有。 of records reached more than 8 million and now I have been unable to get any normal performance out of the DB and have tried changing cache_size etc... but no improvement.记录达到超过 800 万,现在我无法从数据库中获得任何正常的性能,并尝试更改 cache_size 等......但没有任何改进。 I have seen posts that people are using H2 with many millions and even billions of records so is there something basic I am missing?我看到有人使用 H2 处理数百万甚至数十亿条记录的帖子,所以我缺少一些基本的东西吗? Even basic queries such as select count(*) from HISTORICALDATA2 take so long that I end up cancelling the query.即使是诸如select count(*) from HISTORICALDATA2这样的基本查询也需要很长时间,以至于我最终取消了查询。

Here is the table definition:这是表定义:

CREATE TABLE "PUBLIC"."HISTORICALDATA2"
(
   REQUESTID integer,
   SYMBOL varchar(50) NOT NULL,
   EXCHANGE varchar(20),
   SECTYPE varchar(10),
   CURRENCYNAME varchar(5),
   ENDDATETIME varchar(20),
   DURATION varchar(20),
   BARSIZE varchar(20),
   WHATTOSHOW varchar(20),
   USERTH integer,
   FORMATDATE integer,
   CHARTOPTIONS varchar(50),
   DATETIMEDATA timestamp,
   OPEN_PRICE decimal(20,2),
   HIGH_PRICE decimal(20,2),
   LOW_PRICE decimal(20,2),
   CLOSE_PRICE decimal(20,2),
   VOLUME integer,
   COUNT_FIELD integer,
   WAP integer,
   HASGAPS boolean,
   TSTAMP timestamp DEFAULT CURRENT_TIMESTAMP()
);

And the index:和指数:

CREATE INDEX HD_MAIN ON "PUBLIC"."HISTORICALDATA2"
(
  SYMBOL,
  EXCHANGE,
  ENDDATETIME,
  WHATTOSHOW,
  DURATION,
  BARSIZE
);

H2 and Production H2 和生产

H2 is not usually used as a production database. H2 通常不用作生产数据库。 See Are there any reasons why h2 database shouldn't be used in production?请参阅是否有任何原因不应该在生产中使用 h2 数据库? for more details.更多细节。 Many of the answers give valid reasons for not doing this.许多答案给出了不这样做的正当理由。


Migrating to Another DB迁移到另一个数据库

You can migrate your records away from h2 and move them to Postgres, MySQL, or Oracle.您可以将记录从 h2 迁移到 Postgres、MySQL 或 Oracle。

See: How to convert H2Database database file to MySQL database .sql file?请参阅: 如何将 H2Database 数据库文件转换为 MySQL 数据库 .sql 文件?

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

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