Author: Calin OPREA

  • Execution of job LSRestore_ failed. See history for details

    I’ve been itching all day to write about this, but I got caught in way too many other small issues, but now, that I’m home, I hope I get the chance to write about this little mishap that I got today.

    I was documenting an emergency role change for a secondary involved in log shipping and guess what, I managed to f… screw log shippingJ. Yeap, on the prod servers.

    Here’s a little repro of what happened.

    I’ve created log shipping on the same instance, AdventureWorks being the primary DB, while test is the secondary. See below for details.

    As you can see, I decided to have my database as read-only, so users can actually query tables. Sure enough, I can access the DB, as seen below:

    Heck, I can even open a query window to query some data, right? Wrong. If you open a new query window and forget about it, this is what happens:

    And this is the actual print screen from production; apologies for all the rectangles and stuff, but it’s a bit of a confidential stuff (except for the error log):

    I put this here because I find it fascinating: the actual error message is hidden in one of those “successful” stepsJ.

    Anyway, a quick look using sp_who2 has shown the culprit:

    Apologies for the extremely truncated picture, but well, you get the idea.

    I just ran KILL 55 and I was good to go.

    I hope this helps.

    Best regards,
    io

  • Book review: SQL Wait Stats Joes 2 Pros: SQL Performance Tuning Techniques Using Wait Statistics, Types & Queues

    Alright, I bought the book and started reading it.

    Now, this is just my very first impression with the book, so don’t take it too seriously.

    First of all, on a 1 to 5 scale, I would give it somewhere between 3.5 and 4. In other words, above average. OK, hold on, justice is NOT being done here…

    Being a DBA on some large scale systems, I had different expectations. For me (also and MCT), the book is a bit shallow to make it a must read. But truth be told, let me quote the authors: “This book is a humble attempt to make these concepts more accessible to SQL developers. We consider this book a first version of the ongoing research in this area”.
    And now let me give you an example where I tend to disagree with the authors: CXPACKET. We all know that there are no hard rules attached to it, and we also know that we first must “experiment” and see what works best for us. I wish that was true – how many of the real-world DBAs are allowed to “experiment” on production systems? Yes, I know, we have stand-by servers that should replicate the prod servers, sandboxes to play with… Guess what, it’s not always the case.
    Also, consider this article: http://support.microsoft.com/kb/329204/ – we just had this issue with Microsoft. They said (based on what, really beats my knowledge) that we should set the MAXDOP to 8, while the article clearly states that for our particular scenario (2 physical processors, 8-core each, HT enabled), we should set MAXDOP to 2 (yes, that Hyper-Threading thing, I thought it was dead already, but know, it’s like a zombie coming from the dead). Of course, this is going far beyond common knowledge, and until you hit that particular brick wall, you have no idea that it’s there.

    For all these reasons, the book gets a 3.5 – very easy to find the most common wait types, along with decent explanations, but that’s about it.

    Being and MCT, I simply love to see a book that it is this accessible to a large population of SQL developers and DBAs alike. I simply envy the two authors on how they managed to assemble such a fine writing, that is easily digestible to so many. Also, from my personal point of view, it’s a must read, because it completes the Microsoft Official Curriculum beautifully.
    Almost forgot to mention, most of my students are in the Level 300 area, so pretty tough questions appear during the trainings.

    For all these reasons, the book gets a 6 out of 5. Not only that, but Chapter 11 contains a set of “references”, which are actually links to various blog posts. I would pay all the money again, just for that single page.

    Just to summarize: doing the math, 6 + 3.5 = 9.5, which, divided by 2, gives you 4.25 – this would be the final grade.
    And yes, not only that I would buy the book again if I had to choose that, but I really think of buying it as a present.

    Great job, Mr. Dave and Mr. Morelan.

    I hope this helps.

    best regards,
    io

  • Failed to load msxmlsql.dll is SQL Server 2005

    Now, there are a plethora of posts about it, and two of them really stand out:

    Also, you will find many blog posts suggesting to attempt a repair of the MSXM 6 (currently, at Service Pack 2).

    I have another one to add to this: if the msxmlsql.dll file is where it supposed to be, namely: C:\Program Files\Microsoft SQL Server\90\Shared, and, of course, it is at the correct version level, it wouldn’t hurt to go to C:\Program Files\Microsoft SQL Server\90\Shared\Resources\1033 and look for the msxmlsql.rll.

    In our particular case, it was missing, therefore… well, not working:-).

    I hope this helps.

    Best regards,
    io

  • Tool review – SQL Backup and FTP

    We currently do have a process in place that takes a full backup, creates some zip files, sends the over to another server, and whatever else is left. Obviously, it is prone to errors. Therefore I was more than interested to see this tool in action (as recommended by Pinal Dave).

    Also, I will not bother you how to install the tool, just go to the site, download and install the tool, and also make sure you read the tutorial that appears after the installation is complete.

    What I want to mention, though, is where I think this tool is going: to developers that need a very quick access to a database backup that they can restore on their machines, as well as accidental DBAs that need to take care of small IT shops.

    What I see as drawbacks:

    • No way I can use it with anything else than a full backup (filegroup backups, anyone?)
    • No way I can use it with a VLDB – currently we do have some 1+ TB databases that are giving us nightmares, among other things
    • No way I can catch some tricky errors when talking about backups. Just to give you an example, we just had a failed backup that was not caught in the TRY – CATCH block (see this post).

    What I see as major benefits:

    • Open SSMS locally to have a backup of, say, AdventureWorks? Why? I can easily do it with this tool
    • Scratch my head where should I put my backup? Why? I have a wizard for that, or, better yet, let the sys admin handle it
    • Why buy expensive software that offers me features that I’ll never use?
      Just to give you an example, how many of us have Red Gate’s SQL Backup to have a play with? And HyperBac? What is that? J Kidding, Red Gate, I LOVE YOUR TOOLS!

    As a simple conclusion: if you’re an accidental DBA in charge of a small IT shop, or a developer that needs quick access to a centralized folder will all the backups for either a particular DB or some database backups, this tool is for you. Look no further, it’s more than you’ll ever need.

    As for the rest of us, paranoid DBAs with hundreds of database servers, and TB-sized databases, there are some rumors on the street that soon enough we’ll have a way to teleport our backups to the desired location, all at the speed of light. Oh, wait, that was Star Trek…

    Best regards,
    io

  • Online index operations are fully logged in SQL Server 2008 and later!

    The title is self-explanatory, but I had no idea until I recently saw my transaction log size skyrocketing; and here’s the article: http://support.microsoft.com/kb/2407439

    best regards,
    io

     

  • Backup, file manipulation operations and encryption changes on a database must be serialized

    I love scratching my head; that’s why I became a DBA in the first place, I get the chance to scratch my head and swear a lot, without anyone complaining about it.

    The most recent head-scratching situation was when we checked our backup history table (we use a custom script, and no, we’re not allowed to change things in production as we please) and saw something similar to this:

    Ooops, a NULL entry, this is not good.

    After some testing, I arrived at this error:

    “Backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized“. For the ones interested, here’s the link to error messages in SQL Server 2008 R2, 3xxx series.

    Now I have something.

    It turns out that the autogrowth is set to 1 GB, which is totally not sufficient for our particular DBs. In other words, both data files and log files must grow, and every now and then the growth happens during the backup process.

    The solution is very simple: change the autogrowth to something more meaningful to your DB; ah, also, please make sure you don’t shrink the transaction log file because “it looks big”. Yes, I know, we should all have our DBs properly sized, but let’s just say that most of the IT shops are far away from the fairy land.

    I hope this helps.

    Best regards,
    io

  • “A MOF syntax error occurred” when installing SQL Server

    OK, in my case it was a clustered environment, but I bet this applies to single instances as well.

    I ran the setup (it’s not quite my first SQL Server install, you know) and after configuring all the steps, I hit Install and waited. The good news is that I didn’t have to wait too much. The bad news is that the setup failed with this error: A MOF syntax error occurred. Riiiight, veeery self-explanatory.

    However, the solution is simple:

    Open the “Summary <<impossible path to type>>.txt” file by clicking the link provided (see above picture). Locate the “failed” word (yes, CTRL + F, search for failed). This is what I got:

    This is helpful… not, with one tiny exception: the Detail.txt file.

    Copy the Configuration error description (“A MOF syntax error occurred”) and open the Detail.txt file from the mentioned location.

    Search for the error description.

    This is what I got:

    OK, now assuming that something happened and that’s why I got the error, I looked for something that might have happened before the error was written out (yes, I know, I’m a genius).

    Not to keep you too much staring at the above picture: I got something called “Access denied“.

    Resolution, at least in my case: WTF couple of times, and then check to see what exactly is missing. In my case there was a domain group called DevUsers that was supposed to be in the local administrators group for both nodes. It was not there.

    I hope this helps some desperate soul out there.

    Best regards,
    io

  • master database restore failed in SQL Server 2008 R2 SP1 CU1

    We just woke up having 30+ instances of SQL Server 2008 R2 Enterprise edition in development and testing. Which is bad for obvious reasons. So basically I have to uninstall the Enterprise and re-install Developer Edition on all the machines.

    Steps to take:

    • Create a maintenance plan to back up all the databases (simplest way; I create the plan, no schedule, just execute it)
    • Uninstall the Enterprise Edition (10.50.1600, 10.50.2500, etc – plain English: RTM, SP1, etc)
    • Install Developer Edition (10.50.2769 – plain English: SP1 CU1 – I have slipstreamed both SP1 and CU1 in the install media)
    • Restore master (as of documented here)
    • Restore msdb
    • Launch SSMS and clean all the crap that’s left behind

    All is good until I restore the master database and get the following error (see print screen below):

    This basically tells you that you cannot restore the master database from a lower version (the RTM) to a higher version (SQL Server 2008 R2 SP1 CU1). When this happens, chances are that you had some incorrect entries at the metadata level – in my case, I had some bogus DBs, which although appeared in SSMS, they were not physically present (I only saw this when it was too late).

    Now for the crazy hack: restore the master database under a different name in SSMS (see below):

    Leave the defaults under Options. After the backup completes successfully, and trust me, it will, stop all the SQL related services (do me a favor and do it from SQL Server configuration manager).

    Now go to <<drive>>:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA. Rename the master database files to something else. Do the same for the newly created database, but this time rename them so they can replace the old master database. See below:

    In my example, I renamed testmaster database to be master.mdf and mastlog.ldf. the old master database is master.aaa and mastlog.bbb. as you can see, I did the same for msdb, as I needed the jobs, job history, and so on. That’s it, you now have a database that will reflect correctly what you had before.

    Final step, cleaning the crappy leftovers: in my case, the only thing that I had to do was to fix Database Mail; for this, I did the following:

    alter
    database msdb

    set
    new_broker
    with
    rollback
    immediate

    And it worked.

    It’s a crazy and stupid hack, but yet again, when everything else fails, you need to try desperate measures.

    As a conclusion, before doing any kind of migration, I urge you to make sure you have a usable server that can be migrated. The few extra minutes will pay for themselves big time at a later time.

    Best regards,
    io

  • Is truncate logged or non-logged in SQL Server?

    Okay, second blog post in one day – slowly trying to recoverJ.

    Below is an excerpt from a stored procedure from BizTalk server:

    –If you are doing this we assume it is because you have a huge, old db so it is just faster for us to

        –find things which are not done and hold onto them then the other way around.

        –if we crashed after grabbing these uncompleted instances but before reinserting them, we are okay

        –because we have a unique constraint on the serviceinstanceid identity column so we will just ignore dupes

        –Note that if you run this, you need to have the tracking host stopped so that no new data is being inserted while this runs.

        –This hard purge assumes that inserts have stopped so that we can do unlogged operations like truncate table and not hold locks for

        –long periods of time. Make sure if the system crashes while running this, you get a full clean run before restarting the tracking service or

        –you will end up in a non-deterministic state.

    What struck me was: “This hard purge assumes that inserts have stopped so that we can do unlogged operations like truncate table”. I beg your pardon?

    READ THIS: TRUNCATE TABLE IS LOGGED!!! Okay, to do some justice: it’s minimally logged, which in plain English would roughly translate into the fact that only allocation and de-allocation of pages (that is, data file pages) are logged. But this is another discussion (along with ghost cleanup), so we’ll tackle it some other time.

    Moral of the story: because somebody from Microsoft said so, it doesn’t mean it is soJ.

    Best regards,
    io

  • Fix orphaned users in SQL Server 2005 – not

    A quick one, again (haven’t been blogging for a while, I have like a ton of blogs on my mind, lack the time, though): I think most of the DBAs have stumbled upon “how to fix orphaned users in SQL Server”, right? Well, a quick overview of the script:

    SET
    NOCOUNT
    ON


    SET
    QUOTED_IDENTIFIER
    OFF


    GO

    USE
    <database name>


    GO

    DECLARE @sql varchar(100);

    DECLARE curSQL CURSOR
    FOR

    SELECT
    ‘EXEC
    sp_change_users_login
    “UPDATE_ONE“, “‘+ name + “‘, “‘
    + name +
    “”

    FROM
    sysusers

    WHERE issqluser = 1


    AND
    suser_sname(sid)
    IS
    NULL


    AND name NOT
    IN
    (‘dbo‘, ‘guest‘)

    OPEN curSQL

    FETCH curSQL INTO @sql

    WHILE
    @@FETCH_STATUS
    = 0 BEGIN

    EXEC (@sql)

    PRINT @sql

    FETCH curSQL INTO @sql

    END

    CLOSE curSQL

    DEALLOCATE curSQL


    GO

    So far, so good. Or is it?

    Let’s have a very quick look on what’s under the hood, and for that we’ll actually query the sysusers table.

    select
    uid, name, sid, issqluser from
    sysusers
    :

    and here’s the print screen from my test machine:

    Now, please bear in mind that I don’t want to point anything else, BUT: you can (and actually will) have SQL users that are… well, not SQL Users (that is “issqluser – is set to 0) J. This happens for users associated to logins that are mapped to Windows accounts/groups. I hope this helps.

    Best regards,
    io