Tips and tricks while working with Production DBs

From time to time we have to work with live environments and production databases. For some of us this is day-to-day job. And most of the time cost of a mistake is way higher than expected improvement especially on the databases. Because issue on the database side will affect everything else.
I heard enough war stories about ruined productions and can imagine well enough speed of DROP DATABASE command replicating across the cluster. So I’m scared to make changes in production. The more loss expected if things go wrong the more I’m going to be scared planning every change. But I still love to make improvements so the only question is how to make them safer.
This post is not intended to be a guide or best practices on how to avoid issues at all, it’s more invitation to discussion that started between me and @randomsurfer in twitter on how to avoid production failures. It was hard for me to fit to 150 characters so I’m switching to more comfortable environment.
So here is a few practices that I use while working with remote servers:
Do not use rm -rf with leading wildcards. Ever. If you need to delete all subdirectories go with rm -rf dir1 dir1 dir2 etc. I’m also trying to avoid even trailing slashes near to rm -rf to be honest, just because.
Commandline history is convenient but could be dangerous if your connection is slow (it happens often when you work coast to coast or trans-Atlantic) so you could press enter on wrong command. To avoid this I’m hitting <space> at the end of command line before hit enter and wait for terminal response to make sure that command appearing on the command line will not scroll away.
I do my best to not make changes while sick. Sometimes it’s hard to reschedule a change, but most of the time it’s worth to move it to later time (even few hours could help sometimes) or hand off to someone else than put customer’s environment to risk.
Work with a single server at a time. If you have several open SSH windows with different server there is possibility to mess up the window and issue right command in wrong place. Especially when one window is a master and another is slave – same DB names, same tables, easy to mess up. If you still need to work on different hosts at the same time – change terminal’s background. I usually use red color (128,0,0) for master SSH window.
If you have your own tricks on how to not run DROP DATABASE in wrong place (yeah, I know pt-slave-delay helps in this case, but still!) please feel free to share them!
Thank you!
via Planet MySQL
Tips and tricks while working with Production DBs

How Can I Help My Daughter Learn DIY Skills?

A DIY attitude is pretty useful thing to pass on to your kids. But what do you do when your kid’s interested in learning some of those skills and you’re just not that handy?

Jeremy writes:

My daughter is 13 and wants to learn how to build and fix things. She has always liked building stuff, ever since she was little. Now, she’s interested in learning to work with her hands more. The trouble is my wife and I just aren’t really DIYers when it comes to stuff like that. I could probably teach her to build a computer, but not much else. I looked at classes for things like woodworking and electronics, but they’re usually for older kids and adults. So what would be a good way for her to learn some things?

Have some advice for Jeremy? Post it below!

Do you have a problem that needs solving and want help from the Lifehacker community? Email us at tips+wyp@lifehacker.com and we might post it. The best questions are broad enough to apply to other people and have many possible answers (so that you can get lots of opinions from your fellow readers). If you have a question that’s specific to you or only has a single solution, send an email to tips@lifehacker.com instead.


via Lifehacker
How Can I Help My Daughter Learn DIY Skills?

MySQL Backup & Recovery Essentials

Download PDF Presentation
A hardware, software or human failure can occur at any time. Are you prepared?
Many organizations take a risk of serious data loss and system downtime with inadequate procedures in place to support a disaster recovery. This presentation covers the essentials of MySQL backup and recovery options, identifying the necessary tools for an effective strategy to support data resilience and business continuity for your organization. MySQL has no one single unbreakable backup solution, so it is important to understand the impact of MySQL replication, storage engines, configuration options for durability, hardware configuration and the impact on locking and uptime for the various hot/warm/cold options available.
Short Url: http://j.mp/EM-BandR
Presenter: Ronald Bradford
Schedule: MySQL Connect 2013 – San Francisco, California
RMOUG QEW – May 2012- Denver, Colorado
via Planet MySQL
MySQL Backup & Recovery Essentials

