Press "Enter" to skip to content

Curated SQL Posts

Charting Average Full Database Backup Durations with R

Thomas Williams has a script:

DBAs spend time dealing with SQL Server performance, capacity, monitoring, troubleshooting, provisioning, etcetera; I’ve previously mentioned that R is a powerful, open-source language with a great ecosystem of libraries for analysis and visualisation, so it’s no surprise that I think mixing SQL Server and R Markdown for reporting goes together like a Vegemite and cheese sandwich…lunch perfection!

Here’s a couple of real-world examples of how I’ve used R Markdown connected to SQL Server (for a recap of how to do this from a technical perspective, see my earlier blog post “Connecting to a SQL Server database from R Markdown”):

This is a neat approach to visualizing database backup times as a process control chart.

Leave a Comment

Introducing sp_CheckHealth

Jeff Iannucci announces a new stored procedure:

This tool will give you a fast, comprehensive picture of a SQL Server instance. It gathers the kind of information you would otherwise collect by clicking through a dozen dialogs and running a handful of scripts, and it flags potential issues so you can decide what to deal with first. The findings are organized into categories like Recoverability, Security, Availability, Integrity, Reliability, and Performance, and each one comes with details and an action step so you aren’t left guessing about what to do next.

Click through for the script and how you can use it.

Leave a Comment

Surrogate Keys in Fabric Data Warehouse

Louis Davidson does some more digging:

Creating the simplest of tables, the first thing I start thinking about is making sure that the data is going to be protected from the user. Users (including myself on my own projects when I have my user hat on) don’t notice when they start inserting poor quality data sometimes. Oops, I hit F5 twice, I wonder if that will affect my data? Without proper constraints, it probably will.

In this second entry, I want to cover a few things about handling surrogate values that will help you avoid some of the (in retrospect) kind of dumb expectations that I had. Fabric Data Warehouse T-SQL feels so much like SQL Server Relational T-SQL that some stuff like choosing a surrogate key makes me think I am missing something.

One of the things Louis mentions is how the values get inserted and how it looks like they’re in different ranges. This makes sense, as each distributed node likely has its own range of identity values, similar to the way merge replication would work with identity keys to prevent overlap.

Leave a Comment

Row vs Page Compression in Animated Form

Brent Ozar has a new animation:

What’s the difference between SQL Server’s row compression and page compression, and when does each one make sense?

  • Row compression turns every fixed-length datatype into a variable-length datatype, using as little space as possible to store it
  • Page compression does that, AND adds a dictionary of repeated data on the page, getting more compression at the cost of more CPU

Here’s my dirty little secret: I don’t think row-level compression makes sense all that often, simply because I’m not sure I’ve ever seen negative consequences to page level compression, even in a variety of scenarios in very busy environments. I’m sure that there are specific cases, but I just default to page level compression because of how well it works.

Leave a Comment

What’s New with the VSCode MSSQL Extension

Yo-Lei Chen shares some updates:

Writing and maintaining SQL is easier when you can eliminate repetitive steps and keep your scripts cleanly formatted. With the MSSQL extension for VS Code v1.45, we’re introducing the Public Preview of the SQL Formatter alongside the General Availability of Azure SQL Database Provisioning and Shortcuts Configuration. You can now apply consistent T-SQL formatting across your projects, create free tier cloud databases with automated post-deployment actions, and streamline frequently used commands and queries directly inside Visual Studio Code.

The SQL Formatter is potentially interesting, inasmuch as you’re able to control the settings yourself rather than relying on a pre-defined format.

Leave a Comment

Database Application Security and High Availability Checklist

Andreas Wolter has an update:

I have updated the SQL Server Database Application Security & High Availability Checklist and moved the current version to the Sarpedon Quality Lab website: View here

The checklist is written for two audiences:

Database application vendors who want their SQL Server-backed products to be easier to approve in enterprise environments.

DBAs, security administrators, and architects who need to evaluate whether a vendor application can be deployed securely.

Click through to see what’s new, and check out the link for the full checklist.

Leave a Comment

Large Language Models for Data Professionals

Eugene Meidinger has a primer:

It’s tempting to think that working with LLMs and AI agents doesn’t require understanding anything about how they work. These tools are often presented as autonomous, intelligent, and self-explanatory. They communicate through conversational text, making them feel natural and intuitive, and can often even seem like magic.

In practice, however, these intuitions about LLMs are often very wrong. LLMs are a strange technology. As we stack tools and agent interfaces (or harnesses) on top of them, more and more misunderstandings also stack up. Treating them as an easy button leads to layers of frustration, waste, and, in the worst-case scenario, mistakes.

This is a nice baseline to get someone started with understanding LLM output behavior. It’s not a how-to guide, but rather a “Here’s what’s going on” type of guide. Eugene brings less snark to the topic than I do, but that’s par for the course for anyone who remembers the good ol’ days of the SQL Data Partners podcast.

Leave a Comment

Postgres vs Kubernetes container_memory_working_set_bytes

Jeremy Schneider provides an alternative:

Kubernetes metric container_memory_working_set_bytes is used for evicting/killing pods with too much memory use, especially if memory request < limit (don’t do this with Postgres). The metric is calculated from cgroups v2 memory.stat as current-inactive_file [source].

You’d assume it’s a good metric for memory usage in kubernetes. But with Postgres, this metric is very inaccurate for memory utilization and doesn’t tell you at all if you’re going to OOM crash your database.

Click through to understand what goes wrong, why it does, and what you can use instead.

Leave a Comment

sp_executesql and Building Execution Plans

Dualcore DBA needs a plan:

Whilst I would say the actual execution plan is the most useful, estimated execution plans have their place – sometimes you just need to see estimates or a quick verification that a change you have made has had some effect on plan shape. I find them helpful to quickly see if a change made to the code, an index, database setting or similar has had an effect on the execution plan without having to wait for the query to finish (especially if I am performance tuning a query that has a long run time).

sp_executesql is also useful – it helps us to execute dynamically created queries and supports parameterisation. It is also used by the .NET SqlCommand class to issue queries to the database engine in a parameterised form, assisting with SQL injection prevention along the way.

I recently found myself troubleshooting some code coming from an application. It was a Slow in the app, fast in SSMS problem so I was using sp_executesql to replicate the application behaviour. I also wanted to get the estimated execution plan. Here is an example query and what I was greeted with when I asked for the estimated plan:

Read on for one challenge you might find when trying to tune operations that you’ve built using sp_executesql, as well as what you can do about it.

Leave a Comment

For the Love of Markdown

Louis Davidson explains an opinion:

I had no idea what the three tick marks “` meant until soon after I left there because all my recent experience had been with use the Mammoth Word Document converter. It works pretty nice overall, but it had been something I had struggled with over the years trying to get other people’s documents into to work just right. (Ok, and my documents too.)

It worked by mapping styles in a Word Document to a style in a WordPress page. To do it well, I had my template with all the styles set up in the Word template with shortcut keys, which I used an Elgato Stream Deck to remember all the keys. I still use a stream deck for editing, which I will share about some day.

So when I started my own site, I tried hard to replicate that experience but better. Until recently, you couldn’t support plugins in WordPress without spending quite a bit more money than I was willing to spend on this site so I started trying to find the best way to work offline and then (more or less) paste in my text.

Click through for a bit of Louis’s journey. Also, Louis mentions being confused by the name and thinking it was “markup.” That’s because HTML is the Hypertext Markup Language, and John Gruber meant the name as a pun on heavier markup languages like HTML and XML, as Markdown involves much less marking up of the text.

Leave a Comment