Tag: Redgate

  • Monday Monitor Tips: Changing the Fragmentation Alert

    I had a customer that was concerned about the fragmentation alert for indexes and wanted to know how to change it. This post discusses the change.

    This is part of a series of posts on Redgate Monitor. Click to see the other posts

    Finding Alert Configuration

    The settings for Redgate Monitor are available with the gear icon in the upper right side the menu area. You can see this below.

    2024-07-22 16_52_18-ssc-db-n3_(local) - Server Overview — Mozilla Firefox

    Click this to get a list of settings. The second section below has the alert settings, which you can see here. Click this.

    2024-07-22 16_53_49-Zoomit Zoom Window

    This brings up a long list of alerts that are a part of Redgate Monitor. Scroll down a bit and you will see a fragmented indexes alert.

    2024-07-22 17_11_54-Alert settings _ All Servers — Mozilla Firefox

    If you click this, you may see this, as the alert is disabled. This has not proven to be a very useful alert for most organizations, so it’s off. However, you can click the “customize” radio button.

    2024-07-22 17_12_05-Edit Alert Configuration — Mozilla Firefox

    When you do this, you should then see the alert settings. This is defaulting to all your servers, but you can customize the level of alerting by clicking on the left side to a server or group. I’ll cover that in another post.

    The key things here are that you can exclude read-only databases, as the fragmentation won’t change. Below that, you see there is a medium alert specified at a default of 60%. You can change the low/med/hi with the drop down as well as the percentage in the spinner.

    2024-07-22 17_12_19-Edit Alert Configuration — Mozilla Firefox

    If you want more than one alert, flip the “Use multiple alert threshholds” button and you’ll see three choices. I might suggest you not do this as if you worry about fragmentation, it’s likely only a low or medium alert.

    2024- 08_ 0029

    At the bottom, you can set a minimum index size. Smaller indexes aren’t a problem, so keep this relatively high. You might have to decide if 1000 pages is really high enough.

    Below this, you can set your notifications for this. In general, use the defaults and don’t customize this for an alert. The changes get hidden and people forget. Use the same settings everywhere.

    That’s about it. However, read these thoughts from Jeff Moden before you get too worried about index fragmentation.

    Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.

  • Expanding Northwind with Prompt+

    I was trying to do a little testing of our subsetter and needed a larger database. So I decided to ask Prompt + to help me with a little AI assist. This post looks at what happened.

    This is part of a series of experiments with AI systems.

    Getting More Data

    I had a Northwind_FullRestore from my experiments with Alex Yate’s quick PoC tool. I selected that database and asked for a little code. I asked the AI to give me 1000 more rows of data in the Customers table. I got this code.

    -- This script inserts 1000 rows data entry into the dbo.Customers table
    WITH numbers
    AS ( SELECT TOP (1000)
                 ROW_NUMBER () OVER (ORDER BY
                                       (SELECT NULL)) AS num
          FROM sys.all_objects)
    --INSERT INTO dbo.Customers
    --  (CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
    SELECT
       'CUST' + RIGHT('0000' + CAST (num AS nchar(4)), 5)
    , 'Customer' + CAST (num AS nvarchar)
    , 'Contact' + CAST (num AS nvarchar)
    , 'Title' + CAST (num AS nvarchar)
    , 'Address' + CAST (num AS nvarchar)
    , 'City' + CAST (num AS nvarchar)
    , 'Region' + CAST (num AS nvarchar)
    , 'PostalCode' + CAST (num AS nvarchar)
    , 'Country' + CAST (num AS nvarchar)
    , 'Phone' + CAST (num AS nvarchar)
    , 'Fax' + CAST (num AS nvarchar)
    FROM numbers;

    Then I decided to go big. I changed my prompt, as you see below, and got more data. My new prompt: expand this to add 10GB of data to this table

    I got this code:

    -- This script adds approximately 10GB of data to the dbo.Customers table
    -- Firstly, we need to calculate the approximate size of each row. 
    -- For simplicity, we'll assume each row is ~1KB in size after considering nvarchar data expansion.
    -- Therefore, to add 10GB of data, we need approximately 10,000,000 rows.
    WITH numbers
    AS ( SELECT TOP (10000) -- This will generate 10,000 rows in the CTE
                 ROW_NUMBER () OVER (ORDER BY
                                       (SELECT NULL)) AS num
          FROM
            sys.all_objects a
          , sys.all_objects b)
    INSERT INTO dbo.Customers
       (CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
    SELECT
       'CUST' + RIGHT('00000000' + CAST (numbers.num + seqnum AS nvarchar), 8) -- 8 character CustomerID to accommodate large number of rows
    , 'Customer' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Contact' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Title' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Address' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'City' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Region' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'PostalCode' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Country' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Phone' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Fax' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    FROM
       numbers
       CROSS JOIN
         ( SELECT TOP (1000)
                  ROW_NUMBER () OVER (ORDER BY
                                        (SELECT NULL)) AS seqnum
           FROM sys.all_objects) seq;

    The Results

    The results were a bit underwhelming. I ran it and got this:

    8-2-2024-0005

    The problem here is that the CustomerID is a 5 character field. The comment in the code notes that this is now an 8 character field, but that’s not great as I might not want to change the size of the field.

    I then asked this: change this script to ensure the customerID is less than 5 characters and alphanumeric

    I got the same script, but the first line of the select was:

    'CUST' + RIGHT('00000000' + CAST (numbers.num + seqnum AS nvarchar), 8) 
    -- 8 character CustomerID to accommodate large number of rows

    Now when I run it, I get a problem with postal code, which now has the truncation error.

    My Thoughts

    It’s easy to say this was a failed experiment. I didn’t get working code. But I got a bunch of code that was close to what I need, in a fraction of the time that it would take me to write this, even with SQL Prompt. Then add in the fact that I can edit this code to what I need, which works, and saves me times.

    I think this has potential for shortcutting some work and getting me closer to what I need quickly, even if it’s not perfect. If I’d have asked a junior dev to help me with this, I might still have to edit their code. Just as I do with my AI assistant.

  • Grouping by Object Type in SQL Compare

    A customer recently was asking about grouping objects by type to see all the differences in two databases for one set of objects, like all stored procedures. This post shows how this works and what this changes for your system.

    This is part of a series of posts on SQL Compare.

    I have two databases, Compare_1_Source and Compare_2_Destination. I made a number of changes to the Source db and when I run SQL Compare between these, my default view shows me the different objects, as well as those in one database and not in the other. You can see this below.

    Screenshot 2024-07-31 170641

    This is the way most of us want to make changes, by deciding from this short list what changes to deploy. If you look closely, you can see there are 115 objects that are identical, so it’s nice to be able to see what has changed.

    However, I have had a few people ask to see all the stored procs that have changed, so they can decide what needs to move. They aren’t ready for table changes.

    In the upper right corner, above the destination database, I have a drop down for grouping options. I can use the default (type of difference), switch to type of object, or have no grouping.

    Screenshot 2024-07-31 171350

    If I choose object, I see this grouping. In here, the stored procedures are expanded, showing my differences. Second, in the middle, near where the checkboxes are for object selection, I see a count of how many objects are selected, and how many are changes. However, I don’t know the type of change.

    Screenshot 2024-07-31 171501

    I’ll modify a procedure and delete one and I see something slightly different. Now I see the object name to the right side of the checkbox, so I can infer a change if the name is on both sides, or a delete if there is an “x” next to the name.

    Screenshot 2024-07-31 172047

    My default view of tables is shown below. Note that my table changes are mixed within non-changed tables.

    Screenshot 2024-07-31 171517

    However, I can click on the Last modified column and resort the data. If I sort descending, then I see my table changes at the top.

    Screenshot 2024-07-31 172416

    Toggling these settings allows me to see different views. If I just want changes without groups or differences, then I can set no groups and see this (I’ve sorted by modified date).

    Screenshot 2024-07-31 172450

    I have a request to hide the unchanged objects, but that’s not something we do now, nor am I sure we will change things. You can submit your own ideas on Uservoice and get some votes from friends.

    SQL Compare is an amazing tool that millions of users have enjoyed for 25 years. If you’ve never tried it, give it an eval today and see what you think.

  • Monday Monitor Tips- Enabling Index Tracking in Redgate Monitor

    There is a new index feature in Redgate Monitor, but it’s disabled by default. This post shows how to enable things.

    This is part of a series of posts on Redgate Monitor. Click to see the other posts

    Getting Indexing Information

    If you look on monitor.red-gate.com, inside the details for one of your instances, there is a new Indexing tab. I’ve circled it below.

    2024-07-02 15_00_39-ssc-db-n3_(local) - Server Overview — Mozilla Firefox

    After clicking this, I see the data below for this instance. This shows me a lot of high level information usage on different indexes. The data shows index, then table, then database, but I can search/filter here. I can also sort by the columns, which contain size, updates, seeks, etc. Lots of data.

    2024-07-02 15_03_21-ssc-db-n3_(local) - Server Overview — Mozilla Firefox

    This is disabled by default, as the collection of this data used a lot of memory on the Base Monitor system for some users. Not necessarily something everyone wants, so we left it off.

    You can, however, enable it.

    Enabling Index Data

    There is a doc page for this feature, which I show below. This is a fairly easy procedure, but not everyone knows how to do this, so I’ll explain.

    2024-07-02 15_05_48-Indexes - Redgate Monitor 14 - Product Documentation

    If you look above, in the warning box, it notes how to enable this. From the base monitor, you need to add an environment variable.

    To do this on Windows, the easy thing is search the start menu for “environ”. You should see something like this. Pick the “edit the system environment variables” item at the top.

    2024-07-02 15_08_19-Media Player

    This should bring up the System Properties in Windows (desktop or server). You can also search for environment variables in the Control Panel. Earlier version of Windows let you right click the system and select properties.

    Notice the Environment Variables button at the bottom. We’ll click this.

    2024-07-02 15_08_59-System Properties

    This brings up a dialog that has two sections. We want the bottom, system variables, section. Click the New button at the bottom, below this list of system variables.

    2024-07-02 15_10_42-Environment Variables

    In the dialog, paste this in the variable name: SQLMONITOR_Indexes

    For the value, add “on”. I’m not sure if this is case sensitive, but past in lower case.

    2024-07-02 15_18_52-New System Variable

    Then you need to restart both the base monitor and the web server. This is in the Service Applet, where you can see the Base Monitor and the Web Service.

    Note: depending on versions, you might see this as “SQL Monitor Base Monitor” or “Redgate Monitor Base Monitor”.

    2024-07-02 15_23_01-LiveLabConnection (1) - 3.254.186.109 - Remote Desktop Connection

    Restart both of these services.

    When things come up, you’ll see blanks until some index data can be captured, but be patient and check back in an hour or two.

    Make sure you monitor memory usage on your base monitor machine. If you find yourself running low, you can disable this by setting the system variable to off. Or delete it.

    Or add more RAM. More RAM cures a lot of things.

    Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.