在生产环境中使用嵌入式数据库?

     2023-03-31     116

关键词:

【中文标题】在生产环境中使用嵌入式数据库?【英文标题】:Using embedded database in production environment? 【发布时间】:2013-12-09 12:25:11 【问题描述】:

我正在使用Spring MVC 3.2 Embedded database (H2) 支持存储任务的实时进度、排队通知和一些临时日志。这种方法的唯一问题是我的数据消失了;如果应用程序重新部署或服务器重新启动。这种情况在生产环境中可能非常罕见,但我仍然想知道在生产环境中使用嵌入式数据库是否是一个不错的选择?..或者有没有办法将嵌入式数据库状态持久化到硬盘,以便下次服务器启动时我们可以将数据库状态恢复到存储的检查点?

谢谢。

【问题讨论】:

【参考方案1】:

嵌入式数据库不适用于生产环境。它们旨在提供更快的开发选项,因为您不需要运行外部数据库的依赖关系。使用嵌入式数据库,您可以以编程方式启动它,并根据您的需要选择性地对其进行初始化。

您的更改在重新部署期间丢失的原因是您使用的是 HsQL 的内存版本而不是进程内(独立文件)模式。您可以使用保持更改持久的独立模式。

In-Process (Standalone) Mode

This mode runs the database engine as part of your application program in the same Java Virtual Machine. For most applications this mode can be faster, as the data is not converted and sent over the network. The main drawback is that it is not possible by default to connect to the database from outside your application. As a result you cannot check the contents of the database with external tools such as Database Manager while your application is running. In 1.8.0, you can run a server instance in a thread from the same virtual machine as your application and provide external access to your in-process database.

The recommended way of using the in-process mode in an application is to use an HSQLDB Server instance for the database while developing the application and then switch to In-Process mode for deployment.

An In-Process Mode database is started from JDBC, with the database file path specified in the connection URL. For example, if the database name is testdb and its files are located in the same directory as where the command to run your application was issued, the following code is used for the connection:

    Connection c = DriverManager.getConnection("jdbc:hsqldb:file:testdb", "sa", "");
The database file path format can be specified using forward slashes in Windows hosts as well as Linux hosts. So relative paths or paths that refer to the same directory on the same drive can be identical. For example if your database path in Linux is /opt/db/testdb and you create an identical directory structure on the C: drive of a Windows host, you can use the same URL in both Windows and Linux:

    Connection c = DriverManager.getConnection("jdbc:hsqldb:file:/opt/db/testdb", "sa", "");
When using relative paths, these paths will be taken relative to the directory in which the shell command to start the Java Virtual Machine was executed. Refer to Javadoc for jdbcConnection for more details.

HSQL documentation

【讨论】:

我使用嵌入式数据库仅用于跟踪当前进度,任务完成后所有更改都将保存到真实数据库服务器这种方法对吗?..谢谢您建议在进程模式下我会尝试出来了。 是否有任何 MySQL 独立版本可以放在 Spring Boot JAR 文件的同一目录中...然后您创建一个初始化 MySQL 服务器的 bash 或 windows .bat 脚本.. .then 它运行 Spring Boot JAR 文件 ?....如果该场景有效,我将拥有一个 Spring Boot Stand 桌面 Web 应用程序

在生产环境中使用代码优先降级(回滚)数据库

】在生产环境中使用代码优先降级(回滚)数据库【英文标题】:Downgrade(Rollback)Databasewithcode-firstinproductionenvironment【发布时间】:2015-10-1705:58:17【问题描述】:我有一个网络应用程序,我安装在客户的计算机上供他们内部使用... 查看详情

如何在本地 Flask 环境中自动使用生产 postgres 数据库备份

】如何在本地Flask环境中自动使用生产postgres数据库备份【英文标题】:HowtoautomateusingaproductionpostgresdatabasebackupinlocalFlaskenvironment【发布时间】:2021-05-0709:13:31【问题描述】:我们的网站使用Postgres和Flask,并且我们经常在本地使... 查看详情

有啥方法可以在生产环境中使用数据集调试应用程序?

】有啥方法可以在生产环境中使用数据集调试应用程序?【英文标题】:Anywaytodebugappwithdatasetinproductionenvironment?有什么方法可以在生产环境中使用数据集调试应用程序?【发布时间】:2015-03-2609:03:54【问题描述】:我在ProductionEn... 查看详情

在开发和生产环境中使用不同的 Web.config

...问题描述】:我需要在我的ASP.NET应用程序中使用不同的数据库连接字符串和SMTP服务器地址,具体取决于它在开发或生产环境中运行。应用程序通过WebConfigurationManager.AppSe 查看详情

如何在多线程环境中使用嵌入式 MySQL?

