• Skip to main content
  • Skip to primary sidebar

DallasDBAs.com

SQL Server Database Consulting

  • Services
  • Pocket DBA®
  • Blog
  • Testimonials
  • Contact
  • About

syndicated

SQL Server Index Primer

April 23, 2025 by Kevin3NF Leave a Comment

Indexes 101: What, Why, and When?

“What Is an Index?”
I get this question a lot, especially from developers and sysadmins who’ve been handed a SQL Server and told, “Keep it running fast.” No pressure.

At a basic level, an index is a roadmap. Instead of scanning every house on the street to find the one you want, you check a list. Indexes help SQL Server find data faster – less scanning, more targeted seeking. All those pages at the back of a technical book? Those are indexes. The same idea applies to tables.

Now, not all indexes are created equal. Some are used every day. Others are…let’s say, special occasion. Let’s walk through them in order from most to least common (based on my experience).

Clustered Indexes

What it is: Defines how the data is stored on disk. SQL Server physically orders the table based on this. One per table.
Why it matters: Every seek operation relies on this index. If you don’t create one, SQL Server makes a hidden “heap”, which adds time to the query.
When to use: Pretty much always, unless you’re loading massive amounts of data fast and don’t care about retrieval speed such as an ETL/ELT process.
Pro tip: Pick a column (or set) that is narrow, static, and unique (like an identity column). Even better, use a column that is frequently used to retrieve sets of data such as date for “Last month’s sales” types of reports.

Non-Clustered Indexes

What it is: Think of these like side tables (they do add to the database size) with pointers back to the main data. You can have many per table, but too many can be an issue.
Why it matters: Great for covering queries. Especially helpful if they include only a few columns.
When to use: When the same query pattern happens often and doesn’t match the clustered key.
Watch out for: Too many non-clustered indexes = slow inserts and updates. Balance is key.

…Included Columns…

What it is: Bonus data tacked onto a non-clustered index. Doesn’t affect sort order but helps avoid expensive trips to the table to find more data.
Why it matters: Lets you “cover” more queries without bloating the main index definition.
When to use: If the query needs extra columns but they don’t need to be sorted.

Filtered Indexes

What it is: Indexes with WHERE clauses.
Why it matters: Small, fast, and efficient for predictable filters.
When to use: Perfect for things like IsActive = 1 or Status = ‘Pending’.

Columnstore Indexes

What it is: Think column-based storage, not row-based. Optimized for analytics.
Why it matters: Game-changing for reporting queries across millions of rows.
When to use: Data warehouses, not your OLTP system.
Bonus: Clustered columnstore = high compression. Great for archiving.

XML Indexes

What it is: Indexes specifically for querying XML data types.
Why it matters: Without them, XML queries crawl.
When to use: If you’re unlucky enough to be storing structured data as XML blobs.

Spatial Indexes

What it is: Indexes that help with geography and geometry data types.
Why it matters: SQL Server can’t efficiently process spatial queries without these.
When to use: Mapping, geolocation apps, routing engines—very niche but powerful. I’ve only seen a spatial index in production once in my career.

The Bottom Line:

Indexing is both art and science. You want just enough to make reads fly and not too many that writes crawl. Think of it like your car with just the right tire pressure—too little and you drag, too much and you lose control.

— Thanks for reading!

Kevin

 

Filed Under: Beginner, Indexing Strategies, SQL Tagged With: syndicated

SQL Server Wait Stats

April 16, 2025 by Kevin3NF Leave a Comment

Everything in SQL Server is waiting for something…this is by design. And most people never think about it…

Until your application is waiting to complete its request, sell the product or provide “the report” to the CEO!

Most SQL Server performance issues come down to one thing: waiting. Every time a query slows down, SQL Server records what it was waiting on. These wait stats are one of the best diagnostic tools for DBAs, sysadmins, and developers – but only if you know how to use them.

What Are Wait Stats?

SQL Server tracks the time spent waiting on resources like CPU, memory, disk, or locks. Think of them as traffic reports – some delays are normal, while others indicate serious bottlenecks. If your database is slow, wait stats tell you where to start looking.

How to Read Wait Stats

A simple query can reveal where your server is spending the most time:

SELECT wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms 
FROM sys.dm_os_wait_stats 
ORDER BY wait_time_ms DESC;

Key columns:

  • wait_type – The specific type of wait that might be affecting performance
  • waiting_tasks_count – Number of times this wait has occurred
  • wait_time_ms – Total time spent waiting (cumulative since last clear)

 

Common Wait Types and What They Mean:

A table of various SQL Server Wait types and possible fixes

 

Many other waits exist, but these are some of the most common. Microsoft provides a full reference here.

SQL Skills has the best list of wait types and things to know I’ve ever seen. Go there and read before changing anything. MANY recorded waits are benign and not worth looking into.

Finding and Fixing Performance Issues: A guide for you to try in your development environment

  1. Run the wait stats query to capture the current state.
  2. Identify the top wait type and correlate it with system metrics. Research it
  3. Apply a tuning change (indexing, parallelism adjustments, memory tuning).
  4. Re-run the query to compare results.

This process provides a clear before-and-after snapshot of how performance improves.

The Bottom Line

Wait stats don’t tell you exactly what’s broken, but they show where to investigate. The key is to correlate them with query execution plans, server configuration, and system resource usage. Tracking these waits over time can also help spot performance trends before they become critical issues.

SQL Server is always waiting for something. The question is – what are you going to do about it? What are you waiting for?!

Thanks for reading!

–Kevin

Get the first month of Pocket DBA® FREE from Dallas DBAs!

 

Filed Under: Performance Tuning, SQL Tagged With: performance, SQL, syndicated

Why Your SQL Server Backups Aren’t Enough

April 9, 2025 by Kevin3NF Leave a Comment

SQL Server backups are database insurance – you don’t really appreciate them until disaster strikes. But here’s the kicker: having backups doesn’t mean your data is safe. If you’re not regularly doing test restores, your backup strategy is a ticking time bomb.

 

The False Sense of Security

Many IT leaders and system admins think, “We have full backups every night. We’re covered.” But when the time comes to restore, they discover:

· The backup file is corrupt.
· The storage location is inaccessible.
· The restore process takes way longer than expected.
· The recovery model wasn’t configured properly.
· The point-in-time restore doesn’t actually bring back the data they need.

At that point, it’s not a “backup strategy.” It’s a data loss incident.

Why Restores Must Be Tested

SQL Server backups are only as good as your ability to restore them. If you’re not proactively testing restores, you’re just hoping they work when disaster strikes. Hope is not a strategy.

• Test different restore scenarios: Full, differential, and transaction log restores.
• Validate integrity with DBCC CHECKDB after restores.
• Ensure RTO and RPO align with business needs. (Translation: Can you restore fast enough to avoid a business meltdown?)
• Automate restore tests so you’re not guessing when the pressure is on.

Automating Restore Tests with dbatools

If you’re not testing restores because it’s “too time-consuming,” dbatools.io has your back. The Test-DbaLastBackup command automates the process by:

1. Restoring the last backup of a database to a test environment.
2. Running DBCC CHECKDB to ensure data integrity.
3. Reporting on success or failure, so you know where issues exist before you actually need the backup.

Example Command:
Test-DbaLastBackup -SqlInstance YourSQLServer -Databases YourDatabase

This takes a lot of manual effort out of the equation—no more excuses for not testing!

Action Plan for SQL Server Resilience

1. Schedule regular test restores (weekly or monthly) and document the process.
2. Use DBCC CHECKDB to verify database integrity post-restore.
3. Leverage Test-DbaLastBackup to automate restore verification.
4. Confirm backup files are accessible and stored securely offsite.
5. Train your team on recovery processes—because backups are useless if no one knows how to restore them.
6. Monitor backup success, but more importantly, track restore success.

The Bottom Line:

A backup plan without restore testing is a disaster waiting to happen. Don’t wait until you’re knee-deep in downtime to realize your backups weren’t as solid as you thought. Test your restores. Validate your data. Sleep better at night.

Thanks for reading!

–Kevin

New Pocket DBA® clients get the first month FREE!

Get a Free SQL Server Health Check!

 

 

Filed Under: backup, HADR, Restore, SQL Tagged With: syndicated

The Cost of Not Having a DBA

April 2, 2025 by Kevin3NF Leave a Comment

Does skipping a DBA save money? Wait until your system grinds to a halt, your backups fail, or your cloud bill skyrockets.

The “DBA? We Don’t Need No Stinkin’ DBA” Mindset

Common Excuses That Lead to Expensive Problems:

  • “Our system runs fine,”
  • “The cloud takes care of it”
  • “Our sysadmin is really smart”
  • “DBAs are expensive”

 

SQL Server is an Enterprise level database product with so many facets to it you could make 5 different careers developing and supporting it (DBA, Developer, BI Stack, Analyst and more). Terabytes of data, thousands of transactions per second.

I have seen repeated instances of someone not fully trained as a DBA reaching out to Google (faster than vendor support) for answers only to find a 15-year-old blog post and start throwing ancient answers at the server. More than once, a client has reached out to me while on hold with the vendor!

The Hidden Costs of Hiring a Junior DBA

Junior DBAs are generally wonderful people. I don’t bash people, pretty much ever. Almost all of them come from other parts of the overall IT ecosystem. The strongest DBA skills come from a LOT of study and a LOT of practice. You don’t get that in 2 years.

