Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the pros/cons of and best practices for using a single database?

Here at work (a multi-billion dollar manufaturing company with a 12 person Windows development team) we are about to go to a single master database for all new applications and will have it broken up with schemas for what we normally would have had databases for before. There will also be a few common schemas with stuff like employee directory and branch directory and so on...

I'm still not sure how I feel about this move, but we're about to have a meeting on this in a few hours to discuss pros, cons, best practices, pitfalls and so on... so I'm looking for your thoughts on this... Is it good? Is it bad? What problems are we going to run into a year from now?

Any thoughts, tips, or advice is welcome. Thanks

EDIT In response to a comment on this question, we are using SQL Server 2005 and we are actually talking about moving what would have been seperate databases on the same instance into a single database. The driving issue is the complete lack of referential integrity accross databases as the majority of our applications need access to common data such as an employee record, or branch information.

UPDATE Several people requested that I update this question with the results from our meeting so here it is. We debated back and forth the pros and cons of doing this (I even showed them this question using the projector) and by the time we were done we had pretty much covered the pros and cons covered here. About half of us thought we could get it done with the right resources and commitment, and about half thought we couldn't do it (or that it wouldn't work out well). We decided to use some time with Microsoft to get their thoughts and platform specific advice. I will be sure to update this question and my blog after we've talked to them. Thanks for all the help and helpful answers.

like image 329
Max Schmeling Avatar asked May 27 '09 15:05

Max Schmeling


People also ask

Is it better to have one database or multiple databases?

Single database to backup, less maintainance. You don't need to manage multiple connections. Multiple databases can break the chance to perform atomic transactions, a feature I would never throw away. You avoid synchronizing two or more databases to avoid integrity problems.

Why should we have separate databases?

it is better to use different database for each client. Maintaining multiple databases is difficult. For example if we want to modify a table then we should do changes in all databases. Grouping of data into multiple databases each with a significantly fewer number of tables.

What is single database?

With a single database, each database is isolated, using a dedicated database engine. Each has its own service tier within the DTU-based purchasing model or vCore-based purchasing model and a compute size defining the resources allocated to the database engine.


2 Answers

Larger database are harder to maintain due to sheer size: backups take longer, disaster recovery is slower which in turn requires more often backups. You can address these by creating filegroups and using filegroup level backup in your maintenance plans and on crash recovery you can use the 'piecemeal restore' strategy to speed things up.

Proper use of filegroups will make most of the 'cons' cited by previous replies go away: they can distribute the I/O, they can sanitize your maintenance plans and backup/restore strategy, they offer availability by taking offline only the damaged portion of the the db in case of crash. So I'd say that while those 'cons' are legit concerns, they have can be mitigated by a proper deployment strategy. Its true though that these mitigation actions require a true, experienced, dba at the helm as they will go beyond the comfort zone of a developer turned dba by need.

Some of the pros I can think of quickly:

  1. Consistency. You can have a backup-restore so that all data is consistent. Separate dbs don't allow this because you cannot coordinate a consistent set of backups unless you take them all offline, or make them r/o, during the backup.
  2. Dirt cheap high availability: you can deploy database mirroring for disaster recoverability and high availability. Multiple databases have problems because one cannot coordinate a simultaneous failover and apps are faced with the dilemma of seeking each database current location.
  3. Security. While most other posts see one database harder to secure, I'd say is easier to secure. Multiple databases seem harder to secure properly simply because what everyone does is they make one login and add it to that database db_owner group. Having one database will make things harder (unless you end up making everyone dbo, very bad) but once you start doing the right thing (granular access) then one db is not harder than multiple dbs, is actually easier because you won't have to copy/maintain some common groups/rights across multiple dbs.
  4. Control. Will be easier to impose certain policies and good practices on a single db rather than multiple ones (no data access to developers, app data access only through execute rights on the schema to enforce procedures access etc).

There are also some cons I did not see in other posts:

  1. This will be much harder to pull off that you think right now
  2. Increase coupling between formerly separated applications will impose development restrictions: you can't simply alter your schema, you will have to coordinate it with the rest of the apps (you can argue that this was also the case before, but was brushed under the carpet by having separate dbs, and you're right)
  3. Log writes that are now distributed across multiple db logs will be consolidated into one single log file. If your writes are significant, this may turn out to be a serious bottleneck and force you to buy some expensive fast drives for the new, consolidated, log file. In general this can be addresses by making the log drive a stripped array across as many stripes as needed to make it fast enough (usually raid 10).
  4. GAM/SGAM/PFS allocations will also be consolidated, but again this will be alleviated by proper use of file groups.
like image 119
Remus Rusanu Avatar answered Oct 22 '22 16:10

Remus Rusanu


Pros:

  • You only need to remember one connection string
  • When users report that access is slow, you know which DB is causing the trouble

Cons:

  • Backups of The One DB will take a long time and will get progressively longer over time.
  • Restoring data from a backup will get increasingly difficult.
  • Performance Tuning (SQL Profiler, Execution Plan estimation) for a feature for one app will slow down every app.
  • Restricting access to a single application's data is cumbersome if at all possible which will likely mean in practice that all devs and DBAs will be given keys to the ENTIRE kingdom.
  • New developers/DBAs have a much larger learning curve as they need to navigate a large and mostly useless (to them) database structure which means higher costs for training/ramp up.
  • When The One database goes down, everyone in your organization plays solitaire until it is restored.
  • Creating test instances for app development means copying your entire db
like image 7
Rob Allen Avatar answered Oct 22 '22 15:10

Rob Allen