Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Trigger und Event Notifications im SQL Server 2005

Ähnliche Präsentationen

Präsentation zum Thema: "Trigger und Event Notifications im SQL Server 2005"—  Präsentation transkript:

1 Trigger und Event Notifications im SQL Server 2005
Microsoft TechNet Seminar 2006 Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program Seminar Name

2 Microsoft SQL Server 2005 Architektur
Komponenten des SQL Server 2005 RDBMS ETL Werkzeug OLAP Server Data Mining Reporting-Dienste Management-Tools Entwicklungs-Tools Development Tools Reporting Services Management Tools Analysis Services OLAP & Data Mining Integration Services ETL SQL Server Relational Engine

3 Agenda Aktive Komponenten DML- und DDL-Trigger Event Notifications
Ausblick SQL Server 2008

4 Aktive Komponenten SQL Server Agent Trigger Event Notifications
Jobs (Automatisierung) Alerts (Ereignis und Aktion) Trigger Event Notifications Declarative Management Framework (ab „Katmai“)

5 Agenda Aktive Komponenten DML- und DDL-Trigger Event Notifications
Ausblick SQL Server 2008

6 DML- und DDL-Trigger Prozeduren, die bei Datenbankereignissen automatisch ausgeführt werden Laufen im Kontext des Auslösers ab (sind Teil der Transaktion, die sie ausgelöst hat) Können den Auslöser zurückrollen Werden nur einmal pro Befehl ausgeführt DML- und DDL- / LOGON-Trigger AFTER- und INSTEAD OF-Trigger T-SQL- und .NET-Trigger

7 Ausführung im Kontext Zurückrollen der Transaktion möglich
Beim Zurückrollen entstehen doppelte Kosten, daher n.M. constraints (Datentyp, CHECK, DEFAULT, PK, FK, DRI) benutzen Berechtigungskontext beachten! CREATE TRIGGER trg1 ON dbo.tbl1 AFTER INSERT AS IF EXISTS(SELECT * FROM inserted WHERE col1 = <some_value>) ROLLBACK TRANSACTION DML bitte erst *nach* dem Rollback! ;)

8 Verschachtelung und Rekursion
Trigger können standardmäßig andere Trigger auslösen Trigger können sich selbst aufrufen (ALTER DATABASE <name> SET RECURSIVE_TRIGGERS ON;)

9 AFTER Trigger inserted und deleted Spezialtabellen
inserted: Zeilen für INSERT und UPDATE deleted: Zeilen für UPDATE und DELETE Mehrere Trigger pro Objekt möglich (Reihenfolge nur als „first“ und „last“; sp_settriggerorder)

10 INSTEAD OF Trigger Original-Anweisung wird durch den Code des Triggers komplett ersetzt inserted und deleted enthalten die Daten, die geändert worden *wären*! Nie rekursiv, immer nur einer pro Operation Auch auf Sichten möglich Werden *vor* contraint-Prüfung ausgeführt

11 DDL Trigger Auf Datenbank oder Serverebene
Für einzelne DDL Ereignisse oder Gruppen EVENTDATA() Funktion Nur AFTER Trigger CREATE TRIGGER ddlTrigger ON DATABASE FOR DROP_TABLE

