Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need to run several maintenance scripts Expand / Collapse
Author
Message
Posted Tuesday, November 06, 2012 2:23 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 9:57 AM
Points: 24, Visits: 386
Hello there.

I need to run a number of scripts (which will take a number of hours) that involve data purging from a database. When I reach the point of having to run it in Production, which is a highly transactional based environment, I need to effectively to make the database inaccessible from the web frontends and other web services.

I have considered two options.

1. Set the database in SINGLE USER MODE and run the scripts
2. Uncheck the "Allow remote connections to this Server" option at server level and run the scripts.

I am also considering using sqlcmd to run the scripts from the command line as part of option 1.

I would appreciate opinions on either approach or possibly any suggestions other people may have used in similar situations that were successful.
Post #1381455
Posted Tuesday, November 06, 2012 2:36 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, August 01, 2013 10:17 AM
Points: 323, Visits: 984
if you are feasible to work in data center or where the physical server is kept,
you can pull out the network cable connected to your server machine .
but before check if any users are connected to sql server .


-----------------------------------------------------------------------------
संकेत कोकणे
Post #1381458
Posted Tuesday, November 06, 2012 4:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 9:57 AM
Points: 24, Visits: 386
Thanks for the suggestion but that's not possible, as Server is hosted at a remote site.
Post #1381480
Posted Tuesday, November 06, 2012 4:15 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, April 14, 2014 3:56 AM
Points: 162, Visits: 657
I would suggest putting the DB into single user mode and run your scripts - but you do need to send out some kind of warning to the users I would think.

Also, I would think it would be best to do that when the DB is not used (e.g. at night? 02:00 AM?) - you could schedule the jobs at that time - part of your script would be to put DB in single user mode.

Not allowing remote connections to the server sounds a little risky to me - what if something goes wrong, then you will need to make your way over to the physical box and all that?

B
Post #1381483
Posted Tuesday, November 06, 2012 7:23 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:46 PM
Points: 35,959, Visits: 30,250
Be real careful using the single user mode. If YOU lose, drop, or close your connection, on of the Web Services will grab the single connection almost immediately and you won't be able to get back in to set it to multi-user without having to find and shut down all the web services or bouncing the server with it in a maintenance mode.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1381563
Posted Tuesday, November 06, 2012 7:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, June 11, 2013 4:06 AM
Points: 146, Visits: 281
Personally, what I tend to do in this scenario, is set a job to run overnght using SQL Server Agent.
Rather than making alterations to SQL also, if all users are coming from a sole source (i.e. a web front end) then why not just take down the site temporarily while the work is being carried out?
You can also build steps into an Agent Job Script, which incorporates cmdexec commands to stop and start the web services before and after the job has completed...

If you're confident in the job and have rough times from testing, then it will save you having to babysit the job (set email alerts for failures).
Post #1381565
Posted Tuesday, November 06, 2012 7:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 9:57 AM
Points: 24, Visits: 386
Jeff Moden (11/6/2012)
Be real careful using the single user mode. If YOU lose, drop, or close your connection, on of the Web Services will grab the single connection almost immediately and you won't be able to get back in to set it to multi-user without having to find and shut down all the web services or bouncing the server with it in a maintenance mode.


I have considered this and it is a major concern. As part of general deployments to Production, websites are disabled but as far as I know web services remain on. I think it best therefore to disable all web sites and services and run the maintenance scripts then, outside of core hours obviously.
Post #1381566
Posted Tuesday, November 06, 2012 8:05 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, March 28, 2014 9:22 AM
Points: 64, Visits: 376
Could you disable all logins except one, and use that login for this maintenance?
Post #1381591
Posted Tuesday, November 06, 2012 8:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:26 PM
Points: 12,744, Visits: 31,071
scogeb (11/6/2012)
Could you disable all logins except one, and use that login for this maintenance?


maybe a create a logon trigger that prevents anyone from connecting unless from local connection?
then do the work, and drop the login trigger when completed?


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1381601
Posted Tuesday, November 06, 2012 9:48 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 5:20 PM
Points: 237, Visits: 763
If the web front end/services have specific logins (as they should), then your best bet is to disable the logins
during maintenance. Or if you are using roles, you could kick them out of the roles during maintenance and add
them back in when you are done.

What is your security model like?

What is the requirement for the web front end/services? Do they need to know that maintenance is taking place
and be able to display a meaningful message?
Post #1381649
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse