Blog

[Video] Office Hours: Surprise Edition

Videos
6 Comments

Y’all post questions at https://pollgab.com/room/brento, upvote the ones you’d like to see me cover, and then I talk through ’em.

There’s a slight problem with this episode: I forgot to hit the Record Questions button in PollGab, so I can’t quickly/easily generate the list of questions we covered. If you asked a highly voted question in the last week or so, it’s probably in here.


Is There a Bug in SQL Server’s MAXDOP Calculation? (Update: Yes!)

Configuration Settings
21 Comments

I think I’ve found a bug in SQL Server setup’s MAXDOP calculation, and I need you to take a second look. Setup is recommending MAXDOP 8:

Setup recommending MAXDOP 8

Which is odd, because this is running on an AWS i3.16xlarge with 2 sockets, 2 NUMA nodes, 32 logical processors per node, 64 logical processors altogether. In this screenshot, I’ve laid Task Manager alongside setup so you can see what I mean:

If you click on the “Configure the max degree of parallelism” link in setup, it says:

In this case, the SQL Server has multiple NUMA nodes, with greater than 16 logical processors per node – that’s the last line of the screenshot. In that line, Microsoft says MAXDOP should be half of the number of logical processors with a max of 16 – so 16.

But it’s recommending 8. Hmm.

Is Soft-NUMA the culprit? No.

After SQL Server finishes installation and starts up, the error log shows automatic soft-NUMA kicked in because NUMA nodes had more than 8 physical cores:

SQL Server errorlog

So it created 4 NUMA nodes, each with 16 logical processors. In that case, maybe the setup calculation was taking that configuration into account – 4 nodes, each with 16 cores. In that case, let’s revisit the guidance:

Now, the number in play is the 3rd line of the screenshot – “Less than or equal to 16 logical processors per NUMA node.” In that case, we’re supposed to keep MAXDOP at or below the # of logical processors per NUMA node.

Now, technically 8 is below 16 – but where the heck is 8 coming from? Why not, uh, 16, or 4, or 12, or for that matter, 2?

I’m guessing I’m missing something obvious, but I asked on Twitter, and nobody figured it out. Worst case, either the documentation is wrong, or setup is wrong, there’s some kind of other recommendation that isn’t shown in setup – like maybe there’s a hidden max of MAXDOP 8 during setup?

So, what’d I miss?

Update 1: one of the smartest SQL Server folks I know, Joe Obbish, writes that he thinks it may not be documented anywhere. It’d be cool if we did get it documented, though – whatever logic is good enough for setup should be good enough for KB 2806535, so users can make that same decision as their VM sizes grow.

Mystery Solved: Yep, There’s a Mismatch.

Microsoft employee Sean Gallardy answered that setup uses a different formula than the documentation recommends:

Step 1: Calculate Hardware NUMA and Soft NUMA
Step 2: Decide whether Hardware or Soft NUMA will be used
Step 3: Divide the total logical processors by the NUMA used
Step 4: If > 15 LPs/NUMA, MAXDop = (LPs/NUMA)/2, otherwise MAXDop = LPs/NUMA

Which means that if you have:

  • 14 logical processors per NUMA node: MAXDOP will be set to 14
  • 16 logical processors per NUMA node: MAXDOP will be set to 8

<sigh> That doesn’t make any sense, but it is what it is. It’s probably always been this way since SQL Server 2016 “fixed” MAXDOP by setting it during setup.


Who’s Hiring in the Microsoft Data Platform Community? November 2022 Edition

Who's Hiring
12 Comments

Is your company hiring for a database position as of November 2022? Do you wanna work with the kinds of people who read this blog? Let’s set up some rapid networking here. If your company is hiring, leave a comment.

The rules:

  • Your comment must include the job title, and either a link to the full job description, or the text of it. It doesn’t have to be a SQL Server DBA job, but it does have to be related to databases. (We get a pretty broad readership here – it can be any database.)
  • An email address to send resumes, or a link to the application process – if I were you, I’d put an email address because you may want to know that applicants are readers here, because they might be more qualified than the applicants you regularly get.
  • Please state the location and include REMOTE and/or VISA when that sort of candidate is welcome. When remote work is not an option, include ONSITE.
  • Please only post if you personally are part of the hiring company—no recruiting firms or job boards. Only one post per company. If it isn’t a household name, please explain what your company does.
  • Commenters: please don’t reply to job posts to complain about something. It’s off topic here.
  • Readers: please only email if you are personally interested in the job.

If your comment isn’t relevant or smells fishy, I’ll delete it. If you have questions about why your comment got deleted, or how to maximize the effectiveness of your comment, contact me.

Each month, I publish a new post in the Who’s Hiring category here so y’all can get the latest opportunities.


[Video] Office Hours: Answering Your Microsoft Data Platform Questions

Videos
1 Comment

Ask questions at https://pollgab.com/room/brento and upvote the ones you’d like to see me cover.

Here’s what we covered today:

  • 00:00 Start
  • 00:59 neil: is it dangerous/risky to expand a drive in azure with SQL data files on it? sql on azure vm. dont know what happens behind the scenes
  • 02:07 Brett: I am a consultant at a large cloud provider. I have to protect my job and not upset our customers too much. How do you recommend balancing the line when delivering bad news? At times I have to soften my words, but in reality everything is in the toilet.
  • 02:35 Madisynn: Does PostgreSQL handle xml / Json data any better than SQL server?
  • 03:14 Tobias: What is your opinion of the new buffer pool parallel scan feature in SQL 2022? When is this a compelling reason to upgrade from SQL 2019?
  • 04:41 Fyodor: What is your opinion of the Microsoft Azure Premium V2 cloud storage improvements (125 – 1,200 MBPS, 80,000 IOPS, 64TB)?
  • 05:40 Yitzchak: What kinds of performance issues have you run into with SQL Change Tracking?
  • 07:00 DBAInHiding: After 10y as a prod support DBA, I moved to ETL dev with T-SQL + SSIS for 5y. I still tinker with my DBA skills with a home lab setup and training up on PowerShell/dbatools. I’d like to go back to being a DBA but will my recent developer track be seen as an asset or hindrance?
  • 08:09 Efraim: What conditional debug message printing techniques do you like to use in your stored procedures?
  • 08:42 Pyjamarama: Hi Brent, SQLServer 2014 with LARGE amounts of multiple plans. I used your query to find the top10 queries involved (your “Why Multiple Plans for 1 Query Are Bad”post). They are SELECT statements by our PowerBuilder application.Parameter sniffing?What do you suggest we do? Thanx
  • 09:18 Magnús: Which windows server admin concepts / technologies should a SQL DBA be familiar with when running SQL Server 2019 on a Windows Server 2019 cloud VM?
  • 10:22 Haydar: What are common mistakes you see regarding the use of TSQL cursors?
  • 11:34 Jagelman: My Friend needs a Reporting Database on AWS RDS (SQL 2016). He plans to use replication, however there is a problem. The fact table is a partitioned, and has a clustered columnstore index, so it has no primary key (cannot be replicated). Any suggestions on how to deal with it?
  • 12:50 Hans_Niemann_is_innocent : Hey Brent, I’m 5 years into the DBA career and never had to deal with any complex corruption issues. Is this still an important skill? I’m thinking of complex corruption as something more than just doing backup/restore to get online. Go Hans Niemann!
  • 15:16 Yousef: What is your opinion of Azure Cosmos DB for PostgreSQL?
  • 16:24 Yitzchak: Can having a [UNIQUIFIER] hidden column on clustered index affect query plan / query performance?

 


[Video] Office Hours: Nine Minutes of Answers

Videos
3 Comments

Post your questions at https://pollgab.com/room/brento and upvote the ones you’d like to see me discuss during my live streams. This week, I took a break from working on my PASS Summit sessions in order to chat:

Here’s what we covered:

  • 00:00 Start
  • 00:32 Jeremy: We have an older web app we’re going to be rewriting to use microservices. We’ll also be migrating it from on-prem to Azure. Our dev consultant is recommending we use Postgres rather than MS SQL Server to save money. What are your thoughts on moving from MS SQL to Postgres?
  • 02:19 Peter: Have you ever deleted unused stats or think it might be worth deleting stats on a table to improve performance of a stats maintenance job? My pain point is an exceptionally long running stats update.
  • 03:27 Jacob H: Hi Brent, how do you approach tuning when you are not able to run a query in production?
  • 04:30 Kimberly Hathaway: Brent – battling sysadmins in my org. They want Veeam backups for all SQL svrs & not SQL backups. Claim is point in time DB recovery with Veeam. I say logs are not getting truncated so Veeam is not talking to SQL. Can you point me to a doc that will support this.
  • 06:19 Cats_Everywhere : Hey Brent, I’m planning a new SQL Server build. I expect the Business people want this server to exist for 8-10 years. Are there any good arguments (business people would love) to persuade them to stick to a 5 year max? I picked 5 years due to Patching support from MS.
  • 07:39 Ólafur: Any indexing tips for “SELECT DISTINCT F1, F2, F3”? Is this more / less important than indexing for the WHERE condition?
  • 08:17 Bingo Boy: What are the pros / cons of setting up a SQL Server learning environment for log shipping / A.G. using containers vs virtual machines?

Learn the Fundamentals of TempDB for Free This Week.

TempDB
5 Comments

Every weekday during the month of October, one of the modules from my Fundamentals classes will be absolutely free to watch. But you gotta watch it that day – you snooze, you lose.

For this week’s TempDB class, you don’t have hands-on labs, but if you want to follow along with the demos, I’ll be using the same 50GB Stack Overflow 2013 database we used during the first two weeks.

Eagle-eyed readers will note that this isn’t all of the modules from each class, nor is it all of my Fundamentals classes. That’s because this whole thing is a diabolical mind trick, dear reader. I aim to get you hooked on the quality of my online training, and then come November 1st, when my annual Black Friday sale starts, you’ll be ready to get out your wallet – or your boss’s wallet – to get a Recorded Class Season Pass: Fundamentals, or Mastering, or the Level 2 Bundle when they go on sale.


Let’s Hang Out in Person at the PASS Summit Next Month.

#SQLPass
10 Comments

I’m so excited to see everybody again at the PASS Data Community Summit in Seattle on November 14-18.

I’M BACK IN PERSON!

Here’s the crazy part: I’m not going to attend a single session. Not one. (Well, except the ones I’m teaching, and the keynotes.)

Instead, I’m gonna spend every single conference hour hanging out in the Community Zone, talking to people in the hallways, and catching up with people that I haven’t seen for a couple of years. People like you.