Your shiny new DBA (if you have one) might not realize the nuances of the following critical items:

  • Index design at the table level – too many, not enough, duplicates, etc.
  • Query tuning – When is a cursor fine, and when is it bad? What’s killing tempdb? What the heck is RBAR?
  • Inefficient server level configurations. As I typed this, I found 2 major systems at a new client with some horrible default settings that are causing them very high CPU utilization. They are paying monthly for Enterprise licenses they shouldn’t need!
  • Security – Poorly managed permissions = open door for ransomware you may never fully recover from.
  • A Junior DBA may not be test restoring your databases. You MUST know that your backups are valid if you want to meet management expectations.
  • I did this early in my SQL career – ASK FOR HELP sooner rather than later! Junior “anything” people will frequently try too hard to figure something out on their own before seeking assistance.

 

How Not Having a DBA Hurts Your Business

  • Longer downtimes – lets face reality – having a seasoned veteran on speed-dial or in the office means a faster response and resolution. Opening a ticket with your vendor or hunting for a consultant available “now” is difficult, at best.
  • Slow performance leads to lost productivity, angry employees, and customers buying elsewhere. When they STOP complaining, it has gone way too far.
  • Compliance failures if security and audits aren’t handled properly can be costly in fines or remediation expenses.
  • Expensive cloud bills due to inefficient configurations. The cloud isn’t free, or even cheap. Don’t take that nonsense from the cloud vendors. It’s far worse if you are paying for double the hardware of what you really need. Having access to DBA skills can help you right-size!

 

What’s the Right Balance?

A full-time mid to senior DBA makes a lot of sense when there are multiple SQL Servers (25+), various projects happening, tight RPO/RTO requirements, etc.

I ran a poll on LinkedIn asking where the line is drawn on how many SQL Servers a 5-7 year DBA can support:

With a small number of servers, a full-time Sr. DBA is probably overkill. They are going to get bored. I spent a year baby-sitting 4 servers for one of the Big 4 accounting firms. I worked 30 minutes a day and drank a lot of coffee. Until I couldn’t take it anymore and started Dallas DBAs.

With a limited footprint, you are probably better off outsourcing. You might look for a Senior DBA that freelances on the side (availability might be an issue), or a firm that offers a mix of maintenance and off-hours. Dallas DBAs is the best in the world of course (😊):

The Bottom Line: What Should You Do Next?

Get a SQL Server Health Check done. Periodically.
Look for signs of database neglect: Slow queries, long downtimes, too many people with sysadmin rights.
Don’t wait until you’re in emergency mode! Get ahead of the chaos today.

Thanks for reading!

Kevin

My Newsletter (full version)

New Pocket DBA® clients get the first month FREE!

Join my ‘Accidental SQL DBA‘ group here

Get a Free SQL Server Health Check!

Filed Under: Emergency & Troubleshooting, SQL Tagged With: syndicated

SQL Server Source Control on a $0 Budget

March 27, 2025 by Kevin3NF Leave a Comment

The Source Control Dilemma

Every DBA has been there. Trying to keep track of database schema changes while developers have their fancy Git repositories and version control workflows. Meanwhile, database changes are often handled through a mix of manual scripts, backups, and maybe a SharePoint folder full of “final_final_v2.sql” files.

Did you know that SQL Server already has a built-in tool that can help you track your database schema changes, without spending a dime on third-party tools? Enter DBCC CloneDatabase, the secret weapon for DBAs who want version control without the price tag.

  • What it does: Creates a schema-only copy of a database.
  • Why it’s great for source control: Captures object definitions, indexes, statistics, etc. all without data.
  • No third-party tools, no extra licensing costs.

How to Use DBCC CloneDatabase

  • Step 1: Run DBCC CloneDatabase (SourceDB, CloneDB)
  • Step 2: Script out the cloned database.
  • Step 3: Commit the script to Git (or another VCS).
  • Step 4: Or, skip steps 2 and 3, and let the clone sit there. But put that db in read-only.

Benefits Over Other Methods

  • No need for expensive 3rd party software licensing.
  • Fast, lightweight, and built into SQL Server.
  • Keeps a clean history of schema changes, assuming you keep the script and/or backups elsewhere

Bonus Tips

  • Automate the process: Set up a job to create clones regularly and back them up
  • Use in disaster recovery scenarios to validate schema integrity. Compare the clone to the prod database using SQL Server Data tools.

The Bottom Line: SQL Source Control Without the Price Tag

DBAs can manage versions like developers, without breaking the budget. Simple, effective, and already included in SQL Server.

Look how easy this is:

Thanks for reading!

