简体   繁体   English

单个或多个数据库

[英]Single or multiple databases

SQL Server 2008 database design problem. SQL Server 2008数据库设计问题。

I'm defining the architecture for a service where site users would manage a large volume of data on multiple websites that they own (100MB average, 1GB maximum per site). 我正在定义一种服务的体系结构,其中站点用户可以管理他们拥有的多个网站上的大量数据(平均100MB,每个站点最多1GB)。 I am considering whether to split the databases up such that the core site management tables (users, payments, contact details, login details, products etc) are held in one database, and the database relating to the customer's own websites is held in a separate database. 我正在考虑是否拆分数据库,以便核心站点管理表(用户,付款,联系方式,登录详细信息,产品等)保存在一个数据库中,与客户自己的网站相关的数据库是单独保存的数据库。

I am seeing a possible gain in that I can distribute the hardware architecture to provide more meat to the heavy lifting done in the websites database leaving the site management database in a more appropriate area. 我看到了一个可能的好处,我可以分发硬件架构,为网站数据库中的繁重工作提供更多的肉,使网站管理数据库处于更合适的区域。 But I'm also conscious of losing the ability to directly relate the sites to the customers through a Foreign key (as far as I know this can't be done cross database?). 但我也意识到失去了通过外键直接将网站与客户联系起来的能力(据我所知,这不能跨数据库完成?)。

So, the question is two fold - in general terms should data in this sort of scenario be split out into multiple databases, or should it all be held in a single database? 因此,问题有两个 - 一般来说,这种情况下的数据应该分成多个数据库,还是应该全部保存在一个数据库中?

If it is split into multiple, is there a recommended way to protect the integrity and security of the system at the database layer to ensure that there is a strong relationship between the two? 如果将其拆分为多个,是否有建议的方法来保护系统在数据库层的完整性和安全性,以确保两者之间存在很强的关系?

Thanks for your help. 谢谢你的帮助。

This question and thus my answer may be close to the gray line of subjective, but at the least I think it would be common practice to separate out the 'admin' tables into their own db for what it sounds like you're doing. 这个问题,因此我的答案可能接近主观的灰色线,但至少我认为通常的做法是将'admin'表分离到他们自己的数据库中,因为它听起来像你在做什么。 If you can tie a client to a specific server and db instance then by having separate db instances, it opens up some easy paths for adding servers to add clients. 如果您可以将客户端绑定到特定服务器和数据库实例,然后通过具有单独的数据库实例,则会为添加服务器添加客户端提供一些简单的路径。 A single db would require you to monkey with various clustering approaches if you got too big. 如果你太大,单个数据库会要求你使用各种聚类方法。

[edit]Building in the idea early that each client gets it's own DB also just sets the tone for how you develop when it is easy to make structural and organizational changes. [编辑]尽早建立每个客户获得自己的数据库的想法也只是为易于进行结构和组织变革时的发展定下基调。 Discovering 2 yrs from now you need to do it will become a lot more painful. 从现在起发现2年你需要这样做会变得更加痛苦。 I've worked with split dbs plenty of times in the past and it really isn't hard to deal with as long as you can establish some idea of what the context is. 我过去曾经多次使用split dbs,只要你能够对上下文有什么了解,就真的不难处理。 Here it sounds like you already have the idea that the client is the context. 这听起来你已经知道客户端是上下文。

Just my two cents, like I said, you could be close to subjective on this one. 就像我说的那样,我只差两分钱就可以接近主观了。

Single Database Pros 单一数据库优点

  • One database to maintain. 一个数据库来维护。 One database to rule them all, and in the darkness - bind them... 一个数据库来统治它们,在黑暗中 - 绑定它们......
  • One connection string 一个连接字符串
  • Can use Clustering 可以使用群集

Separate Database per Customer Pros 每个客户专业人员单独的数据库

  • Support for customization on per customer basis 支持基于每个客户的定制
  • Security: No chance of customers seeing each others data 安全性:客户无法看到彼此的数据

Conclusion 结论

The separate database approach would be valid if you plan to support per customer customization. 如果您计划支持每个客户的自定义,则单独的数据库方法将是有效的。 I don't see the value if otherwise. 否则,我没有看到价值。

You can use link to connect the databases. 您可以使用链接来连接数据库。 Your architecture is smart. 你的架构很聪明。

If you can't use a link, you can always replicate critical data to the website database from the users database in a read only mode. 如果无法使用链接,则始终可以在只读模式下从用户数据库将关键数据复制到网站数据库。

concerning security - The best way is to have a service layer between ASP (or other web lang) and the database - so your databases will be pretty much isolated. 关于安全性 - 最好的方法是在ASP(或其他网络语言)和数据库之间建立一个服务层 - 这样你的数据库就会非常孤立。

If you expect to have to split the databases across different hardware in the future because of heavy load, I'd say split it now. 如果由于负载过重,您希望将来必须在不同的硬件上拆分数据库,我现在就说拆分它。 You can use replication to push copies of some of the tables from the main database to the site management databases. 您可以使用复制将某些表的副本从主数据库推送到站点管理数据库。 For now, you can run both databases on the same instance of SQL Server and later on, when you need to, you can move some of the databases to a separate machine as your volume grows. 现在,您可以在同一个SQL Server实例上运行这两个数据库,稍后在需要时,可以随着卷的增长将一些数据库移动到单独的计算机上。

Imagine we have infinitely fast computers, would you split your databases? 想象一下,我们拥有无限快速的计算机,你会拆分你的数据库吗? Of course not. 当然不是。 The only reason why we split them is to make it easy for us to scale out at some point. 我们拆分它们的唯一原因是为了让我们在某些时候能够轻松扩展。 You don't really have any choice here, 100MB-1000MB per client is huge. 你在这里没有任何选择,每个客户100MB-1000MB是巨大的。

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

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