Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need to run several maintenance scripts


Need to run several maintenance scripts

Author
Message
Paul Treston
Paul Treston
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 448
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.
sanket kokane
sanket kokane
Old Hand
Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)Old Hand (331 reputation)

Group: General Forum Members
Points: 331 Visits: 1019
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 .

-----------------------------------------------------------------------------
संकेत कोकणे
Paul Treston
Paul Treston
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 448
Thanks for the suggestion but that's not possible, as Server is hosted at a remote site.
bleroy
bleroy
SSC-Enthusiastic
SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)

Group: General Forum Members
Points: 172 Visits: 739
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
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44778 Visits: 39845
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
McSQL
McSQL
SSC-Enthusiastic
SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)

Group: General Forum Members
Points: 162 Visits: 299
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).
Paul Treston
Paul Treston
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 448
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.
scogeb
scogeb
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 420
Could you disable all logins except one, and use that login for this maintenance?
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14897 Visits: 38890
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

arnipetursson
arnipetursson
Old Hand
Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)Old Hand (337 reputation)

Group: General Forum Members
Points: 337 Visits: 1019
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?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search