Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the pros and cons for using a database to store configuration information compared to a File System

Suppose you are tasked with writing a web application that must store configuration information in some format. What are the benefits and drawbacks for storing these configuration information in a relational database compared to storing the information in a file? Configuration options may include but not limited to data retention settings and settings for interfacing with external system (e.g. ip address, port, username, password).

like image 403
Gewthen Avatar asked Apr 09 '12 19:04

Gewthen


People also ask

Why is it better to store data in a database rather than in the file system?

Database provides a proper data recovery process while file system did not. In terms of security the database is more secure then the file system (usually).

Is database better than file system?

A file system does not allow for efficient data storage and retrieval. The use of a database management system is efficient because there are numerous techniques for storing and retrieving data. It does not provide data recovery services. In DBMS, there is a backup recovery option for data.

Should data be stored in files in a file system or in a database for the system?

Since the dawn of time, database vendors have called out to developers, “Store everything inside the database. You know you want to. Here, we'll make it easy for you by adding data types like binary and features like filestream.”

What are the advantages of storing the content in a database?

Databases support good data access because: Large volumes of data can be stored in one place. Multiple users can read and modify the data at the same time. Databases are searchable and sortable, so the data you need can be found quick and easily.


2 Answers

Here is a summary of pros and cons

Pros for file:

  1. Fast access to configuration data. (assuming no caching)
  2. Each server can be configured differently (in a load balancing situation)
  3. You already need a file for the database credentials so everything can be stored in one place.

Cons for file:

  1. Configuration in a load balanced environment is difficult.
  2. When adding settings under development, one most remember to move them into the files on every server in production.
  3. Configuration must be writable by the webserver if you want to write a control panel to change the settings at runtime. Manipulating files in a control panel is a hassle due to timing issues and or locking.

Pros for database:

  1. Load balancer can share configuration across the cluster
  2. It's very easy to check on settings remotely or change them such as in phpMyAdmin or a straight sql client.
  3. Control panel development becomes simple.
  4. Performance impact can be mitigated by caching configuration in memcached or in a hash in memory.
  5. Programmers are more likely to control settings rather than IT people or at least can be controlled through control panel.

Cons for database:

  1. Performance maybe slow if you're fetching the settings continuously.
  2. If you don't provide a tool, it might be more difficult for sysadmins to administer the product rather than a file. They might not be sql gurus.
  3. Clustering is more of a pain.

This comes down to personal preference and any current or possible future requirements for providing easy configuration.

like image 56
Lucas Holt Avatar answered Sep 24 '22 15:09

Lucas Holt


And now a real answer.

I guess in the end it is a matter of taste

Pro:

  • you could add an admin page to edit the settings in your applications

Con:

  • if your database is not available, your settings are also gone
  • if you migrate a database to a different environment (e.g. a production database to test to do some issue checking) your settings are included
  • slightly harder to deploy
  • more difficult to add to version control
  • you need a file anyway to store your database credentials
like image 26
Pleun Avatar answered Sep 25 '22 15:09

Pleun