Five Tips for Managing Database Servers in Production
Check out these five tips to secure, replicate, performance tune, and scale your database server.
Join the DZone community and get the full member experience.Join For Free
your web application or mobile api needs a database, so you'll likely be using
apt-get install postgres
brew install postgres
to get up-and-running on your laptop. when you deploy to the cloud, you'll decide to run the same command used previously. everything should be production-ready, right? well not quite.
there's much more to running and managing a database in production than meets the eye. this article outlines tips for managing a production database, giving you some helpful resources on how to get started.
tip #1: secure your database server
how secure is your production database? this should be the first question you look to answer. from network access to securing your data over the wire using tls connections, your database must protect the data it stores.
you should install and configure a firewall to protect your database servers. to limit access to a specific ip or ip range via ssh for external connections, apply firewall rules to restrict the accessible port(s) to your database (e.g. 5432 for postgres and 3306 for mysql) so they're accessible only from your app servers. this restriction will require you to ssh to the database server, in order to connect to your database, while ensuring your database process is not publicly accessible to the world.
we also recommend using ssl to secure the connections between your application and database, to prevent snooping on authentication details and sensitive data over the wire. be sure to verify that the distribution of your installed database supports ssl. some distributions don't include ssl support by default, requiring the installation of an add-on package or custom distribution.
tip #2: tune your database for production
when databases are installed from a binary distribution or package manager, a default configuration file is used to ensure the server uses a limited footprint to be the most compatible for just about any environment. this means, however, that tuning your database is required to get the most of your server in production.
an investment of time for research and testing is required to optimize server performance. there are a variety of variables associated with tuning a database, including a server's available memory, number of cpus, and the types of queries you will likely execute. skipping this step will cause your application performance to degrade much earlier than expected, limiting scalability.
below are some resources to help get you started tuning your database:
tip #3: replicate your database for high availability
it's common for applications to span multiple web servers, with a load balancer in front to distribute incoming requests amongst the servers. techniques such as server groups can be used to auto-scale servers up and down based on incoming traffic, as we outlined in "cloud server scaling strategies" .
no matter how many app servers you may have configured, if you only have one server for your database, you are at risk of the entire application becoming unavailable if your database server fails. instead, we need to design for high availability.
database replication allows your data to be duplicated across multiple database servers, preventing a single point of failure. database replication takes time to set up and configure, so allocate enough time and resources to properly setup your replica strategy.
below are some resources to help get you started with high availability database replication:
tip #4: select a scaling strategy for your database
as your application starts to experience more traffic, you'll begin to see your database queries slow down. the most common use of replication is to create read-replicas, allowing data for incoming requests to be served from multiple servers while retaining a master server for writes. here is a diagram that illustrates how this works:
read my article titled "patterns for scaling databases" section of our scaling databases article to learn more.
we encourage you to develop a solid monitoring solution, as well as performing pro-active load testing to better estimate your database and application scalability. this will prevent the setup from occurring under the pressures of a down website.
tip #5: establish a reliable database back-up and recovery plan
a database back-up ensures your data can be recovered in the case of corrupted data or server loss. a good database backup should include:
- all data stored within your database
- server configuration files
- database user accounts
- certificates used for secure database communications
- any external files that may be referenced from within the database via an absolute or relative path
be sure to store your backups on a third-party system or an object storage solution such as aws s3, rather than on your database server where they could be lost due to a hardware or filesystem failure.
there are many scripts that make it easy to create a backup solution. i've had great success using the backup rubygem , as it's flexible and easy to use.
perhaps you're using one already, or one that you crafted yourself. that's a great first step. but, can you be certain that your backups are current, reliable, and accessible to the team? do you know that your backup scripts are working properly, contain a complete data set, and you can restore the data quickly and reliably?
creating a backup script can be done quickly. however, your backups are only as good as your ability to restore them in a time of need. if you are not testing your backup files to ensure they can be restored, you may be devastated when you realize they don't work.
verify your database backups as part of your disaster recovery strategy. perform a dry-run of the restoration process once per month to ensure you understand how to conduct a restoration process quickly and easily. a critical situation is not the best time to look up the commands to execute a backup restoration.
managed databases: when a diy solution isn't the right choice
if your team doesn't have the experience to properly setup and configure a secure database server with replica support, you may want to opt into a managed database service. managed database services may vary based on the service provider. cloud 66 offers a managed database service for teams that includes:
- single-click database replication support , including mongodb replica sets
- database backup and verification
- tuned database server configurations based on your cloud provider and vm size
- multiple vendor support , including postgresql, mysql, mongodb, redis, elasticsearch, and rabbitmq for messaging
- multiple cloud support , including aws, google, ms azure, digitalocean, and rackspace
Published at DZone with permission of James Higginbotham, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.