Author: way0utwest

  • T-SQL Tuesday #186–Agent Jobs

    It’s that time of the month again, when the T-SQL Tuesday blog party takes place. I manage this site, and am looking for hosts all the time. This month I managed to convince Andy Levy to host, and I’m grateful for his participation.

    His invitation is asking about SQL Agent jobs and how they are managed. It’s focused, but he gives a lot of choices for how to examine this subsystem in SQL Server.

    Note: if you work in Oracle or PostgreSQL or anything else, how do you schedule work in an automated fashion? Cron? Something else? You can still write.

    If you want to host, ping me and I’ll get you a month.

    Designing Jobs for an Enterprise

    I used to work in a fairly large enterprise (5,000+ people, 500+ production SQL instances) with a small staff. It was 2-3 of us to manage all these systems, as well as respond to questions/queries/issues with dev/test systems. As a result, we depended heavily on SQL Agent.

    We decided on a few principles which helped us manage jobs, with a (slow) refactoring of the existing jobs people randomly created with no standards. A few of the things we did are listed below. This isn’t exhaustive, but these are the main things I remember.

    Name schedules clearly

    Scheduling gets crazy. As a result, we would try to name with the days and times something ran. For days, we’d use SMTWRFSa. If something ran every day, that was in the name. If it were week days, then it had MTWRF in the name. Thursdays only were R.

    We’d include a time, such as 0200 or 1830 in there. If there were just one or two times, we’d list those. If it were more often, we had “every hour” or “every 15 minutes”.

    This wasn’t perfect, but it made most schedules clear.

    Job Names and Descriptions

    We tried to make job names clear with a starting noun (Backup, Maintenance, Sales), which was a little overloaded. It was a DBA thing for most work that DBAs might run and a department for those business level things.

    Job Steps

    I tried desperately to get away from code in the job step and use stored procedures instead. This helps us tune and watch things that run, and it keeps code in code places.

    For DBA stuff, we had a DBA database on each instance for our procs. We’d put our code in there (Ola’s procs, our own custom maintenance things, checks, ETL, etc.). This way we could more easily run server level stuff.

    For business level jobs or things related to a db, we want a proc in there. Then call that. This also let us often have a logging table alongside the proc where we could track progress.

    Alerts/Operators

    Luckily we had a monitoring solution that notified us when jobs failed. We didn’t use these systems. However, we did have an auditing report that queried DMVs and noted job failures and stored this data in a table (rolling 30 days) and used it to produce a daily report we archived in a folder.

    This was for our ISO compliance and auditors loved it. We would store a daily report and then add a daily note of any actions we took. That way we knew what we did and had a record.

    Summary

    For most of the other options (categories, etc.) we ignored them. The goal was to keep things very simple and streamlined. We had a standard job we deployed to most servers as part of a build process.

    We also drove a lot of activity in code off queries as much as possible and only used a table to log exceptions. We might have a table that stored the “FinanceDW” db name as an exception. The backup process would get a list of all dbs, and then delete those in the exception table. Then run as normal.

    K.I.S.S. worked very well for us.

  • Deleting a Database

    Who among us has deleted a production database?

    I’d hope it’s very few of you that have done this in your career. I’m sure a few of you have deleted (or truncated or updated all rows for) a table in production. I’ve done that a few times, but fortunately, I’ve been able to recover the data quickly. I had this happen in SQL 6.5 and was grateful I could start a single-table restore before my phone rang.

    Here’s another question: which of you has had a storage admin delete or remove some remote storage and cause you database problems? Has anyone had that happen in their environment? I haven’t had this in production, but I have had this happen to test systems, and I was very irate with the storage people when it did. After that, I’m sure they were very cautious about changing any configuration for database servers. I’m also sure that also contributed to my struggles in getting more space promptly as well, so I’m not sure I came out ahead in that situation.

    A hospital system had issues after this happened to them: engineers deleted critical storage that connected to a database system. Fortunately, no services have stopped, and no patients are missing services, at least as far as we know. Everything has to be moving slower, and that might mean that staff is spending more time on “downtime procedures”, i.e. paper, than focusing on patients. Knowing a few medical professionals, this means they’re more stressed and working harder to be sure patients aren’t affected. Sucks for them, and I doubt the hospital compensates them for an engineer’s mistake.

    I haven’t heard about this happening in a long time, and I’m surprised by that. Almost all storage these days for server systems is remote, especially in the cloud, and it would be easy to click the wrong button or select the wrong disk when re-configuring a system and remove critical storage. Maybe we’ve gotten better at popping up warnings that slow people down and prevent mistakes.

    Or maybe we don’t delete disks and only add them to database systems 😉

    In any case, I hope they can recover things quickly and easily. If you’ve seen this, let me know. If you haven’t, here’s a reminder that this could happen. You should be sure your backups are running AND you can perform a test restore.

    Steve Jones

    Listen to the podcast at Libsyn, Spotify, or iTunes.

    Note, podcasts are only available for a limited time online.

  • SQL Server Engineering in Austin

    I was lucky enough to attend SQL Saturday Austin 2025 a little over a week ago in conjunction with some work at the Redgate office. The opening keynote at the event was given by Conor Cunningham, who is an architect at Microsoft and runs the engineering team in Austin for the Data Platform. His talk was very interesting and engaging. This was about half the room below.

    20250503_090655

    I’ll describe the talk, which was great, but I’m probably mis-stating something. Keep in mind I’m writing this a few days later from memory.

    One of the interesting things Conor talked about was the engineering process in Redmond. The main thrust was that they work in 6 month planning cycles. Work gets submitted, voted on, works through groups, and as a result, most of the things approved are related to more revenue in some way.

    Good for Microsoft, not something many of us love.

    In Austin, they tackled things differently. You can see the outline in the image below. Conor hired a few engineers here, usually out of college, and they work on new features. Things that are too small to make the list in Redmond, but this also helps grow/train engineers on how to write production quality code.

    20250503_091036

    What do they work on? He had a few slides, but IS [NOT[ DISTICNT was one. He described this a bit, but the cool thing was a bunch of the SQL 2022 features were from Austin. String_Split with the ordinal, the bit functions, and a bunch more.

    20250503_091842

    Basically all the cool features I appreciated, including DATETRUNC, came from this small team. I am very glad they exist.

    He also delved into the challenges of doing remote work. Building SQL Server is a non trivial procss, and they’ve been working to try and make this easier. They refactor code, they try to break things out so engineers can get quicker feedback, write more tests, etc. to make their software engineering easier.

    20250503_094728

    He also talked about their work with hardware manufacturers and some of the optimizations he’s done with CPU and the ATX instructions to make SQL Server a little faster. For some types of queries, they’ve great improved the speed of internal SQL Server processing.

    It was a great talk and quite entertaining. Hopefully some of you will see it elsewhere, or he’ll do it again in Austin and you can come.

     

  • Database DevOps Recommendations

    The DORA organization is constantly researching how to better produce software at any organization. This is similar to work done by Carnegie Mellon Software Engineering Institute many years ago. Both groups are trying to determine what things help engineers work better and produce high-quality software.

    On the DORA site, there is a database change management page, where they recommend approaches to managing database schemas. The main thing they talk about is treating all schema changes as migrations, which is something some people do. However, many teams also like a desired-state-configuration approach, where they just deploy all the changes from dev (or QA) to prod in a state-based flow. Both can work, but I do think as software matures (and becomes legacy), migrations are preferred. The article lists lots of frameworks in different languages. Flyway is among them, which is the product on which I work and sell at Redgate. If you haven’t looked at a migrations framework, I’d recommend you do so. They do really give you a tremendous amount of control and flexibility. There are trade-offs, so I’m not blindly recommending this approach, but it’s worth educating yourself on how migrations frameworks work.

    The other thing they recommend is using a zero-downtime change approach. They list a few strategies that you can use make changes without impacting clients. None of these are hard, but they require a little coordination with application developers, as well as some patience in splitting changes across multiple deployments. They also require good coding practices, so many of us have a few habits to unlearn.

    DORA does also recommend considering a NoSQL database since you don’t have downtime from schema changes, but my view is that you’re likely making trade-offs that aren’t worth in. If you read that paragraph in the article, my guess is many application developers read everything but the last sentence, or they dismiss that last sentence. Then they just start developing against a NoSQL database platform and expect it to magically be better. It might be, but it might not work as well.

    The one thing I wish they had a better answer for was how to measure our work as database developers. This section doesn’t give you any concrete things to measure, just some suggestions, which are often hard for people to implement in their environment. Most of us don’t have salary or time numbers for others, and need more help in trying to determine how to measure changes. Maybe the one good measurement to aim for is 100% of database changes made by automation, rather than manual execution.

    Steve Jones

    Listen to the podcast at Libsyn, Spotify, or iTunes.

    Note, podcasts are only available for a limited time online.