five steps to being a top dba learning automation in sql server

20
EMBARCADERO TECHNOLOGIES EMBARCADERO TECHNOLOGIES Five Steps to Being a Top DBA Learning Automation in SQL Server Joey D’Antoni 25 March 2015

Upload: embarcadero-technologies

Post on 16-Jul-2015

148 views

Category:

Software


0 download

TRANSCRIPT

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

EMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIES

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

25 March 2015

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

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

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

EMBARCADERO TECHNOLOGIES

Agenda

Everyone is Really Busy

Introduction to Tools

Cool Automation Tricks

Another Tool to Reduce Your Workload

3

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

EMBARCADERO TECHNOLOGIES

4

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

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

EMBARCADERO TECHNOLOGIES

Automation

5https://xkcd.com/1205/

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

EMBARCADERO TECHNOLOGIES

Standards

6

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

EMBARCADERO TECHNOLOGIES

Tricks of the Trade

PowerShell SQLCMD DOSDynamic SQL

and Concatenation

Agent Jobs

7

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

EMBARCADERO TECHNOLOGIES

PowerShell

A must have for Windows tasks

You can’t automate Azure

without it

SQL PS has some limitations

8

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

EMBARCADERO TECHNOLOGIES

SQLCMD

Command Line interface to SQL Server

Very, very powerful

Can integrate with SQL Agent or Windows Scheduler

9

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

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

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

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

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

EMBARCADERO TECHNOLOGIES

Agent Jobs

Use the Scheduler

More than jobs—alterting and notifications

Regular Data Collection and Automation

12

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

EMBARCADERO TECHNOLOGIES

Now You Have the Tools

13

Let’s Build Something Cool

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

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

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

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

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

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

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

EMBARCADERO TECHNOLOGIES

Demo—Availability Groups DB Add

Complex example of T-SQL automation

Some interesting techniques

17

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

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

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

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

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

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