Weird, right? Especially since this is a release year for SQL Server 2022, and there are probably gonna be a lot of good sessions from Microsoft. You know what? I don’t care. I don’t. I’ll watch the recordings and read the slide decks later. When I’m in Seattle, I’m gonna have the experience that I missed so much.

I wanna see y’all again, hear what you’ve been up to, take pictures with each other.

If you can’t come in person, it’s also a hybrid event: you can either attend in-person in Seattle, or online via live streaming. If you attend online, PASS is recording the live stream, and you’ll be able to re-watch it during the week of the conference. This is super helpful for folks who have an emergency at work, have to drop off the call, and want to be able to catch up on what they’ve missed.

Here are my sessions.

Pre-Conference Workshop: Mastering Parameter Sniffing – You’re a database developer or DBA with at least 5 years experience performance tuning queries and indexes. You already know you have parameter sniffing issues, and now you need to figure out how to fix it. In this one-day class, you’ll learn how to reduce the blast radius with index changes, query tuning, and database-level settings. You’ll also see firsthand how SQL Server 2017, 2019, and 2022 try to reduce it with adaptive joins, adaptive memory grants, automatic tuning, and caching multiple plans. Attendees will also get one year access to the full 3-day Mastering Parameter Sniffing recordings, too! That’s a $395 value, and it’s free with your workshop admission. (You’ll get the access in class.)

Everything You Know About Parallelism Is Wrong. Just because you see parallelism icons on execution plans doesn’t mean the query went parallel. SQL Server doesn’t load-balance work across CPU cores. CXPACKET isn’t a problem you fix by changing MAXDOP. Hell, even the term “MAXDOP” doesn’t mean what people think it means. It’s not that SQL Server’s parallelism is bad, it’s just not what you think it is.

Fragmentation Explained in 10 Minutes. Short, fast-paced lightning talks require difficult choices for presenters. If things go even the slightest bit off the rails, you are completely screwed. You have to viciously edit down your material to get the right points across, and no more than that. Then, you have to rehearse, rehearse, rehearse to get the timing right. The last lightning talk I did at PASS, I was wearing a Bob Dylan costume, a wig, and a harmonica. This year, no costumes – just aiming for ambitious delivery.

Register now. Let’s hang out. I miss you.

That just got weird, and I don’t even care.


Updated First Responder Kit and Consultant Toolkit for October 2022

First Responder Kit Updates
0

It’s fall – time to review your SQL Servers’ configurations, health, backups, and performance before fall turns into fail. To help, we’ve got a new version of the First Responder Kit.

How I Use the First Responder Kit
Wanna watch me use it? Take the class.

To get the new version:

Consultant Toolkit Changes

I updated it to this month’s First Responder Kit, but no changes to querymanifest.json or the spreadsheet. If you’ve customized those, no changes are necessary this month: just copy your spreadsheet and querymanifest.json into the new release’s folder.

