简体   繁体   English

何时在同一服务器上使用单独的SQL数据库?

[英]When to use separate SQL databases on the same server?

I've worked in several SQL environments. 我曾在多个SQL环境中工作过。 In one environment, the different tables holding business data were split across several different SQL databases, all on the same server. 在一个环境中,保存业务数据的不同表分散在几个不同的SQL数据库中,所有这些数据库都在同一服务器上。

In another environment, almost all the tables are kept on one single SQL database. 在另一种环境中,几乎所有表都保存在一个单独的SQL数据库中。

I'm creating a new project that is closely related to another project, and I've been wondering if I should put the new tables in the same SQL database or a new SQL database. 我正在创建一个与另一个项目密切相关的新项目,我一直在想是否应该将新表放在相同的SQL数据库或新的SQL数据库中。

This all runs on MS SQL Server. 所有这些都在MS SQL Server上运行。

What factors do I need to consider as I make this decision? 做出此决定时需要考虑哪些因素?

It's tough from your question to tell what your actual requirements are, or what data you would consider to store in different databases. 从您的问题出发,很难说出您的实际需求是什么,或者考虑将哪些数据存储在不同的数据库中。 But in addition to Gordon's points I can address a couple of additional reasons why you might want to use separate databases for data belonging to different customers / users (and this answer assumes that one possible separation of data, whether by database or schema, would be by customer): 但是除了Gordon的观点之外,我还可以解决几个其他原因,为什么您可能想要对属于不同客户/用户的数据使用单独的数据库(并且此答案假设可能是通过数据库还是架构来分离数据)。按客户):

  • As I mentioned in a comment, some customers will demand that their data be stored separately, and you may need to agree to that in writing before you see a penny or are able to secure their business. 正如我在评论中提到的那样,有些客户会要求将其数据单独存储,您可能需要以书面形式同意,然后再花一分钱或能够保护自己的业务。 So you may as well be prepared for that inevitability. 因此,您最好为这种必然性做好准备。

  • Keeping each customer in their own database makes it very easy to move them if they outgrow your current server. 将每个客户保留在自己的数据库中,可以在他们超出当前服务器数量的情况下轻松移动他们。 At my previous job we designed the system in this way, and it saved our bacon later - we were able to move customers completely to a different server with what essentially amounted to a metadata operation. 在我之前的工作中,我们以这种方式设计了系统,后来节省了培根-我们能够将客户完全转移到另一台服务器上,而这实际上就是元数据操作。 During a maintenance window, backed up their database, set the original to offline, restored the backup to a new server, and updated a config table that told all the apps where to find that database. 在维护窗口期间,备份其数据库,将原始数据库设置为脱机,将备份还原到新服务器,并更新配置表,该表告知所有应用程序在哪里可以找到该数据库。 This is much more flexible than trying to extract all of their data from a database shared by others... 这比尝试从他人共享的数据库中提取所有数据要灵活得多。

  • Separate databases also allow you to handle maintenance differently. 单独的数据库还允许您以不同的方式处理维护。 One customer needs point-in-time restore, and another doesn't? 一个客户需要时间点还原,而另一个不需要吗? Perfect, you can just use a different recovery model on separate databases. 完美,您可以在单独的数据库上使用不同的恢复模型。 Much easier than separating by filegroups and trying to implement some filegroup-level backup solution, and much more efficient than just treating one big database in full recovery. 这比按文件组分开并尝试实施某些文件组级别的备份解决方案要容易得多,并且比仅对一个大数据库进行完全恢复要有效得多。

This isn't free, of course, it's about trade-offs. 当然,这不是免费的,而是权衡取舍。 Multiple databases scares some people away but having managed such a system for 13 years I can tell you that managing 100 or 500 databases that are largely identical is not that much more complicated than managing 500 schemas in one massive database (in fact I would say it is less so in a lot of respects). 多个数据库吓跑了一些人,但是已经管理了13年这样的系统,我可以告诉您,管理100个或500个基本相同的数据库并不比在一个大型数据库中管理500个模式复杂得多(实际上,我会说它在很多方面都不太好)。

A database is the unit of backup and recovery, so that should be the first consideration when designing database structures. 数据库是备份和恢复的单元,因此在设计数据库结构时应首先考虑。 If the data has different back up and recovery requirements, then they are very good candidates for separate databases. 如果数据具有不同的备份和恢复要求,那么它们非常适合用于单独的数据库。

That is only half the problem, though. 不过,这只是问题的一半。 In most environments, backup/recovery is pretty much the same for all databases. 在大多数环境中,所有数据库的备份/恢复几乎相同。 It becomes a question of application design. 这成为应用程序设计的问题。 In other words, the situation becomes quite subjective. 换句话说,情况变得很主观。

In the environment that I'm working in right now, here are some criteria for splitting data into different databases: 在我现在正在使用的环境中,以下是将数据拆分到不同数据库中的一些标准:

(1) Publishing tables to a wide audience. (1)将表格发布给广大读者。 We "publish" data in tables and put these into a database, separate from other tables used for building them or for special purposes. 我们将数据“发布”到表中,并将其放入数据库中,与用于构建数据表或用于特殊目的的其他表分开。 Admittedly, SQL Server claims that "schema" are the unit of security. 诚然,SQL Server声称“模式”是安全性的单位。 However, databases seem to do a good job in the real world. 但是,数据库在现实世界中似乎做得很好。

(2) Strict security requiremeents. (2)严格的安全要求。 Some data is so sensitive that lawyers have to approve who can see it. 有些数据非常敏感,律师必须批准谁可以看到它。 This goes into its own database, with its own access. 它进入自己的数据库,并具有自己的访问权限。

(3) Separation of data tables (which users can see) and tables that describe the production system. (3)分离数据表(用户可以看到)和描述生产系统的表。

(4) Separation of tables used for general querying by a skilled group of analysts (the published tables) versus tables used for specific reports/applications. (4)将熟练的分析人员用于一般查询的表(已发布的表)与用于特定报告/应用程序的表分开。

Finally, I would add this. 最后,我将添加此内容。 If some of the data is being updated continuously throughout the day and other data is used for reporting, I would tend to put them in different databases. 如果某些数据在一天内不断更新,而另一些数据用于报告,我倾向于将它们放在不同的数据库中。 This helps separate them in the case of problems. 这有助于在出现问题时将它们分开。

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

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