12 CLR Trigger Trigger können seit SQL Server 2005 in .NET geschrieben werden Zugriff auf die .NET Klassenbibliotheken Zugriff auf externe Ressourcen Warnung: Transaktion erst beendet, wenn Trigger fertig! Externe Aufrufe eine Sicherheitsproblem! [SqlTrigger(Event=„FOR INSERT“)] public static void trg_LogToEventlog() { …

13 Agenda Aktive Komponenten DML- und DDL-Trigger Event Notifications
Ausblick SQL Server 2008

14 Trigger bieten im Vergleich zu Event Notifications den Vorteil, dass sie im Kontext der sie auslösenden Transaktion ablaufen (und sie daher auch zurückrollen können). Gleichzeitig leiden sie aber auch an dem eklatanten Nachteil, dass sie im Kontext der sie auslösenden Transaktion ablaufen (und die Transaktion folglich warten muss, bis jegliche Triggeraktivität beendet ist, ehe sie fortfahren kann)! WAITFOR DELAY ‚0:03‘; …

15 Event Notifications „Asynchrone Antworten auf ein Ereignis“
Können keine Transaktionen zurückrollen! Trigger: Reaktion auf DML und DDL Ereignisse Führen Code aus Event Notifications: Reaktion auf DDL und Trace/Performance Ereignisse (CREATE TABLE, LOCK_DEADLOCK,…) Senden XML-Nachrichten

16 Voraussetzungen für Event Notifications
SQL Server 2005 oder neuer Service Broker Nachrichtenwarteschlange muss aktiviert sein Ein Dienst, der auf EN reagiert, muss erstellt werden Erweiterte Service Broker Funktionalität (Aktivierung, …) kann genutzt werden

17 Agenda Aktive Komponenten DML- und DDL-Trigger Event Notifications
Ausblick SQL Server 2008

18 Productive Policy-based Management of your infrastructure
Enterprise Data Platform Productive Policy-based Management of your infrastructure Spend less time on ongoing operations Manage via policies instead of scripts Define Enterprise wide data management policies Automated monitoring and enforcement of policies Simplify your installation and configuration Integrated with your enterprise system management Define Policies that are compliant with System Definition Model Manage your data and system infrastructure with Microsoft System Center Declarative Management Framework Server Group Management Streamlined Installation Enterprise System Management <Note: this blurb covers background on the Declarative Management Framework (DMF) which is SQL Server’s new modern approach to database management and part of SQL Server’s continuing investment in the Dynamic Systems Initiative (DSI) see It also describes some key improvements to Setup and Install that are coming with Katmai> Today DBAs spend a large amount of their time manually running and monitoring jobs, or writing complex code to define tasks to run, standard database maintenance tasks.  This can be extremely challenging, since (1) the "triggers" for these tasks are often complex, requiring in-depth understanding of the product and intimate understanding of database workload, and (2) "best practices" are often very relative things, varying wildly based on workload, hardware, and other production server considerations.  Understanding when a given task should be run, monitoring that task, and appropriately reacting to its outcome requires a lot of administrative overhead -- this costs money. To dramatically improve the productivity of DBAs we need a new approach which Simplifies the process of database management by removing the need for detailed knowledge and providing the right level of automation; AND Scales to the hundreds or thousands of servers to be managed in a large enterprise To achieve this we need to move from management through detailed configuration setting to management by declarative intent or policy. More simply put we want to define how the system should be and not the detailed means to achieve it. The basic idea in Declarative Management is simple ---- raise the level of abstraction so that the admin manages SQL Server via concepts that are natural to them. These conceptual actions involve defining management policies and applying them to targets. For Example, “I should be able to recover data to within an hour” versus physical statements describing how they should be enforced (e.g.: “create a backup job with an hourly schedule”). In Katmai, the focus will be on a subset of important areas to do with Over several releases we want to apply these ideas across the board to _all_ the management experiences and tools in SQL Server. 1) the installation, configuration and security of SQL Server including many of the Best Practices that are recommended by the existing Best Practice Analyzers Surface Area Configurator (SAC) Upgrade Advisor (UA) Best Practice Analyzer (BPA) Note that we are not simply replacing the functionality of these tools. The existing tools must be run periodically and only audit the configuration of the system and report compliance. With Katmai the new Declarative Management framework will Enable forced compliance to policy (instead of simply monitoring via periodic polling); and Will enable customers to author and apply their own policies based on the needs of their organization 2) Automation of standard administration tasks based on a policy explicitly set by the user, in this case automatic index defragmentation when index fragmentation, or index space utilization problems are detected, a background task can be queued to correct the problem Setup and Install Katmai will introduce significant improvements to the Service Lifecycle for SQL Server through the re-engineering of the installation, setup and configuration architecture. These improvements will separate the installation of the physical bits on the hardware from the configuration of the SQL Server software. This will enable the following key benefits The ability to create a disk image of a basic unconfigured installation to enable wide-spread distribution and installation of the software to a number of servers The ability to install the base software, applicable service packs and patches as a single transaction The ability for the software to download and install the latest patches from an internal corporate location or from Microsoft over the Internet during the install process The ability to create installation and configuration templates for standard configuration types to accelerate the installation of standard database configurations including a default set of pre-populated templates from Microsoft The ability to check compliance with or enforce organizational installation and configuration policies at the time of installation and/or configuration The ability to uninstall service packs As part of SQL Server’s commitment to the Dynamic Systems Initiative, the models used in the Declarative Management Framework will be compliant with the Service Modeling Language Specification (SML) that Microsoft, IBM, HP, EMC, Intel, Sun, BEA and others are driving as a new industry standard to enable management of distributed systems. This will also provide the mechanism for SQL Server to be monitored and managed by the new System Centre family of products from Microsoft including System Center Operations Manager and System Center Configuration Manager. Background Info for DMF What does an admin really do on a day-to-day basis? He has to manage a database server instance that has a number of applications installed on it. This is the management target. He needs to make sure that the target is configured to meet certain goals (for example, that data is recoverable if there is a system failure). These goals are the management policy he wants to ensure. Further, he needs to monitor that the policies stay in effect, report on the health of the server (that it is conforming to the desired policy), and occasionally react when the server no longer conforms to the desired policy. Today, in order to effect this, the admin has to translate these policies to a set of detailed low-level actions that configure the system. This needs significant knowledge of the various options exposed by SQL Server, and significant knowledge of the details and semantics of the deployed applications. It is not easy and intuitive. The admin needs to establish separate monitoring and reporting mechanisms (i.e. automation has to be manually established) and this process must be repeated individually for every single server being managed (i.e. there are no efficiencies of scale in management).

