Five Steps to Being a Top DBA Learning Automation in SQL Server

Preview:

Citation preview

EMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIES

Five Steps to Being a Top DBA Learning Automation in SQL ServerJoey D’Antoni

25 March 2015

EMBARCADERO TECHNOLOGIES

Joey D’Antoni

• Joey has over 15 years of experience with a wide variety of data platforms, in both Fortune 50 companies as well as smaller organizations

• He is a frequent speaker on database administration, big data, and career management

• He is the co-president of the Philadelphia SQL Server User’s Group

• MSCE, Business Intelligence

• He wants you to make sure you can restore your data

Joeydantoni.com

EMBARCADERO TECHNOLOGIES

Agenda

Everyone is Really Busy

Introduction to Tools

Cool Automation Tricks

Another Tool to Reduce Your Workload

3

EMBARCADERO TECHNOLOGIES

4

Does Your Job Feel Like This?You Want to Get to Here

EMBARCADERO TECHNOLOGIES

Automation

5https://xkcd.com/1205/

EMBARCADERO TECHNOLOGIES

Standards

6

EMBARCADERO TECHNOLOGIES

Tricks of the Trade

PowerShell SQLCMD DOSDynamic SQL

and Concatenation

Agent Jobs

7

EMBARCADERO TECHNOLOGIES

PowerShell

A must have for Windows tasks

You can’t automate Azure

without it

SQL PS has some limitations

8

EMBARCADERO TECHNOLOGIES

SQLCMD

Command Line interface to SQL Server

Very, very powerful

Can integrate with SQL Agent or Windows Scheduler

9

EMBARCADERO TECHNOLOGIES

DOS

DOS is still alive

Mainly because I haven’t ported all

of my code to PowerShell

Can still be useful—especially

if on older Windows releases

10

EMBARCADERO TECHNOLOGIES

Dynamic SQL and Concatantion

11

--Create the files

WHILE @number_of_files > 0BEGINif @number_of_files = 1 -- main tempdb file, move and re-sizeBEGINSELECT @sql_statement = 'ALTER DATABASE tempdb MODIFY FILE (NAME = tempdev, SIZE = '+convert(nvarchar(25), @individ_file_size) + ', filename = '+nCHAR(39)+@data_file_path+'tempdb.mdf'+nCHAR(39)+',MAXSIZE = '+ convert(nvarchar(25),@individ_file_size) + ', FILEGROWTH = 100MB);';ENDELSE -- numbered tempdb file, add and re-sizeBEGINSELECT @sql_statement = 'ALTER DATABASE tempdb ADD FILE (NAME = tempdev0' + convert(nvarchar(25),@number_of_files)+',filename = '+nCHAR(39)+@data_file_path+'tempdb0' + convert(nvarchar(25),@number_of_files)+'.ndf'+nCHAR(39)+', SIZE = '+ convert(varchar(25), @individ_file_size) + ', MAXSIZE = '+ convert(nvarchar(25), @individ_file_size) + ', FILEGROWTH = 100MB);';END

EXEC sp_executesql @statement=@Sql_StatementPRINT @sql_statement

EMBARCADERO TECHNOLOGIES

Agent Jobs

Use the Scheduler

More than jobs—alterting and notifications

Regular Data Collection and Automation

12

EMBARCADERO TECHNOLOGIES

Now You Have the Tools

13

Let’s Build Something Cool

EMBARCADERO TECHNOLOGIES

Demo--SQL Server Install and Best Practices

Default SQL Servers installs are a bad thing

Every time someone leaves cost threshold for parellelism at 5, a kitten dies

Let’s fix this..

14

EMBARCADERO TECHNOLOGIES

Demo--SQLCMD Dynamic SQL for Backups

This is a simple demo of the combination of some dynamic SQL and SQLCMD

Just an example—still schedule as an agent job

Or just use Ola’s script

15

EMBARCADERO TECHNOLOGIES

Demo--Patching SQL Server

Will use a combination of commands and PowerShell for CU automation

Use PowerShell to verify patch successful and notify admin

16

EMBARCADERO TECHNOLOGIES

Demo—Availability Groups DB Add

Complex example of T-SQL automation

Some interesting techniques

17

EMBARCADERO TECHNOLOGIES

Automation

With these tools the only limits are your imagination

Any repetitive tasks can and should be automated

Take advantage of scripting tools

Test, Test, Test and Test some more

18

EMBARCADERO TECHNOLOGIES

Summary

I didn’t say DevOps—but this is kind of what DevOps is like

Automation makes you a better DBA—you can focus on value added activities like query tuning

Start small (installations) and build your skills to advanced techniques like patching and code deployments

19

EMBARCADERO TECHNOLOGIES

Thank you for attending!

Connect with us

20

Read Joey’s Blog

Community.embarcadero.com

Take our word for

it & try it out!

http://www.embarcadero.com/products/DBArtisan

Take our surveyLocated in the chat window

https://www.surveymonkey.com/s/TopDBA

Community.embarcadero.com