SQL Clone
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 Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 487
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
SSC Eights!
SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)SSC Eights! (853 reputation)

Group: General Forum Members
Points: 853 Visits: 1022
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 Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 487
Thanks for the suggestion but that's not possible, as Server is hosted at a remote site.
bleroy
bleroy
Say Hey Kid
Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)Say Hey Kid (661 reputation)

Group: General Forum Members
Points: 661 Visits: 758
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 Guru
SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)SSC Guru (219K reputation)

Group: General Forum Members
Points: 219952 Visits: 42002
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
McSQL
McSQL
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1278 Visits: 301
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 Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 487
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-Addicted
SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)

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

Group: General Forum Members
Points: 74035 Visits: 40974
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
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1409 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