Tips to Build a Fault-tolerant Database Application

Applications should be written taking into account that errors will eventually happen and, in particular, database application developers usually consider this while writing their applications.Although the concepts required to write such applications are commonly taught in database courses and to some extent are widely spread, building a reliable and fault-tolerant database application is still not an easy task and hides some pitfalls that we intend to highlight in this post with a set of suggestions or tips.In what follows, we consider that the execution flow in a database application is characterized by two distinct phases: connection and business logic. In the connection phase, the application connects to a database, sets up the environment and passes the control to the business logic phases. In this phase, it gets inputs from a source, which may be an operator, another application or a component within the same application, and issues statements to the database. Statements may be executed within the context of a transaction or not.First Tip: Errors may happen so plan your database application taking this into accountSo we should catch errors, i.e. exceptions, in both the connection and business logic phase. This idea can be translated into code using Python as follows:class Application(object): def __init__(self, **db_params): self.__cnx = None self.__cursor = None self.__db_params = db_params def connect(self): try: self.__cnx = MySQLConnection(**self.__db_params) self.__cursor = self.__cnx.cursor() except InterfaceError: print "Error trying to get a new database connection" def business(self, operation): try: self._do_operation(operation) except DatabaseError: print "Error executing operation" if main == "__main__": app = Application(get_params()) app.connect() while True: app.business(get_operation())The InterfaceError class identifies errors in the interface, i.e. connection, between the application and the MySQL Server. The DatabaseError class identifies errors associated with database operations.In this simple example though, the application may abort after any connection error. For instance, a MySQL Server will automatically close a connection after a period of inactivity thus causing an application error if one tries to use the invalid connection.Second Tip: Set up the appropriate timeout propertiesThere are two properties which fall under this suggestion:wait_timeout – It is a MySQL option that defines the interval that must elapse without any communication between an application and a MySQL Server before the MySQL Server closes a connection.connection_timeout – Sets the socket_timeout property in the Connector Python which defines the maximum amount of time that a socket created to connect to a database will wait for an operation to complete before raising an exception.The wait_timeout must be set according to the application’s characteristics. On the other hand, the connection_timeout property is usually set to zero which means that there will be no socket timeout period. In rare cases, such as when applications must execute operations within a fixed interval, we should set it up.Third Tip: Connection errors may happen at any time so handle them properlyThe previous measurements will not circumvent problems related to transient network issues or server failures though. To handle this type of problem, one needs to consider that a connection may fail at any time. This requires to catch connection errors also while executing the business logic and get a fresh connection to proceed with the execution. In other words, this requires to combine the aforementioned two phases. This idea can be translated into code as follows:class Application(object): def __init__(self, **db_params): self.__cnx = None self.__cursor = None self.__db_params = db_params.copy() def connect(self): try: self.__cnx = MySQLConnection(**self.__db_params) self.__cursor = self.__cnx.cursor() except InterfaceError: print "Error trying to get a new database connection" def business(self, operation): try: self._do_operation(operation) except (AttributeError, InterfaceError) print "Database connection error" self.connect() except DatabaseError: print "Error executing operation" if main == "__main__": app = Application(get_params()) app.connect() while True: app.business(get_operation())In general, connectors cannot hide connection failures from the application because this may lead to data inconsistency. Only the application has enough knowledge to decide what is safe to do and as such any failure, including connection failures, must be reported back to the application. In what follows, we depict a problem that may happen when a connector tries to hide some failures from the application:When the connection fails, the server rolls back the on-going transaction thus undoing any change made by the first insert statement. However, the connector gets the error and automatically tries to reconnect and succeeds. With a valid connection to the server, it executes the failed statement and succeeds. Unfortunately, the application does not find out about the connection issue and continues the execution as nothing has happened and by consequence a partial transaction is committed thus leaving the database in an inconsistent state.It is worth noting that if statements are executed in “autocommit” mode, it is still unsafe to hide failures from the application. In this case, an attempt to automatically reconnect and try to execute the statement may lead to the statement being executed twice. This may happen because the connection may have failed after the statement has been successfully executed but before the server has had a chance to reply back to the connector.Fourth Tip: Guarantee that session information is properly set after getting a connectionFrom a fault-tolerant perspective the application looks better now. However, we are still missing one key point.We should use the "my.cnf" configuration file to set up the necessary MySQL’s properties (e.g. autocommit, transaction isolation level). However if several applications share the same database server and require different configuration values, they should be defined along with the routine that gets a connection. If you do it in a different place, you may risk forgetting to set the options up when trying to get a new connection after a failure. Our code snippet already follows this rule and you are safe in that sense.This suggestion is specially important when the applications (i.e. components) share the same address space and use a connection pool.We should also avoid using temporary tables and/or user-defined variables to transfer data between transactions. Although this is a common technique among developers, this will fail miserably after a reconnection as the session information will be lost and may require an expensive routine to set up the necessary context. So starting every transaction with a “clean slate” is probably the safest and most solid approach.Fifth Tip: Design all application components taking failures into accountFinally, it is worth noticing that if the database fails the system as whole will be unavailable. So to build a truly resilient solution, we still need to deploy some type of redundancy at the database level. We will discuss possible high availability solutions for MySQL in a different post.See http://alfranio-distributed.blogspot.com/2013/09/writing-fault-tolerant-database.html
via Planet MySQL
Tips to Build a Fault-tolerant Database Application

