Need to run several maintenance scripts

  • 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.

  • 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 .

    -----------------------------------------------------------------------------
    संकेत कोकणे

  • Thanks for the suggestion but that's not possible, as Server is hosted at a remote site.

  • 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

  • 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.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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).

  • 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.

  • Could you disable all logins except one, and use that login for this maintenance?

  • 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!

  • 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?

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply