Sql Server 2017 Yeni Komut Satırı (MacOs-Linux-Windows) – Linux DBFS Dmv Tool
Sql Server 2017 ile birlikte MacOs, Linux ve Windows için geçerli olacak yeni Sql Server komut satırı ile birlikte gelecek. Mssql-scripter ve DBFS olarak iki tane yeni tool Sql Server ailesine katılmış bulunuyor.
Mssql-scripter toolu, developer ve Dba’lerin T-SQL scriptlerini Create ve Insert etmesine olanak sağlayacak. Sql Server on-prem’in yanı sıra, Azure Sql DB ve Azure Sql DataWarehouse içinde geçerli olacak.
DBFS toolu ise, Dba’lerin kullandığı DMV dediğimiz Dynamic Management Views’ların daha kolay kullanılmasını sağlayacak. Linux işletim sisteminde özellik bu araçla performance counterları rahatlıkla izlenebilecek.
Mssql-scripter, Sql Server Management Studio’daki Generate Script Wizard ile benzer özelliklere sahip multiplatform bir komut satırı olarak karşımıza çıkıyor. Mssql-scripter’ı Linux, MacOS ve Windows üzerinde data definition language (DDL) ve data manipulation language (DML) scriptlerini istediğiniz yerde çalıştırabilme rahatlığı sunuyor. Aynı zamanda Azure Sql Databaseleri ve Azure Sql Data Warehouse içinde kullanabilmektedir.
Mssql-scripter ile oluşturulan scriptleri .sql dosyası olarak da kaydedebilirsiniz. Mssql-scripter Phyton ile geliştirilmiş, yeni çıkan Azure CLI 2.0 toolu içerisindeki çalışma prensiplerini kapsamaktadır. Kaynak kodunu aşağıdaki Github linkinden inceleyebilirsiniz.
https://github.com/Microsoft/sql-xplat-cli
Mssql-scripter Windows Kurulumu
Phyton, Windows da varsayılan olarak gelmemektedir. Aşağıdaki linkten ilk olarak Phyton’u indirip kuruyoruz.
https://www.python.org/downloads/
MSCR – 1
Executable veya zip li halibi indirebilirsiniz. Add Phyton 3.6 to Path seçeneğini
MSCR – 2
Phyton for Windows kurulduktan sonra, mssql-scripter’ı komut satırına aşağıdaki kodu yazarak yüklüyoruz.
C:\> pip install mssql-scripter
MSCR – 3
Kurulum tamamlandığında aşağıdaki gibi succesfully mesajını verecek.
Successfully installed future-0.16.0 mssql-scripter-1.0.0a1 mssqltoolsservice-Windows-7-64-1.0.0a1 wheel-0.29.0
Linux ve MacOS Kurulumu
Linux ve MacOS tarafında ise aşağıdaki kod ile Phyton kurulumunu yapabilirsiniz.
sudo apt-get install python-pip
Kurulum başladı
MSCR – 4
Upgrade komutu ile de, son versiyonu kontrol ediyoruz.
sudo pip install --upgrade pip
Pyhton 9.0.1 yüklenmiş oldu.
MSCR – 5
Pyhton yüklendikten sonra, mssql-scipter’ı yükleyebiliriz. Aşağıdaki komut ile Linux üzerine mssql-scripter’ı yükleyebiliriz.
sudo pip install mssql-scripter
Mssql-scripter yüklenmiş oldu.
MSCR – 6
Msscripter Kullanımı
Sqlcmd’ye benzer bir yapısı olan mssql-scripter’in kullanımına bakalım.
Veritabanındaki tüm nesnelerin sciptlerini çıkarmak çıkartmak için aşağıdaki scripti kullanıyoruz.
C:\> mssql-scripter -S localhost\CTP21 -d AdventureWorks2014 -U sa
-S Sunucu adı ve inscatence bilgisi
-d Veritabanı
-U Sql login bilgisi
Sql login ile bağlanıldıktan sonra kullanıcının şifre bilgisini girmemiz gerekmektedir.
MSCR – 7
Databasedeki tüm objectlerin scriptlerini buraya yazmak uzun olacağından örnek olarak aşağıda bir trigger’ın script örneği var.
MSCR – 8
Sadece schema istenirse, –schema-only parametresini eklememiz gerekiyor
mssql-scripter -S localhost -d AdventureWorks -U sa --schema-only
Sql server version bilgisi için
mssql-scripter -S localhost\CTP21 -d AdventureWorks2014 -U sa –target-server-version “vNext” > myData.sql
Tüm datayı .sql file olarak kaydetmek için aşağıdaki scripti kullanıyoruz.
mssql-scripter -S localhost -d AdventureWorks2014 -U sa --data-only > ./adventureworks-data.sql
Mssql-scripter ile ilgili tüm komutları,
Mssql-scripter –h
Help komut ile elde edebilirsiniz.
Tüm komutlar;
$ mssql-scripter -h
usage: mssql-scripter [-h] [--connection-string | -S ] [-d] [-U] [-P] [-f]
[--data-only | --schema-and-data]
[--script-create | --script-drop | --script-drop-create]
[--target-server-version {2005,2008,2008R2,2012,2014,2016,vNext,AzureDB,AzureDW}]
[--target-server-edition {Standard,PersonalExpress,Enterprise,Stretch}]
[--include-objects [[...]]] [--exclude-objects [[...]]]
[--ansi-padding] [--append] [--check-for-existence] [-r]
[--convert-uddts] [--include-dependencies] [--headers]
[--constraint-names] [--unsupported-statements]
[--object-schema] [--bindings] [--collation]
[--defaults] [--extended-properties] [--logins]
[--object-permissions] [--owner] [--use-database]
[--statistics] [--change-tracking] [--check-constraints]
[--data-compressions] [--foreign-keys]
[--full-text-indexes] [--indexes] [--primary-keys]
[--triggers] [--unique-keys] [--display-progress]
[--enable-toolsservice-logging] [--version]
Microsoft SQL Server Scripter Command Line Tool. Version 1.0.0a1
optional arguments:
-h, --help show this help message and exit
--connection-string Connection string of database to script. If connection
string and server are not supplied, defaults to value
in Environment Variable
MSSQL_SCRIPTER_CONNECTION_STRING.
-S , --server Server name.
-d , --database Database name.
-U , --user Login ID for server.
-P , --password Password.
-f , --file Output file name.
--data-only Generate scripts that contains data only.
--schema-and-data Generate scripts that contain schema and data.
--script-create Script object CREATE statements.
--script-drop Script object DROP statements
--script-drop-create Script object CREATE and DROP statements.
--target-server-version {2005,2008,2008R2,2012,2014,2016,vNext,AzureDB,AzureDW}
Script only features compatible with the specified SQL
Version.
--target-server-edition {Standard,PersonalExpress,Enterprise,Stretch}
Script only features compatible with the specified SQL
Server database edition.
--include-objects [ [ ...]]
Database objects to include in script.
--exclude-objects [ [ ...]]
Database objects to exclude from script.
--ansi-padding Generates ANSI Padding statements.
--append Append script to file.
--check-for-existence
Check for database object existence.
-r, --continue-on-error
Continue scripting on error.
--convert-uddts Convert user-defined data types to base types.
--include-dependencies
Generate script for the dependent objects for each
object scripted.
--headers Include descriptive headers for each object scripted.
--constraint-names Include system constraint names to enforce declarative
referential integrity.
--unsupported-statements
Include statements in the script that are not
supported on the target SQL Server Version.
--object-schema Prefix object names with the object schema.
--bindings Script options to set binding options.
--collation Script the objects that use collation.
--defaults Script the default values.
--extended-properties
Script the extended properties for each object
scripted.
--logins Script all logins available on the server, passwords
will not be scripted.
--object-permissions Generate object-level permissions.
--owner Script owner for the objects.
--use-database Generate USE DATABASE statement.
--statistics Script all statistics.
--change-tracking Script the change tracking information.
--check-constraints Script the check constraints for each table or view
scripted.
--data-compressions Script the data compression information.
--foreign-keys Script the foreign keys for each table scripted.
--full-text-indexes Script the full-text indexes for each table or indexed
view scripted.
--indexes Script the indexes (XML and clustered) for each table
or indexed view scripted.
--primary-keys Script the primary keys for each table or view
scripted.
--triggers Script the triggers for each table or view scripted.
--unique-keys Script the unique keys for each table or view
scripted.
--display-progress Display scripting progress.
--enable-toolsservice-logging
Enable verbose logging.
--version show program's version number and exit
DBFS
DBFS, Linux tarafında Sql Server DMV’lerini komut tarafında görüntülenmesini ve izlenmesini sağlayan bir tooldur.
Kurulum
Ubuntu için aşağıdaki komutlar ile DBFS kurulumunu yapabilirsiniz.
sudo wget https://github.com/Microsoft/dbfs/releases/download/0.1.5/dbfs_0.1.5_amd64.deb
sudo dpkg -i dbfs_0.1.5_amd64.deb
sudo apt-get install -f
DMV ler için bir çalışma klasörü oluşturalım
$ mkdir DMV
Config bilgilerinin tutulacağı bir dosya oluşturalım
touch dmvtool.config
Config dosyasını nano programı ile düzenleyeceğiz,
nano dmvtool.config
Karşımıza gelmekte, gelen ekrana aşağıdaki örnekteki gibi config bilgilerini yazıyoruz.
[server]
hostname=00.000.000.000
username=sa
password=”Şifreniz”
version=16
Exit ile nano dosya editlemesinden çıkıyoruz, çıkmadan önce dosyayı kaydetmek için Y ile onay veriyoruz.
Cd komutu ile DMV leri yüklediğimiz klasöre geliyoruz
Cd /DMV/server
ls ile tüm dmv leri aşağıdaki gibi görmeiz gerekiyor
MSCR – 9
Çalıştırmak istediğimiz DMV nin başına cat komutunu yazarak çalıştırabiliriz.
cat dm_os_sys_memory
veya
cat dm_os_sys_memory.json | python -m json.tool
MSCR – 10
awk '{print $1,$5}' dm_os_sys_memory | column -t
join -j 1 -o 1.1,1.16,1.17,2.5,2.8 <(sort -k1 dm_exec_connections)
<(sort -k1 dm_exec_connections) -t $'\t'
| sort -n -k1 | column -t
Bu makalede sizlere, Sql Server 2017 ile birlikte gelen mssql-scripter ve Linux tarafında DMV lerin izlenmesini sağlayan DBFS toollarını anlatmaya çalıştık. Bir sonraki Sql Server 2017 yenilikleri makalesinde görüşmek üzere.