Press "Enter" to skip to content

Curated SQL Posts

Validating GPS Coordinates in SQL Server

Muhammed Imran prevents errors:

TL;DR: To validate GPS coordinates in SQL Server, stage the raw latitude and longitude as text, check each value’s format and range, log failures with a rejection reason, and only then pass the accepted pairs to geography::Point().

This stops malformed values, such as the word “north”, a blank longitude or a latitude of 95, from breaking your load, and it lets you run distance queries on clean spatial data.

This article follows 12 fictional service locations from raw input to a “within 10 km” search. It also shows the one thing numeric validation can’t catch: a swapped latitude and longitude that passes every check.

Click through for the demo.

Leave a Comment

Using S3 Object Locks for Write-Once Read-Many Storage

James Gallagher takes advantage of immutable storage:

Write Once, Read Many. WORM storage used to mean a physical appliance, usually expensive, usually managed by a vendor, often a pain to integrate with anything. S3 Object Lock gives you the same guarantee natively on objects stored in S3, backed by the same durability story as the rest of S3, and configurable down to individual object retention periods.

It’s one of the more useful compliance features AWS has shipped, and despite it being announced at AWS re:Invent 2018, it is still very much underutilized. Maybe that’s because people don’t quite understand the two modes and when to use each.

Click through for an explanation of how it works, where you can get yourself in trouble, and the benefits you can gain from this. Microsoft is making a push for immutable backups in Azure, and they have similar types of object locks, making this a solid plan for ransomware-proofing your backup strategy, even if your systems are on-premises. Just make sure to do the math on how much it’ll cost you, as any mistakes you make are permanent until the files roll off.

Leave a Comment

The Death of the DBA, Again

Daniel Calbimonte adheres to Betteridge’s Law of Headlines:

So, what is the impact to DBAs?

Here are several questions about how AI could impact the DBA profession:

  • Is the DBA career dead?
  • Is it safe to study a DBA career?
  • Is the cloud affecting the DBA jobs?
  • What can AI do for the DBAs?
  • What is AI unable to do yet?
  • What does the US bureau of labor statistics say about the DBAs and Database architects?

The way I describe things is, what DBAs do today is not a perfect match for what DBAs did 10, 20, or 30 years ago. The specific mechanisms change, the expectations around the role change, and even the tooling and database platforms change. But what doesn’t change is the need for availability, resiliency, disaster recovery, and responsiveness. All of these things are what good database administrators support, whether that’s in SQL Server, Postgres, Databricks, Snowflake, Firebase, or wherever else. What you can control will depend on the underlying platforms, but the big picture is that there are a lot of companies with a lot of data and, as long as access to data retains some amount of business value, there will be room for people to manage where the data gets stored.

“Is the role of DBA dead?” is a different question from “Will I have a job as a DBA?” That answer has a bit more nuance because the opportunity cost of maintaining you (or someone you know) as a DBA.

Leave a Comment

Availability Groups with a Local Service Account

Dualcore DBA doesn’t need your Active Directory trees:

This post is a follow-on from my previous post where we set up a SQL Server Availability Group on a Windows domain. In this post, we’ll run through the process again but this time, our instances will be running under local service accounts and so the process is slightly different. As in the previous post, both instances I will work on are SQL Server 2022 Developer Edition and so benefit from Enterprise Edition features.

Read on to see how the process differs from a scenario with Active Directory.

Leave a Comment

The Importance of Blocking in Databases

Louis Davidson explains why we suffer:

Nope, this is not a clickbait title (ok, well sort of). Blocking is good….otherwise SQL Server (and all the other database platforms would eliminate it for good. And before you say something about a pure MVCC implementation like SQL Server implemented with in-memory OLTP… there is no blocking, but in place of blocking you can do a lot of work, perhaps hours, and when you go to commit, it fails… blocking is better than that in any case where you are doing large transactions.

Read on for the nuance. I fully agree with Louis on this, with the caveat that SQL Server, by default, does too much blocking due to its Read Committed isolation level. A default of Read Committed Snapshot Isolation would have been a good switch about 15 years ago.

Leave a Comment

An Initial Review of Fabric Apps

Teo Lachev takes a look:

Before diving in, let’s clarify the terminology. Power BI and Fabric have abused the word “app” to cover several very different things:

  • Power BI template app – A packaged solution that a software vendor can distribute through Microsoft AppSource. Customers install it, connect their own data, and use the included semantic models and reports.
  • Power BI workspace app – A way to package and distribute selected workspace content within an organization. For example, Finance can publish reports to users who are not members of its workspace.
  • Power BI organizational app – An evolution of the workspace-app experience that supports creating and distributing multiple apps from content in a workspace.
  • (NEW) Fabric App – A custom-coded web application, typically built with JavaScript/TypeScript and a web framework such as React, that is deployed to Fabric and can use managed APIs, authentication, and data services. “Custom-code app” would be a more revealing name. Unlike a Power BI report, it is an application artifact with its own user experience—even if the result looks suspiciously report-like.

Read on to see what Teo likes about them, the trade-offs you’ll have to make when using them, and some of the limitations in the feature today.

Leave a Comment

Methods to Enable Query Store

Lee Markum has a few:

Query store is a valuable tool for people managing SQL Server, whether that’s on-prem, in an IaaS scenario or AWS RDS, Azure Managed Instance or Azure SQL DB. There are several possible ways to enable the Query Store.

This post will explore some of those methods. If you’re not familiar with Query Store, then go read this post. If you need help getting started with PowerShell, then start here, and that will help the later examples make a bit more sense.

Click through for examples using T-SQL and dbatools.

Leave a Comment

CLR and Memory Usage

Andy Levy troubleshoots an issue:

A large Availability Group (100+ databases) started to report all replicas in an Unhealthy state. It was a Tuesday afternoon with no planned activity aside from Normal Business Processes™️, so a few alarms went off. After about a half hour, it looked like things were back in sync, everything healthy…and then it happened again. And a couple more times. The situation went on for about 2 1/2 hours. Ultimately it settled out with all the database replicas getting back into a healthy and synchronized state on their own, everything intact.

This is a good reminder that there are more things in heaven and earth, Horatio, than are dreamt of in your buffer pool.

Leave a Comment

Immutable Backups in Azure SQL DB and MI

Dinkar Nethi talks about a backup option in Azure:

Ransomware attacks are becoming increasingly sophisticated. Attackers no longer focus only on encrypting or stealing production data. They also target backups, knowing that eliminating an organization’s recovery options can turn a security incident into a prolonged business disruption.

Imagine discovering that your database has been compromised, only to find that the backups you were counting on have also been deleted. Even with a comprehensive backup strategy, recovery becomes significantly more challenging when attackers can tamper with the very data needed to restore business operations.

That’s why backup immutability matters.

I imagine that the only thing allowed to modify or delete these backup files is the automated cleanup process that runs on a schedule and ages out old backups. But it’d be interesting (in a cruel way) to think about how to satisfy GDPR deletion requests if your backups are immutable. In practice, I suppose the answer to that is probably something like “restore the backup and then run a script to clear out customers who requested data deletion.”

Leave a Comment

Combining Semantic Views in Microsoft Fabric

Chris Webb mixes a pair of views:

One of the most interesting things about Fabric semantic views (announced this week at Ignite) is the way you can combine multiple semantic views together, allowing you to reuse semantic modelling and metrics easily. This has been a long-standing ask for Power BI semantic models and while composite models were created to solve this problem, and had their uses, they never solved the problem properly – mostly because by building composite models on top of a single, physical semantic model that semantic model became a bottleneck. The documentation for semantic views talks about reuse and combining but I thought it would be good to show a simple example to help you understand what’s possible.

Click through to see how.

Leave a Comment