sp_AllNightLog Changes

  • Fix: now works when system database collations don’t match. (#3132, thanks Bjorn Nordblom.)

sp_Blitz Changes

  • Enhancement: check for most recent log backup using DBCC DBINFO rather than msdb. This way, it works even if the log backups were taken on another AG replica. (#3143, thanks SQL Lambert.)
  • Enhancement: warn about additional dangerous 3rd party modules. (#3149 and #3150, thanks David Wiseman.)
  • Enhancement: works on Amazon RDS even if the server name has been changed. (#3146, thanks Bo Anderson.)

sp_BlitzFirst Changes

  • Fix: returns the Azure SQL DB compatibility that was broken in the last release. (#3139, thanks SJOrderDIRECT.)
  • Fix: even more compatibility for Azure SQL DB. (#3130, thanks DMonlineUK.)

sp_BlitzQueryStore Changes

sp_DatabaseRestore Changes

  • If you use sp_DatabaseRestore and you have servers in different time zones, we’d appreciate your help testing #3113. It’s not included in this release because no one has tested it yet. If you can test the StopAt parameter with different time zones and report back in that issue (not here in the comments) about how it worked, that’d be great.

Bonus changes: Anthony Green kept up the tireless work of keeping the SQL Server versions file up to date.

For Support

When you have questions about how the tools work, talk with the community in the #FirstResponderKit Slack channel. Be patient: it’s staffed by volunteers with day jobs. If it’s your first time in the community Slack, get started here.

When you find a bug or want something changed, read the contributing.md file.

When you have a question about what the scripts found, first make sure you read the “More Details” URL for any warning you find. We put a lot of work into documentation, and we wouldn’t want someone to yell at you to go read the fine manual. After that, when you’ve still got questions about how something works in SQL Server, post a question at DBA.StackExchange.com and the community (that includes me!) will help. Include exact errors and any applicable screenshots, your SQL Server version number (including the build #), and the version of the tool you’re working with.


Learn Columnstore Indexes for Free This Week.

Columnstore Indexes
5 Comments

Every weekday during the month of October, one of the modules from my Fundamentals classes will be absolutely free to watch. But you gotta watch it that day – you snooze, you lose.

For this week’s Fundamentals of Columnstore class, you don’t have hands-on labs, and you’re not meant to follow along with the demos. Columnstore is about bigger data, so I use the 2018-06 ~180GB copy of Stack Overflow (info page.) You definitely don’t need to grab that, but I’m mentioning it here in case you want to follow along with the demos.

Make sure to keep up – next week, we’ve got Fundamentals of TempDB to finish up the month.

Eagle-eyed readers will note that this isn’t all of the modules from each class, nor is it all of my Fundamentals classes. That’s because this whole thing is a diabolical mind trick, dear reader. I aim to get you hooked on the quality of my online training, and then come November 1st, when my annual Black Friday sale starts, you’ll be ready to get out your wallet – or your boss’s wallet – to get a Recorded Class Season Pass: Fundamentals, or Mastering, or the Level 2 Bundle when they go on sale.


Office Hours: One-Word Answers Edition

Some of the questions y’all post at https://pollgab.com/room/brento are pretty straightforward. Let’s get ‘er done.

LetTheDbaHandleIt: My friend needs to track who has accessed what data. This is easy at OS and app level, but how can my friend verify that those who have direct DB access are not snooping on data inappropriately? e.g. payroll or HR DB. Yes, trust them, but how to verify (efficiently)? SS Profiler?
Erik: Do you know how to see last execution of a SQL view in SQL server?

Auditing.

PaginationWoo!: Hi Brent. In all of your training and demos you’re very AR (lol) about always prefixing your tables with the schema name (.dbo) which, let’s face it, is the correct way to roll, but was there an experience you had that enforced this decision?

No.

Cats_Everywhere: Do you think Microsoft will stop supporting on-prem Windows Failover Clustering to push customers to the cloud in the next 5 years? WFC appears to no longer be covered in their training on learn.microsoft.com — that’s all just azure focused now.

“No.”

No.

SeekingUnderstanding: You frequently make it clear that you don’t care about external fragmenation. Do you care about internal fragmenation (page density)?

Yes.

Dopinder: What are your thoughts about new support for the MERGE statement in PostgreSQL 15? Better than Microsoft implementation?

Dunno.

Gershom: Does use of NOLOCK affect the query plan?

Rarely.

ZappyDBCC: Hi Brent, what would your advice be to dev teams to allow DBA to easily associate SQL requests to applications ? “Application Name” in cnx string ? comments in SQL requests ? other ? Thanks

Logins.

Peter Riis: How does a Nonclustered index behave on a Heap?

Watch.

Wes: Hello Brent, what do you think is the best way to have multiple sequences in the same table (one for each company id). I currently use a trigger with an UPDLOCK when selecting the highest previous value to avoid duplicates.

Dunno.

Efraim: Does having access to PostgreSQL source code make it easier to troubleshoot hard performance issues as compared with SQL Server?

Yes.

EngineHorror: Hi Brent! How often do you see PolyBase used in production? What are the top used data sources and their sizes?

Never.

Srinivas: Is it ever ok to consolidate two NC indexes with some overlapping include fields if it puts you over the 5 field max suggestion while reducing the number of NC indexes for a table?

Yes.

Pyjamarama: Hi Brent! How can I locate unused and missing indices using sp_BlitzIndex? Thaaaanx

Watch.

Gershom: Are there any RDBM’s that do a good job of automating NC index management (creation, monitoring, altering)?

Dunno.

Gershom: Do you have a recommended way of testing the selectivity of multi col Index A vs multi col Index B when consolidating similar NC indexes?

No.

Sister Hazel: Will you be releasing any new course content featuring SQL Server 2022 functionality?

Yes.

John-DK: Do you know how SQL server select which rows when I use sample in runstat?

No.

Rush: Hey Brent, I’ve got a set of tables that have a non-clustered PK (long story). I saw in your index tuning class that you don’t need to have the ID in the index normally. Is that also the case with a non-clustered PK? Thanks!

No.

CraigUK: I assume that paramaterised Dynamic SQL is prone to param sniffing? Any benefit to concatentaing the variable to build SQL that contains a hardcoded string literal and have a plan per value? Assuming that Forced Paramaterisation is not on. Or would that lead to too many plans?

Read.

Better than Ezra: Any new SQL 2022 books you look forward to reading?

Yes.

DBAbyDefault: Big fan, thanks for answering these questions Brent! My friend is wondering how much of a difference going from a default setting of 512 byte sectors on data/log/tempdb drives to the recommended 64k sectors? Is it work the effort to shuffle data around and redo everything?

No.

Ezrah: Should DBAs embrace the awesomeness of Ottertune or fear being made obsolete by it?

Yes.

Anatoli: Do you have any recommended books on the origins / history / evolution of relational databases?

No.

Efraim: SQL Sever 2022 not announced at Microsoft Ignite, should we be concerned?

Why?

I’m a potato: Any word of advice against indexing views?
Haydar: When addressing non-sargable queries, what are the pros / cons of materialized – indexed views?

Watch.

Yitzchak: Before accepting a new VM from sysadmin for a new SQL installation, what Network and Disk checks should SQL DBA’s perform?

Read.

Mikail_Tal: Brent! Have you or someone you know ever switched jobs to work with a particular technology?

Yes.

Blurred_Lines_on_Docs: On the official Microsoft documentation I found a query for Azure SQL Database that allows to pull data from sys.resource_stats and find AVG and MAX CPU, IO, Log Write, Sessions and Workers… but what are Sessions and Workers?

Really?

FrankieG: After 20+ years in the MSSQL space the more I feel like there is no clear answer to the majority of the problems I’m tasked to resolve. One could argue that this is due to the advanced features etc but frankly I feel that it’s just making it less attractive as a product.

Okay.


[Video] Office Hours Live: Ask Me Anything

Videos
4 Comments

Got a question for me? Post your questions at https://pollgab.com/room/brento and upvote the ones you’d like to see me discuss. Before heading to NYC for vacation, I recorded a live Office Hours on my Twitch channel.

Here’s what we covered:

  • 00:00 Start
  • 04:40 neil: are there any ‘band aids’ a DBA can apply for a third-party application that deadlocks all the time or is it up to the vendor of the application? maybe maxdop=1 or just tweak some indexes & general performance tuning and hope for the best? 06:58 Yehudah: What is the best way to track down the top queries that are experiencing ASYNC_NETWORK_IO waits? Did not see this as an option in sp_blitzcache source.
  • 07:21 Youssef: For your 5×5 NC index guideline, do you have a total byte limit you try to keep the include fields under?
  • 07:54 Remko van Hierden: Hi Brent, BI dev here. New server is slower than the old one. Supplier does not seem to be able to pinpoint it. I adviced management to hire DBA consultant. SP_Blitz says ‘Slow Storage Writes on Drive..’, could this be due to format with allocation blok size 4kb? Other reasons?
  • 08:45 Malachi: What are your recommended minimum network speeds for corresponding SQL Batch Requests Per Second rates of 1,000, 3,000, 20,000 batch requests per second?
  • 10:09 Yehudah: What do you estimate the percentages are for your students that pay for Ozar training via their company vs out of their own pocket?
  • 11:16 MyFriend: Hi Brent. Do you consider an Uptime of 1 whole business day, too small? In the context of making reliable DEATH method decisions on a production DB based on sp_BlitzIndex @BringThePain=1 results. What would you consider to be your optimal/minimum Uptime?
  • 13:19 DeferredNamesCauseProblems: Hi Brent! I am looking for a query to find all procedures that have deferred name resolution, ie the messages that appear when I issue sp_refreshsqlmodule (the messages come out informational). I want to capture those for resolution, but do not know how to do it all in TSQL.
  • 14:48 Leszek: Hi, Is there (since SQL server 2016) reliable, with good performance feature to do auditing – data changes (table name, column name, value before, value after change) ? Or better do it manually in code?
  • 17:27 Youssef: Hi Brent, I’ve been introduced to SQL at 18, I’m 22 now with a Senior Production/Development DBA fulltime position and I’ve somehow kickstarted a consulting career in my city, consulting for hospitals, banks, Insurance companies and NGOs. how can I move up higher & go global?
  • 19:12 Don’t blame Anthony: Back in your DBA days, how did you handle requests to delete old data and requests to delete old DB’s?
  • 19:39 YouGottaDoWhatYouGottaDo: Hi Brent, as a consultant have you ever found performance issues related to Change Data Capture (I think about Tlog growth or DB in Availability Group) where you had your hands tied? How did you manage those cases?
  • 20:29 Uncle Leo: Do you have any clients that do poor man’s log shipping where they do log backups but have their own code to do the copy/restores? When is poor man’s log shipping a better fit over true log shipping?
  • 22:14 Stefano: Hi, is there any performance or “less-blocking” benefit to query a SNAPSHOT of an AlwaysOn replicated database, instead of the replicated database? Are queries to snapshot databases generally less blocking, even though most of the data remains in the main database data files?
  • 23:21 StillLearning: Hello Brent, I must execute long running queries on Azure SQL DB (migration scripts, update jobs) with concurrent OLTP queries. As Azure SQL DB doesn’t have the Resource Governor feature, are there tips to write resource friendly SQL script to workaround that ? Thanks.
  • 24:31 Cassian: What is your opinion of memory optimized tempDB metadata in SQL 2019/22? Is it safe to enable?
  • 26:07 Yedidyah: Do you have a recommended way to easily migrate SQL Server 2019 from one Azure Windows VM to a newer more powerful Azure VM?
  • 26:39 Desi: Is it better to use SET NOCOUNT ON in stored procedures?
  • 26:59 Yedidyah: Is it easy or difficult to to learn PostgreSQL if you already know SQL Server?
  • 28:04 Brasso: What are your thoughts on using SQL Server to query Parquet, CSV, and JSON files in S3 or ADLS?
  • 30:23 JasonEverill: We have a SQL 2008 R2 instance and I’m trying everything within my power to get the organisation to move to 2019 (I’m a web developer). What are the best resources to allow me to do this? We currently don’t have a DBA (surprise surprise) – should this be our first task?

#tsql2sday: Start Your Dynamic SQL with a Comment.

T-SQL
6 Comments

When you write dynamic SQL, start like this:

Right after the SELECT (or INSERT or UPDATE or whatever), immediately put a comment – using /*, of course, because you’re not a terrible person.

That way, when you’re looking at the plan cache or monitoring tools, you can see what generated the dynamic SQL, and where you need to go if you need to performance tune or fix it.

You can’t put the comment at the very beginning because SQL Server tracks the exact point at which your query begins, and that’s what shows up in most plan cache or monitoring tools. If you put the comment immediately after the first word of the query, however, it’s easy to spot the query’s source.

This becomes even more important in SQL Server 2022 because of the PSPO implementation of cached plans.


This Week, Fundamentals of Query Tuning Classes are Free!

Execution Plans
5 Comments

Every weekday during the month of October, one of the modules from my Fundamentals classes will be absolutely free to watch. But you gotta watch it that day – you snooze, you lose.

This week is Fundamentals of Query Tuning. Last week’s class had hands-on labs you had to follow, but this week’s doesn’t. You’re welcome to follow along with the demos, though, and if you want to do that, you’ll need the same setup as last week: SQL Server 2017 or newer, with the most recent Cumulative Update, the most recent SQL Server Management Studio, and the 50GB Stack Overflow 2013 database (10GB 7z file, extracts with 7-zip.)

Make sure to keep up – next week, we’ve got Fundamentals of Columnstore coming fast & furious.

These are recordings of live classes. In the live class, the questions & chat take place over Slack. You don’t need to join the Slack – I only monitor that chat room during the live classes. (I’m on vacation in New York at the moment, heh.)

Eagle-eyed readers will note that this isn’t all of the modules from each class, nor is it all of my Fundamentals classes. That’s because this whole thing is a diabolical mind trick, dear reader. I aim to get you hooked on the quality of my online training, and then come November 1st, when my annual Black Friday sale starts, you’ll be ready to get out your wallet – or your boss’s wallet – to get a Recorded Class Season Pass: Fundamentals, or Mastering, or the Level 2 Bundle when they go on sale.


[Video] Office Hours Silent Edition

Videos
7 Comments

Okay, I, uh, forgot to unmute the microphone for this one:

So here are the answers in text form instead. <sigh> Thank goodness it was a speed round!

Mike: When Brent Ozar’s certification exams for SQL Server will be available? Looking forward to having exams like “Fundamentals of QT”, “Mastering Server Tuning” etc, so you can pass in the testing center. 1st cert. exams on performance tuning for SQL Server in the world. When?

Never. I don’t wanna write exams.

RoastMe: Hi Brent. You have earned the reputation for roasting people for asking certain questions with talent and entertainment. Do you think some will ask a question to get a roast? Do you think people watch just for the roasting?

I think some people do, but I think the purposely trolling questions don’t get that many upvotes.

MyFriendConsulting: Hi Brent, In consulting, do you recommend doing all the business/clients and technical work myself at the beginning (say first 1-2 years) or do you recommend hiring someone (maybe part-time) to meet clients and handle the business part?

Don’t hire people until you already have more incoming business than you can handle.

Mike: What do you think will be the consequence of events, if Microsoft releases SQL Server 2022 with PSPO implementation as it is in its current form ?

People who need monitoring won’t use 2022 compat level.

Index_It_All: Hello Brent, We are looking to determine how to classify all our SQL Servers into small, medium,Large and Very Large. We want a default template so we can onboard clients databases. What metric would you use to measure what should be a small, large or very large client Database?

Read this.

Will Marshall: How do you decide when a given a single stored proc should be refactored into multiple child stored procs?

We cover that in my Mastering Parameter Sniffing class.

Yourbiggestfan: Hi Brent, I know you have spoken about SQL22 changes, but the ‘Percentile and persist mode mem grant fdbck’ improvment scares me as MS have smartly overcome issues with Mem grant fdbck (where it only relied upon last exec). I fear avg DBA would no longer be needed in 10 yrs time.

If you’re content with being average at something, then yes, you’ll find that you’re probably not going to be needed no matter what your job title is.

Mehmet: What are your thoughts on the use of surrogate keys vs natural keys in new SQL tables?

I don’t think about that. Get this book.

Espen Eriksmoen Løke: Hi, I have been working with SQL Server query tuning for many years and think I am quite skilled. I would like to go to classroom training for and advanced course both to sum up and learn new things. Tired of online courses and Teams 🙂 Something to recommend?

Read this.

Ralph: I love your simple explanations, e.g. recently “what’s fragmentation” at SQLBits! Do you have anything like that for how LOB data is handled and how it affects performance if we use e.g. nvarchar(max) extensively?

Yes, watch my free How to Think Like the Engine course.

Don’t blame Anthony: How did you handle reviews for new SQL code back in the day?

I didn’t. Companies are rarely staffed well enough that people can review every new line of code. Instead, focus on the top resource-consuming queries.

Gang of DBAs: Is there a resource like the Gang of Four Design Patterns book for Data Modeling? The data model is such an important piece of my development, but I always struggle and feel like there must be people who’ve solved these issues before.

I don’t even know what that is.


Who’s Hiring in the Microsoft Data Platform Community? October 2022 Edition

Who's Hiring
19 Comments

Is your company hiring for a database position as of October 2022? Do you wanna work with the kinds of people who read this blog? Let’s set up some rapid networking here. If your company is hiring, leave a comment.

The rules:

  • Your comment must include the job title, and either a link to the full job description, or the text of it. It doesn’t have to be a SQL Server DBA job, but it does have to be related to databases. (We get a pretty broad readership here – it can be any database.)
  • An email address to send resumes, or a link to the application process – if I were you, I’d put an email address because you may want to know that applicants are readers here, because they might be more qualified than the applicants you regularly get.
  • Please state the location and include REMOTE and/or VISA when that sort of candidate is welcome. When remote work is not an option, include ONSITE.
  • Please only post if you personally are part of the hiring company—no recruiting firms or job boards. Only one post per company. If it isn’t a household name, please explain what your company does.
  • Commenters: please don’t reply to job posts to complain about something. It’s off topic here.
  • Readers: please only email if you are personally interested in the job.

If your comment isn’t relevant or smells fishy, I’ll delete it. If you have questions about why your comment got deleted, or how to maximize the effectiveness of your comment, contact me.

Each month, I publish a new post in the Who’s Hiring category here so y’all can get the latest opportunities.


Erik Darling’s Month of Free Tools Training

Over the past month (plus or minus a couple days), Erik Darling churned out dozens of posts to show how he uses different SQL Server Community Tools that are free and open source to troubleshoot SQL Server issues. You should read all of them. I did. (I also shamelessly copy/pasted this intro, plus the below, directly from his blog.)

Here’s the full list of posts:

I don’t know anybody who works harder at giving you free SQL Server training than Erik does. (That part I didn’t copy/paste from his blog.)


October is Free Fundamentals Month – And The Training Starts Now.

Indexing
18 Comments

Every weekday during the month of October, one of the modules from my Fundamentals classes will be absolutely free to watch. But you gotta watch it that day – you snooze, you lose.

This week is Fundamentals of Index Tuning. To follow along with the labs this week & next week, you’ll need SQL Server 2017 or newer, with the most recent Cumulative Update, the most recent SQL Server Management Studio, and the 50GB Stack Overflow 2013 database (10GB 7z file, extracts with 7-zip.) You don’t have to follow along with the labs, but I highly encourage it.

Make sure to keep up – next week, we’ve got Fundamentals of Query Tuning coming fast & furious.

These are recordings of live classes. In the live class, the questions & chat take place over Slack. You don’t need to join the Slack – I only monitor that chat room during the live classes. (I’m on vacation in New York at the moment, heh.)

Eagle-eyed readers will note that this isn’t all of the modules from each class, nor is it all of my Fundamentals classes. That’s because this whole thing is a diabolical mind trick, dear reader. I aim to get you hooked on the quality of my online training, and then come November 1st, when my annual Black Friday sale starts, you’ll be ready to get out your wallet – or your boss’s wallet – to get a Recorded Class Season Pass: Fundamentals, or Mastering, or the Level 2 Bundle when they go on sale.


[Video] Office Hours: Ask Me Anything at the Mediterranean Sea

Videos
0

On the last day of my Israel trip, I went through the highly upvoted questions from https://pollgab.com/room/brento and answered ’em, standing in front of the beach.

Here’s what we covered:

  • 00:00 Start
  • 00:37 AllThePartyPeople: On our server, MAXDOP=1 (not my choice); we had a poor performing SP call (called as dynamic SQL; again not my choice); Ran in SSMS; ran fine. Cleared plans & tried; Failed web; SSMS worked. Set MAXDOP=4, and both work fine. What are we missing? Why did it always work in SSMS
  • 02:09 FrankieG: Hi Brent, How do I sell the sp_Blitz scripts and, for that matter other advice you and other similar experts, have imparted that I have come to rely on, to the “owners” of the MSSQL client databases at a company where I’m the new guy?
  • 03:05 APB: Hi Brent, Just curious about your thoughts on creating a view in a data warehouse with an index (schemabinding + unique clustered index) versus creating a similar table and truncating and reloading after a nightly data refresh. Which is most efficient?
  • 05:01 Medazzaland : What criteria do you use to decide if a given long running transaction is a concern or not? 06:14 Medazzaland: What are the best training resources for learning SQL Availability Groups?
  • 06:54 PB&J: Hi brant, I’m a big fan of transactions and error handling in stored procedures. Developers say they implement try/catch and transactions in the application code so they don’t want to add it on the SP as well. Is it indeed duplicate or handling errors in SQL has its benefits? Tnx
  • 08:00 Ramil: Hi Brent! App controls a lot of things like amount of database files – only one, indexes can be created only via app, partitioning is not allowed. How can I scale up horizontally in this case? because DB is growing 300gb per month. OLTP DB, currently 1.8 TB, in AlwaysOn AG.
  • 10:05 bamdba: Hi Brent, I’ve inherited a SQL estate where I have multiple SQL HADR (2012 to 2017) on a single OS and with data files on mount points. Any suggestions on how can I consolidate these servers without migrating to new ones?
  • 11:43 Mehmet: Do untrusted foreign keys adversely affect query plans?
  • 12:03 Mehmet: Have you ever experienced an ailing SQL Server that sent out so many failure simultaneous notifications that it took down the mail server?
  • 12:49 Timbalero: Hi Brent, apart from inaccurate stats, UDFs and table variables, what other reasons can make the CE produce estimates of exactly 1 row? Can multiple joins have something to do with it?
  • 14:56 Ingibjorg: Do you have any recommended guidance for creating / optimizing new VM configuration for SQL Server 2019 Standard in an Azure VM? Is it any different than bare metal new server configuration?

Vegas Home Office Tour

Home Office
17 Comments

I’ve been teaching online from home for years, and you’d probably think my office would keep growing and growing – but actually, my setup has gotten a lot smaller since the last time I blogged about it. I don’t really need space in order to work, and I kinda wanna incentivize myself to get out of the office when my work is done.

I designed my Vegas home office around the side camera view that the audience sees while we’re doing live Q&A and chatting in Slack (the window at the top right of the stream):

I wanted a lively view with a bunch of personal stuff in the background (although blurred a little with good bokeh.) Here’s how it looks behind the scenes – the entire wall to the left is painted chroma key green so I can do greenscreen work:

And here’s the camera I’m staring at when the side view is on:

When I turn back to the computer to continue presenting, here’s what the setup looks like:

Desk: Vari Standing Desk – I went for the smallest stable standing desk I could find. It’s got just enough room for my monitor, laptop, keyboard, trackpad, and Stream Deck, but no more than that. It’s quite the departure from my giant NextDesk Terra Pro, which is down in the garage now.

Chair: Vari Active Seat – I’ve used an Aeron on wheels for years, but I wanted something that was more of a bar stool height. I was really curious about the Active Seat because it doesn’t have wheels, and instead lets you naturally move around in a small area. I thought for sure I’d fall over – but it’s been great! I love it, and I can sit on it for hours.

Laptop: MacBook Pro 16 – I’m on the 2021 model with the M1 Max processor and 64GB RAM. The Apple Silicon processor is everything you’ve read about in reviews: crazy fast and completely silent, even when I’m streaming and recording videos. The ARM processor can’t run SQL Server in Windows VMs, so I use the cloud for that instead.

Monitor: Gigabyte M34WQ 34″ (RTings) – Around $500 for 3440×1440 resolution and a 144Hz refresh rate. I like the way Apple’s Pro Display XDR looks, but I’m not about to spend 10X more in order to see colors more vividly when I’m partially colorblind anyway.

Control panels: Elgato Stream Deck XL – A vital, vital part of my streaming workflow with keys to trigger all kinds of stuff that I use while streaming. I use two of these, one on the right side of my desk and one on the left, because regardless of what I’m doing and where I’m standing, I wanna be able to trigger events.

Elgato Stream Deck

Slack chat display: Apple iPad – In my classes, the audience can ask questions and chat with each other via Slack. I need to be able to see that chat at all times so I can respond immediately to questions or feedback. When I’m doing PowerPoint presentations full screen, I need one clean monitor with the PowerPoint display that the audience will see, and the other display is PowerPoint presenter view. I could have added another monitor to my desktop, but I just didn’t wanna take up much space, and an iPad is perfect for this.

Green screen camera: Sony ZV1 – This is actually a big step down from my previous streaming setups. When I’m doing green screen work, my image is a small part of the entire screen, so I don’t need a really good camera here. I just need something better than the typical USB webcam, because those don’t pick up enough color details for green screen work. The ZV1’s small sensor is good enough. I use the HDMI output, and plug that into an Elgato Cam Link 4K. I have a Rode VideoMic Go on the top of this camera as an emergency microphone in case my wireless headset goes out during a class. The mic is always on, so if my regular mic dies, I can just unmute the ZV1’s audio in OBS, and we can keep right on going.

Side camera: Sony ZV-E10 with Sigma 16mm lens: While I don’t need a high quality green screen camera, the side view camera has to be lusciously detailed. When I switch to the side camera, I’m having a discussion with the audience, and I take up the whole screen. I want the background to be defocused. This camera’s HDMI output also gets plugged into an Elgato Cam Link 4K. If you need to plug multiple Cam Links into a laptop, I don’t recommend routing them through a dock – instead, get a simple USB 3.1 hub. Otherwise, when I run too much through a dock, the Cam Links end up dropping offline.

Microphone: DPA headset microphone plugged into a Sennheiser AVX transmitter, into a Focusrite Scarlett – This setup is total overkill, but I really like the flexibility of being able to move around a lot while I do green screen work, and not have to worry about tripping over cables.

Lighting: a hodgepodge. A pair of Neewer 12.9″ lights for the desk, and a couple of older Neewer lights to light the green screen. I really wanted to use Elgato Key Lights so that I could automatically turn them off & on when I changed camera scenes and put the stream on break. However the Key Light’s WiFi connections were wildly unreliable for me. The Neewer lights are actually mounted to Elgato Key Light stands because those are nice hardware, but the Key Lights themselves are sitting in the closet, unused.

Streaming software: OBS. I’ve written about how I use OBS for streaming and training classes, and how to make online streams fun and interactive with OBS scenes. For video delivery, I use Mux for private classes, Twitch for public streams, and YouTube for public stream replays.

If you’ve got questions about my office setup, feel free to ask away in the comments!


Free Live Webcast: Why is One Query Sometimes Slow and Sometimes Fast?

SQL Server
2 Comments

Sometimes the exact same query goes slow out of nowhere. Your current fix is to update statistics, rebuild indexes, or restart the SQL Server. It works, but you don’t know why.

The single most common reason is parameter sniffing. SQL Server “sniffs” the first set of parameters for a query, builds an execution plan for it, and then reuses that same plan no matter what parameters get called. It’s been the bane of our performance tuning for decades.

In this one-hour session on Thursday, October 20th, I will explain:

  • How it happens
  • How SQL Server 2022 is trying to fix it
  • How you can work around emergencies in the meantime

Thanks to the session’s sponsor, Pure Storage, the first 200 folks to register and attend the entire webinar will get a $10 gift card for lunch. Get your lunch and learn on for free.