19 Optimized And Predictable Performance
Enterprise Data Platform Optimized And Predictable Performance Optimize your System Performance Monitor your system by collecting and storing system events Analyze and report on your system performance Reduce your storage costs and increase query performance Predictable performance Manage concurrent workloads on single system Prevent runaway queries Ensure consistent query performance Performance Data Collection System Analysis Data Compression Query Optimization Modes Resource Governor One of the largest consumers of DBA time is performance tuning and troubleshooting. To help address this we are investing in dramatically improving the performance insight we can deliver to DBAs through the development of more extensive performance data collection, a centralized data warehouse for storing this performance data and some initial tools for reporting and monitoring that will be extended in future releases. Continuous performance monitoring for a set of KPIs will be provided based on collected and cached data. Data will be uploaded to the warehouse on a user-defined schedule. Users will also be able to trigger uploads on demand to get a current snapshot. Although the overhead cost of performance data collection will definitely depend on what is being collected. We aim to have <5% CPU overhead and <5% Physical Memory overhead for a default set of performance-related collections that we would recommend run all the time. The solution consists of three key parts A Data collector - which enables collection of specific data sets. It will allow users to track the top 10 issues Microsoft typically sees in support e.g. tracking memory usage, disk usage etc. as well as enabling the user to define other sets of events to be tracked Performance Data warehouse – which persists an historical record of the data collected; and Reports - These reports will address the top 10 issues Microsoft sees in support including slow queries, locking issues (including historical data, users & PIDs involved, etc) , and recompiles. The reports will allow the user to drill down into issues to assist in troubleshooting. I/O Performance Benefits of Compression In addition to the storage cost savings we expect that for I/O bound loads one could see a performance improvement of 15-20% as a result of data compression. For CPU bound workloads there could be a net performance hit as a result of the extra computation. Resource Governor Details The Resource Governor imposes resource consumption bounds on users, queries, and applications, limiting the resources consumed. It also provides query progress monitoring. The initial release of the resource governor in Katmai will govern CPU bandwidth, degree of parallelism (DOP), timeout waits, execution time, blocking time and idle time. If resource limits are exceeded the system can be configured to either trigger and event or terminate the offending process. Query Plan Locking In Katmai we will enable greater query performance stability and predictability by providing functionality to lock down query plans so that, to the maximum extent possible for correctness, the query plans survive server restart, server upgrade, metadata changes etc. 

20 Management by Intent Today Tomorrow From Managing by scripts
By default SQL Server 2005 turns off sensitive features e.g. CLR, Database Mail and OLE Automation To enable CLR and Database Mail the DBA must either: Use Surface Area Configurator (SAC) tool to explicitly enable these features OR Use T-SQL script to do so To monitor compliance the DBA will manually run SAC or her script regularly Tomorrow To Management by Policies In Katmai, Declarative Management Framework (DMF) will offer easy configuration, automation and enforcement To enable CLR and Database Mail with DMF, the DBA will simply Define a policy to enable these features From Management Studio simply run the policy Compliance checking: DMF will automatically enforce the policy based on a schedule OR it will check once a user changes the configuration Reporting: DMF reports policy violation each time it occurs Can run on multiple servers automatically

21 Advanced Performance Analysis
Extensible Data Collector Katmai will collect performance data e.g. memory usage, disk usage, etc User can also define other sets of events for tracking Performance Data Warehouse The Performance data warehouse will store deep data on SQL Server’s performance including query performance and locking issues The data can be analyzed to offer deep insights on SQL Server’s performance Rich Performance Reports Historical data on database performance will be displayed in rich reports Reports will allow drill downs for root cause analysis

22 Administratives… PASS – Professional Association for SQL Server
„Die“ SQL Server Nutzergruppe! Regelmäßige SQL Server Workshops und BootCamps Nutzergruppentreffen – von Usern für User SQL Jedis und SQL Rookies – jeder ist willkommen

23 Ressourcen SQL Server http://www.microsoft.com/sql
MSDN AA für Informatik-Studenten! Inside SQL Server Buch-Reihe Data Mining with Microsoft SQL Server 2005 (Tang, MacLennan) Microsoft Certified Professional, Technology Specialist, IT Professional, …