Eagle POV

YouTuber Srachi uploaded this awesome POV footage taken from a camera that was strapped to an eagle. The bird was soaring above the Mer de Glace glacier in the Chamonix valley in France. It’s at once amazing and soothing.
via The Awesomer
Eagle POV

Organize Your Garage with This Six-Zone System

Organize Your Garage with This Six-Zone System

The garage is one of those areas that can easily become a cluttered, disorganized mess. To make your garage more usable and maximize storage space, take a look at this organizing system.

As all neat freaks know, "a place for everything and everything in its place" is the key to staying organized. This six-zone system suggested by EasyCloset’s Inspired Organization blog follows that mantra by setting up distinct zones for different purposes (outdoor gear, bulk storage, etc.). The zones are also ordered according to how often you might need to reach them. The zones are:

  1. Transition Zone: Shoes, jackets, bags, and other stuff you grab before leaving the house
  2. Need It Now: Everyday stuff like canned food, bulk food items, large packs of paper towels, etc.
  3. Long, Tall, Thin Storage: Rakes, shovels, and similar yard stuff to be hung on the walls
  4. Large Item Storage: Things like holiday decorations and camping gear that are rarely used
  5. Frequently Used Items: Outdoor gear and sports equipment placed near the garage door for easy access
  6. Workspace: A workbench and cabinets for your hobby, whether it’s gardening or woodworking

Of course, these are all just suggestions, and the zones you might need may differ. Still, it’s a template you can use to get your garage organized so you can actually find what you need in there when you need it.

6 Garage Zones for Maximum Organization | Inspired Organization


via Lifehacker
Organize Your Garage with This Six-Zone System

Awesome Guy Re-Created the Star Wars Opening Crawl with HTML and CSS

Awesome Guy Re-Created the Star Wars Opening Crawl with HTML and CSS

Here’s something completely awesome on a day that needs more awesome. Tim Pietrusky recreated the famous opening crawl of Star Wars from 1977 using HTML, CSS and JavaScript because he couldn’t find a web version of it. Even better, the code is all up on Codepen.io and Pietrusky detailed his process on his website for all to see. Watch the opening sequence here (just click on the text). [Tim Pietrusky via BoingBoing]

Read more…


    




via Gizmodo
Awesome Guy Re-Created the Star Wars Opening Crawl with HTML and CSS