DBMS H2.
Вот основной ресурс этой СУБД. Здесь все подробности.
Столкнулся с этой БД при обновлении OSS Nexus. Там они в последней версии перешли с OrientDB на H2 (для тех, кто бедный) или на PostgreSQL (для тех, кто побогаче, т.к. надо покупать премиум аккаунт по подписке).
Но т.к. в современных реалиях, на момент написания данной заметки, нет возможности оплатить хотя бы месяц этого премиального аккаунта, то пришлось выбирать H2.
И так…
Скачать архив:
1 | wget https://github.com/h2database/h2database/releases/download/version-2.3.232/h2-2024-08-11.zip |
распаковать:
1 | unzip h2-2024-08-11.zip |
Запустить скрипт:
1 | bash build.sh |
Targets: | |
benchmark | Run the benchmarks. |
clean | Clean all jar files, classes, and generated documentation. |
compile | Compile all classes. |
coverage | Run the JaCoco code coverage. |
docs | Create the documentation from sources (incl. API Javadocs). |
download | Download all required jar files. |
installer | Create the h2.zip file and the Windows installer. |
jar | Create the regular h2.jar file. |
jarMVStore | Create h2mvstore.jar containing only the MVStore. |
javadoc | Create the API Javadocs (incl. JDBC API and tools). |
javadocImpl | Create the Javadocs of the implementation. |
mavenDeployCentral | Build H2 release jars and upload to file:///data/h2database/m2-repo. |
mavenInstallLocal | Build a snapshot H2 jar and upload to local Maven 2 |
offline | Build H2 jar avoiding downloads (list missing files). |
spellcheck | Run the spellchecker. |
test | Compile and run all tests (excluding the compile step). |
testCI | Compile and run all tests for CI (excl. the compile step). |
testNetwork | Test the local network of this machine. |
testSysProperties | Print the system properties. |
uploadBuild | Upload all build results to the public website. |
warConsole | Build the h2console.war file. |
Запустим так:
1 | bash build.sh test |
Мне написало такое:
Error: JAVA_HOME is not defined.
Тогда сделаю так сначала:
1 | export JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64 |
и повторю выполнил предыдущую команду. Вот что мне написало:
Target: test
/usr/lib/jvm/java-17-openjdk-amd64/bin/java -ea -Xmx128m -cp src/java10/precompiled:src/java9/precompiled:temp:bin:ext/postgresql-42.7.2.jar:ext/javax.servlet-api-4.0.1.jar:ext/jakarta.servlet-api-5.0.0.jar:ext/lucene-core-9.7.0.jar:ext/lucene-analysis-common-9.7.0.jar:ext/lucene-queryparser-9.7.0.jar:ext/org.osgi.core-5.0.0.jar:ext/org.osgi.service.jdbc-1.1.0.jar:ext/jts-core-1.19.0.jar:ext/slf4j-api-2.0.7.jar:ext/slf4j-nop-2.0.7.jar:ext/asm-9.5.jar:/usr/lib/jvm/java-17-openjdk-amd64/../lib/tools.jar:ext/nashorn-core-15.4.jar:ext/asm-commons-9.5.jar:ext/asm-tree-9.5.jar:ext/asm-util-9.5.jar org.h2.test.TestAll
Error: Could not find or load main class org.h2.test.TestAll
Caused by: java.lang.ClassNotFoundException: org.h2.test.TestAll
Попробую так:
1 | bash build.sh compile |
Вывод большой, не буду сюда его выкладывать. Только то, что в конце было написано:
Building index for all classes…
Generating docs/javadoc/allclasses-index.html…
Generating docs/javadoc/allpackages-index.html…
Generating docs/javadoc/index-all.html…
Generating docs/javadoc/overview-summary.html…
Generating docs/javadoc/help-doc.html…
Zip temp/org/h2/util/data.zip (669 KB)
Done in 22407 ms
Потом можно опять попробовать тест запустить, но это долгий процесс.
Options are case sensitive.
Supported options[-help] or [-?]Print the list of options
[-web] Start the web server with the H2 Console
[-webAllowOthers] Allow other computers to connect — see below
[-webExternalNames] The comma-separated list of external names and IP addresses of this server, used together with -webAllowOthers
[-webDaemon] Use a daemon thread
[-webPort ] The port (default: 8082)
[-webSSL] Use encrypted (HTTPS) connections
[-webAdminPassword] Password of DB Console administrator
[-browser] Start a browser connecting to the web server
[-tcp] Start the TCP server
[-tcpAllowOthers] Allow other computers to connect — see below
[-tcpDaemon] Use a daemon thread
[-tcpPort ] The port (default: 9092)
[-tcpSSL] Use encrypted (SSL) connections
[-tcpPassword ] The password for shutting down a TCP server
[-tcpShutdown «»] Stop the TCP server; example: tcp://localhost
[-tcpShutdownForce] Do not wait until all connections are closed
[-pg] Start the PG server
[-pgAllowOthers] Allow other computers to connect — see below
[-pgDaemon] Use a daemon thread
[-pgPort ] The port (default: 5435)
[-properties «»] Server properties (default: ~, disable: null)
[-baseDir] The base directory for H2 databases (all servers)
[-ifExists] Only existing databases may be opened (all servers)
[-ifNotExists] Databases are created when accessed
[-trace] Print additional trace information (all servers)
[-key ] Allows to map a database name to another (all servers)
The options -xAllowOthers are potentially risky.
Попробовал запустить вот так:
1 2 3 4 | /h2/bin# java -cp h2*.jar org.h2.tools.Server \ -tcp -tcpAllowOthers -tcpDaemon \ -pg -pgAllowOthers -pgDaemon \ -properties /mnt/nexus_blob/dbms_h2/databases/ |
Я запускал в режиме PG, чтобы это ни значило.
Потом запустил консоль:
1 | java -cp h2-*.jar org.h2.tools.Shell |
Далее указывал следующие параметры:
1 | URL jdbc:h2:/mnt/nexus_blob/dbms_h2/databases/nexus3 |
/mnt/nexus_blob/dbms_h2/databases/ — путь, где будет храниться БД, nexus3 — название БД
Далее, будет Driver — тут просто нажал Enter.
1 | Driver |
Потом задал имя пользователя:
1 | User nexusdbusr |
Задал пароль и повторил потом:
1 | Password |
В итоге получилось что-то типа такого:
Попробую посмотреть какие есть таблицы:
1 | SHOW TABLES; |
Можем запустить web-доступ:
1 2 | java -cp h2*.jar org.h2.tools.Server \ -web -webExternalNames 192.168.1.4 -webAllowOthers -webPort 8088 |
Здесь:
- JDBC URL: вводим — jdbc:h2:/mnt/nexus_blob/dbms_h2/databases/nexus3
- User Name: nexusdbusr
- Password: [пароль который задавали в консоли]
Жмём Connect и попадаем вот сюда:
If you found an error, highlight it and press Shift + Enter or to inform us.