Tuesday, September 20, 2016

Working with Live Database

Working with Live Database

Connecting to live database from development environment


1 - Never connect to live database from developer environment
2 - If it is necessary to debug live database then ask for the live back up to be restored on staging database server
3 - If it is necessary to work directly to live database from developer environment then follow below precautions


If connecting to live database from developer environment then following things need to be considered


First and foremost ask to take backup of live database so we don't loose any data - no backup, no work on live database


* If connecting through code

  • Make sure all the scheduler are commented out/turned off
  • Make sure all the external service push or pull is commented our/turned off
  • Never update live database from developer environment - Fix the code and push it to live server and re run it.

* If connecting through Sql server from developer environment


  • Always wraps command in BEGIN TRAN command see example below and comment out the COMMIT TRAN section so nothing applies to live server mistakenly
BEGIN TRAN 
 update aa set City='chennai',LastName='vinoth'; 
-- if update is what you want then
-- COMMIT TRAN 
-- if NOT then
ROLLBACK

  • It's VERY IMPORTANT to remember to either COMMIT or ROLLBACK; This wouldn't be a good time to go to lunch while forgetting the transaction open!  :-) Open Transaction would lock the database.
  • If Update is necessary then always ask  I.T guy to do backup
  • If it is small task then make sure you run the select command first to make sure it will affect only required table and row for .eg

SELECT Column1 , Column2
-- UPDATE t SET Column1 = x, Column2 = y
FROM MyTable AS t
WHERE ...



Always do the peer review before running any script or code on live databsae

No comments:

Post a Comment