24 Microsoft Student Program
Friedrich-Schiller-Universität Jena Fakultät für Mathematik und Informatik

25 MSDN - Academic Alliance
Microsoft Software für Euch kostenlos!!! Betriebssysteme (Vista, XP, 2003, …) SQL Server 2005 Visual Studio 2005 Office Visio, Project, Access, InfoPath Euer Ansprechpartner: Dr. Günter Schorr (EAP Raum 3416) Voraussetzung: Student der Fakultät für Mathematik und Informatik

26 Veranstaltungen an der FSU Jena
ASP.NET 2.0 Workshop März 2007 Mai 2007 … weitere Veranstaltungen in Planung! Ankündigung unter:

27 Microsoft Student Partner an der FSU Jena
Stefan Kontschinsky (Dipl. Informatik) Auch Student Partner werden:

28 Fragen


30 Was ist neu am SQL Server 2005
.NET Framework Common Language Runtime Integration User-defined Aggregates User-defined Data Types User-defined Functions SQL Server .NET Data Provider Extended Triggers Data Types Managed SQL Types New XML Datatype SQL Server Engine New Message Service Broker HTTP Support (Native HTTP) Database Tuning Advisor Multiple Active Result Sets Persisted Computed Columns Queuing Support Snapshot Isolation Level Scale Up Partitioning VIA support NUMA support Database Failure and Redundancy Fail-over Clustering (up to 8 node) Enhanced Multi-instance Support Database Mirroring Database Viewpoints XML XQUERY Support (Server & Mid Tier) XML Data Manipulation Language FOR XML Enhancements XML Schema (XSD) Support MSXML 6.0 (Native) .Net XML Framework Notification Services & SQL Server CE Database Maintenance Backup and Restore Enhancements Checksum Integrity Checks Dedicated Administrator Connection Dynamic AWE Fast Recovery Highly-available Upgrade Online Index Operations Online Restore Parallel DBCC Parallel Index Operations Management Tools New Management Studio MDX Query Editor Version Control Support XML/A SQLCMD Command Line Tool Performance Tuning Profiler Enhancements Profiling Analysis Services Exportable Showplan Exportable Deadlock Traces Full-text Search Indexing of XML Datatype MDAC Side by Side installation Microsoft Installer base setup Support for Active Directory Deployment SQL Client .NET Data Provider Server Cursor Support Asynch Security All Permissions Grantable Fine Grain Administration Rights Separation of Users and Schema Replication Auto-tuning Replication Agents Oracle Publication Improved Blob Change Tracking OLAP and Data Mining Analysis Management Objects Windows Integrated Backup and Restore Web Service/XML for Analysis DTS and DM Integration New Data Mining Algorithms Auto Packaging and Deployment Data Transformation Services New Architecture (DTR + DTP) Complex Control Flows Control Flow Debugging For Each Enumerations Property Mappings Full Data Flow Designer Full DTS Control Flow Designer Graphical Presentation of Pkg Execution Immediate Mode and Project Mode Package (Advanced) Deployment Tools Custom Tasks and Transformations Reporting Services Multiple Output Formats Parameters (Static, Dynamic, Hierarchical) Bulk Delivery of Personalized Content Support Multiple Data Sources STS (Web Parts, Doc Libraries) Visual Design Tool Charting, Sorting, Filtering, Drill-Through Scheduling, Caching Complete Scripting Engine Scale Out architecture Open XML Report Definition

31 Transparent Data Encryption External Key Management Data Auditing
Pluggable CPU Transparent Failover for Database Mirroring Declarative Management Framework Server Group Management Streamlined Installation Enterprise System Management Performance Data Collection System Analysis Data Compression Query Optimization Modes Resource Governor Entity Data Model LINQ Visual Entity Designer Entity Aware Adapters SQL Server Change Tracking Synchronized Programming Model Visual Studio Support SQL Server Conflict Detection FILESTREAM data type Integrated Full Text Search Sparse Columns Large User Defined Types Date/Time Data Type LOCATION data type SPATIAL data type Virtual Earth Integration Partitioned Table Parallelism Query Optimizations Persistent Lookups Change Data Capture Backup Compression MERGE SQL Statement Data Profiling Star Join Enterprise Reporting Engine Internet Report Deployment Block Computations Scale out Analysis BI Platform Management Export to Word and Excel Author reports in Word and Excel Report Builder Enhancements TABLIX Rich Formatted Data Personalized Perspectives … and many more The point of this slide is to show that Katmai is a big release and it shouldn’t be considered just a dot release.

Herunterladen ppt "Trigger und Event Notifications im SQL Server 2005"

Ähnliche Präsentationen