–Kevin

Get a Free Health Check for your most important SQL Server today from Dallas DBAs.

Filed Under: Development, SQL, Tools Tagged With: syndicated

Our SQL Server is Slow! What Do I Do First?

March 19, 2025 by Kevin3NF Leave a Comment

Don’t Panic!

It’s a vague but common complaint, frequently with no additional details. Before blindly restarting SQL Server, let’s walk through quick checks that don’t require deep DBA skills.

Step 1: Is the Server Itself Struggling?

Before blaming SQL, check system-level resources

  • Check:
    • Is CPU pinned at 100%? SQL Server could be a victim of something else on the box
      • Task Manager is your friend for CPU…less so for memory
    • Is SQL Server using 100% of the memory, and starving windows? It should be capped to maybe 90%
    • Are disk latencies/usage high? Use Resource Monitor to check this
  • Quick Fixes:
    • If CPU is the problem, find the process consuming it. SQL Server? Another app?
    • If memory is an issue, see if SQL is configured to take everything (default setting is 2 PB).
    • Low disk space? It won’t typically cause slow performance but it can cause errors.

Step 2: What Queries Are Running Right Now?

  • Use sp_whoisactive. This free tool has helped solve thousands of “slow” complaints over many years
    • Look for:
      • Long-running queries
      • Blocked Processes
      • High CPU usage queries
      • Locking issues
  • SQL Server has a bunch of reports at the instance level, as well as a Performance Dashboard:

  • Quick Fixes:
    • If a query has been running for hours and shouldn’t be, investigate before killing it.
    • If blocking is an issue, find the lead blocker. It’s frequently the real problem. There are “lead blocker” scripts all over the internet
      • I don’t recall where I got this one, but it works:
        • SELECT
              spid
              ,sp.STATUS
              ,loginame   = SUBSTRING(loginame, 1, 12)
              ,hostname   = SUBSTRING(hostname, 1, 12)
              ,blk        = CONVERT(CHAR(3), blocked)
              ,open_tran
              ,dbname     = SUBSTRING(DB_NAME(sp.dbid),1,10)
              ,cmd
              ,waittype
              ,waittime
              ,last_batch
              ,SQLStatement       =
                  SUBSTRING
                  (
                      qt.text,
                      er.statement_start_offset/2,
                      (CASE WHEN er.statement_end_offset = -1
                          THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2
                          ELSE er.statement_end_offset
                          END - er.statement_start_offset)/2
                  )
          FROM master.dbo.sysprocesses sp
          LEFT JOIN sys.dm_exec_requests er
              ON er.session_id = sp.spid
          OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt
          WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses)
          AND blocked = 0

           

Step 3: Are There Index Problems?

  • SQL Server needs good indexing. Missing or fragmented indexes = bad performance.
    • Check for missing indexes:
      • SELECT * FROM sys.dm_db_missing_index_details
    • Check for fragmentation:
      • SELECT * FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, ‘LIMITED’)
        • If you are on SSDs, this is very unlikely to be the issue.
  • Quick Fixes:
    • If missing indexes show up, don’t blindly create them—validate first.
    • Rebuilding/reorganizing indexes might help, but don’t do it blindly on huge tables.

Step 4: Is TempDB a Bottleneck?

  • If TempDB is under stress, everything suffers.
  • Check for open/hung transactions:
  • DBCC OPENTRAN
    • Long-running transactions can fill up tempdb and transaction log files.
  • Quick Fixes:
    • Verify you have proper number of TempDB data files (this is a specific fix for allocation performance issues).
    • Restarting SQL clears TempDB, but that’s a temporary fix.

Step 5: Query Store

  • If Query Store is enabled, use it to find consistently bad queries.
  • Look for:
    • High resource-consuming queries
    • Execution plans that suddenly changed
  • Quick Fix:
    • For unstable plans, forcing a known good plan might be a short-term fix.

The Bottom Line: Don’t Panic! Measure First

  • Gather stats before you restart – outside of Query Store, SQL Server logs almost nothing to help you troubleshoot.
  • Most slowdowns have a root cause rather than “just SQL being slow.”
  • Use these steps to find where the problem is before making changes.
  • If these checks don’t point to a clear fix? That’s when you bring in a DBA.

Filed Under: Performance Tuning, SQL Tagged With: syndicated

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 4
  • Go to page 5
  • Go to page 6
  • Go to page 7
  • Go to page 8
  • Interim pages omitted …
  • Go to page 16
  • Go to Next Page »

Primary Sidebar

Search

Sign up for blogs, DBA availability and more!

Home Blog About Privacy Policy
  • Home-draft
  • Blog
  • About Us

Copyright © 2026 · WordPress · Log in

 

Loading Comments...