programming4us
programming4us
DATABASE

SQL Server 2012 : Defining Policies (part 3) - Creating Policies

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/24/2014 4:30:12 AM

Creating Policies

If the facet property is the fact and the condition the brain, the policy is the muscle. Policies define how and where the condition is applied and enforced.

You can create a new policy using the New Policy menu item in Object Explorer's Management → Policy Management → Policies and then selecting the New Policy option from the context menu. Alternatively, you can go to the File menu, browse to the New submenu, and then select Policy from the list. The Create New Policy dialog, as shown in Figure 6, has a general page and a description page.

Figure 6 Viewing a Policy. This policy enforces the AutoShrink condition for every database on demand.

20.6

You can open an existing policy by double-clicking the policy or by using the Property command in its context menu.

The general page has four key selections. The first is the condition; a policy may check only a single condition. The ellipsis opens the condition.

The second selection, targets, defines which objects will be tested. The options vary depending on the type of object the facets apply to.

Evaluation mode is the third key selection. There are four Evaluation modes for a policy:

  • On Demand: The policy is evaluated only manually. There's no schedule, automatic testing, or enforcement.
  • On Schedule: The policy is evaluated and any violations are logged but not corrected.
  • On Change Log Only: The policy is evaluated when the facet is changed, and violations are logged.
  • On Change Prevent: The policy is evaluated when the facet is changed, and violations are rolled back. This action rolls back a violation only after the action has occurred; meaning a large transaction that violates a policy may take a long time to roll back changes.

Every facet may be set to On Demand or On Schedule, but On Change is limited. PBM relies on DDL eventing to do CheckOnChange, and not all objects support DDL eventing. The following query reports which Execution modes are available for which facets:

SELECT name as Facet, 
Max(CASE WHEN execution_mode & 0 = 0 Then 1 else 0 End)
as ‘On Demand',
Max(CASE WHEN execution_mode & 4 = 4 Then 1 else 0 End)
as ‘On Schedule',
Max(CASE WHEN execution_mode & 2 = 2 Then 1 else 0 End)
as ‘On Change Log Only',
Max(CASE WHEN execution_mode & 1 = 1 Then 1 else 0 End)
as ‘On Change Prevent'
FROM msdb.dbo.syspolicy_management_facets
GROUP BY name
ORDER BY name

Result is shown in Table 1:

Table 1 Facet Listing

c20tnt001 c20tnt001 c20tnt001 c20tnt001

The fourth key selection on the general page is Server Restriction. You can use this option to define the target servers based on criteria.

Caution
PBM generates DDL triggers that enforce the policy and roll back DDL operations that don't comply with the policy. Don't manually delete or edit these DDL triggers. Also, servers that use PBM must have nested triggers enabled.
PBM also generates agent jobs for policy automation. They shouldn't be deleted either.

To programmatically view the created policies, query the dbo.syspolicy_policies view in the MSDB database:

select * from msdb.dbo.syspolicy_policies

You can export policies to XML and import them using the Policy context menu.

Other  
  •  SQL Server 2012 : Validating Server Configuration (part 2) - Evaluate the Policy, Using the Central Management Server
  •  SQL Server 2012 : Validating Server Configuration (part 1) - The Need for a Policy, Create Policy on a Local Server
  •  SQL Server 2012 : Encryption (part 2) - Certificate-Based Encryption, Transparent Data Encryption
  •  SQL Server 2012 : Encryption (part 1) - Encryption Primer, Password-Based Encryption
  •  SQL Server 2012 : Auditing in SQL Server (part 3) - Database Audit Specification Object, User-Defined Audit Event
  •  SQL Server 2012 : Auditing in SQL Server (part 2) - Server Audit Specification Object
  •  SQL Server 2012 : Auditing in SQL Server (part 1) - Auditing Objects, Server Audit Object
  •  SQL Server 2012 : Reordering Nodes within the Hierarchy - The GetReparentedValue Method,Transplanting Subtrees
  •  SQL Server 2012 : Querying Hierarchical Tables - The IsDescendantOf Method
  •  Protecting SQL Server Data : Obfuscation Methods (part 4) - Truncation,Encoding, Aggregation
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us