简体   繁体   中英

H2 database unuseable when table contains 9 million records

I am using H2 as an embedded database started with 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. 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? Even basic queries such as select count(*) from HISTORICALDATA2 take so long that I end up cancelling the query.

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 is not usually used as a production database. See Are there any reasons why h2 database shouldn't be used in production? 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.

See: How to convert H2Database database file to MySQL database .sql file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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