我可以在 Heroku 上使用基于文件的数据库吗? [英] Can I use a file based database on Heroku?

查看:20
本文介绍了我可以在 Heroku 上使用基于文件的数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署到 Heroku 的小型 Node.js/Express 应用.

I have a small Node.js / Express app deployed to Heroku.

我想使用像 NeDB 这样的轻量级数据库来保存一些数据.如果我使用这种方法,是否可以定期从 Heroku 备份/复制文件?

I'd like to use a lightweight database like NeDB to persist some data. Is it possible to periodically backup / copy a file from Heroku if I used this approach?

推荐答案

基于文件的数据库不适合 Heroku,因为它的 临时文件系统(加粗):

File-based databases aren't a good fit for Heroku due to its ephemeral filesystem (bold added):

每个 dyno 都有自己的临时文件系统,以及最近部署的代码的全新副本.在 dyno 的生命周期内,其正在运行的进程可以使用文件系统作为临时暂存器,但是写入的文件对于任何其他 dyno 中的进程都是不可见的,并且任何写入的文件都将在 dyno 停止或重新启动的那一刻被丢弃.例如,这会在由于应用程序部署而更换 dyno 时发生,并且作为正常 dyno 管理的一部分大约每天一次.

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.

根据您的用例,我建议使用客户端-服务器数据库(这看起来很适合这里)或类似 用于文件存储的 Amazon S3.

Depending on your use case I recommend using a client-server database (this looks like a good fit here) or something like Amazon S3 for file storage.

这篇关于我可以在 Heroku 上使用基于文件的数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