】如何在多线程环境中使用嵌入式MySQL?【英文标题】:HowtouseMySQLEmbeddedinamultithreadedenvironment?【发布时间】:2011-12-0419:57:20【问题描述】:我正在编写一个使用MySQLe作为嵌入式后端的程序。数据库库归一个名为“域”的对象所有... 查看详情

在生产环境中执行 liquibase 更新

...描述】:我有一个JavaMaven项目。我正在使用liquibase来更新数据库。在本地,要更新我的数据库,我只是在命令行中运行:mvnliquibase:update在生产环境中,我没有安装Maven。我需要实现的是通过控制台,执行命令以 查看详情

在生产环境中使用 postgres 进行数据挖掘 - 有没有更好的方法?

...期内,该应用程序收集了大量用户数据。数据存储在关系数据库(postgres)中。并非所有这些数据都需要运行应用程序(做业务)。 查看详情

在生产环境中使用 RAM Disk 来加速应用程序性能

...】:2012-11-2019:42:14【问题描述】:我的应用程序由于其与数据库的聊天性质而面临问题。由于许多I/O操作或数据库调用,完成一个流程特殊的批处理作业需要时间。代码优化正在进行中,这个过程需要一些时间才能显示出积极的... 查看详情

为啥不应该在 Liferay 的生产环境中使用 HSQLDB?

】为啥不应该在Liferay的生产环境中使用HSQLDB?【英文标题】:Whyshouldn\'tHSQLDBbeusedinproductionforLiferay?为什么不应该在Liferay的生产环境中使用HSQLDB?【发布时间】:2011-05-0509:54:54【问题描述】:我已将liferay安装为一个可供200人使用... 查看详情

生产环境中的 NSPersistentCloudKitContainer

...一个使用NSPersistentCloudKitContainer的应用。在开发中,我的数据库按预期跨设备同步,但在生产中,我的数据库根本没有同步。调试完情况后,我意识到我必须将iCloud架构发 查看详情

生产环境中的 Laravel 4.x 迁移

...主要开发人员在Laravel方面经验丰富,但是,倾向于掩盖数据库细节。手头的问题是我们一直在使用工匠使用“迁移”和“播种者”。这在开发环境中运行得相对较好(有一些小问题)。我们 查看详情

如何在 NOPCOMMERCE app 中使用开发和生产环境?

】如何在NOPCOMMERCEapp中使用开发和生产环境?【英文标题】:HowtousedevelopmentandproductionenvironmentinNOPCOMMERCEapp?【发布时间】:2021-09-3007:55:51【问题描述】:我想知道您如何在生产和开发环境中管理应用程序。如何将源代码发布到IIS... 查看详情

不建议在生产环境中使用 CredSSP

】不建议在生产环境中使用CredSSP【英文标题】:CredSSPnotrecommendedinProductionenvironments【发布时间】:2012-09-0509:24:39【问题描述】:我尝试使用PowerShellRemoting部署SharepointWSP项目。见https://sharepoint.stackexchange.com/questions/44880/powershell-rem... 查看详情

Next js 在生产环境中不使用 cookie

】Nextjs在生产环境中不使用cookie【英文标题】:Nextjsnotusingcookiesonproduction【发布时间】:2022-01-1410:34:14【问题描述】:我的Nextjs应用程序没有在生产环境中使用响应cookie。它在开发和本地构建中就像一种魅力。cookie在所有情况下... 查看详情

在生产系统中使用 Hibernate 和 flyway

...hibernate。它看起来像我们想要的那样为给定的一组类生成数据库。但是,强烈建议不要在生产环境中使用hbm2ddl.auto=update。环顾四周,我看不出人们为这种情况做了什么。一旦数据库被填 查看详情

BeforeRouteEnter 无法通过脚本设置在生产环境中工作

】BeforeRouteEnter无法通过脚本设置在生产环境中工作【英文标题】:BeforeRouteEnternotworkinginproductionwithscriptsetup【发布时间】:2022-01-1312:14:48【问题描述】:我在vue-router中使用了beforeRouteEnter钩子,使用axios从两个不同的端点加载数... 查看详情

无法使用 Webpack 在生产环境中使用 Bootstrap CSS

】无法使用Webpack在生产环境中使用BootstrapCSS【英文标题】:Can\'tgetBootstrapCSSworkinginProductionwithWebpack【发布时间】:2020-12-2704:54:47【问题描述】:对Rails6和一般编码来说还是很陌生,我正在努力让Bootstrap在生产中工作。我正在使... 查看详情

在生产环境中使用 localhost 的电子邮件验证链接

】在生产环境中使用localhost的电子邮件验证链接【英文标题】:Emailverificationlinkusinglocalhostinaproductionenvironment【发布时间】:2020-04-2215:24:18【问题描述】:我在AWSElasticBeanstalk上部署了一个Laravel6.7.0应用程序。环境变量是使用Elasti... 查看详情