Search This Blog


SQL 2012 Always On Status Report (SQL Replication)


To use this script just copy, paste and execute. Please test this script on you development system.

Output of this script will display information on the status of the SQL 2012 Always On replication.
--  Always On Status Report
--
-- This script will show the status of the Alway On replication status

SELECT DISTINCT
primary_replica as 'Primary Server',
[endpoint_url] as 'End Point URL',
primary_recovery_health_desc as 'Primary Server Health Status',
secondary_recovery_health_desc as 'Secondary Server Health Status',
operational_state_desc as 'Operational State',
connected_state_desc as 'Connection State',
recovery_health_desc as 'Recovery Health',
synchronization_state_desc as 'Synchronization State',
database_state_desc as 'Database State',
JOIN_state_desc as 'Join State',
suspend_reason_desc as 'Suspended Reason',
availability_mode_desc as 'Availability Mode',
failover_mode_desc as 'Failover Mode',
primary_role_allow_connections_desc as 'Primary Connections Allowed',
secondary_role_allow_connections_desc as 'Secondary Connections Allowed',
create_date as 'Date Created',
modify_date as 'Date Modified',
[backup_priority] as 'Backup Priority',
role_desc as 'Role Type',
last_connect_error_description as 'Last Connection Error',
last_connect_error_timestamp as 'Last Connection Error Time',
last_sent_time as 'Last Data Send Time',
last_received_time as 'Last Data Recieved TIme',
last_hardened_time as 'Last Hardened Time',
last_redone_time as 'Last Redone Time',
log_send_queue_size as 'Log Send Queue Size',
log_send_rate as 'Log Send Rate',
redo_queue_size as 'Redo Queue Size',
redo_rate as 'Rate of Redo',
filestream_send_rate as 'Filestream Send Rate',
last_commit_time as ' Last Commit Time',
low_water_mark_for_ghosts as 'Low Water Mark for Ghosts'
FROM sys.dm_hadr_availability_group_states

JOIN sys.availability_replicas
ON sys.dm_hadr_availability_group_states.group_id =  sys.availability_replicas.group_id

JOIN sys.dm_hadr_availability_replica_cluster_states
ON sys.dm_hadr_availability_group_states.group_id =  sys.dm_hadr_availability_replica_cluster_states.group_id

JOIN sys.dm_hadr_availability_replica_states
ON sys.dm_hadr_availability_group_states.group_id =  sys.dm_hadr_availability_replica_states.group_id

JOIN sys.dm_hadr_database_replica_states
ON sys.dm_hadr_availability_group_states.group_id =  sys.dm_hadr_database_replica_states.group_id

WHERE operational_state_desc IS NOT NULL
AND database_state_desc IS NOT NULL
ORDER BY [endpoint_url] DESC

-- Testing section
/*
-- Suspend replication from primary
ALTER DATABASE [AdventureWorksLT2008] SET HADR SUSPEND

-- Resume replication from secondary
ALTER DATABASE [AdventureWorksLT2008] SET HADR RESUME

-- Force a manual failover of replication with data loss. MUST EXECUTE ON SECONDARY SQL SERVER
ALTER AVAILABILITY GROUP [AG-AdventureWorksLT2008] FORCE_FAILOVER_ALLOW_DATA_LOSS;

-- Force a manual failover of replication with NO data loss MUST EXECUTE ON SECONDARY SQL SERVER
--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.
--Connect VDV1OPS03

ALTER AVAILABILITY GROUP [AG-AdventureWorksLT2008] FAILOVER;
GO

--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.
--:Connect OPSDBSRV

ALTER AVAILABILITY GROUP [AG-AdventureWorksLT2008] FAILOVER;
GO

*/

MS SQL Server 2005 - failover cluster Installation

Please read prerequisites for MS SQL Server 2005 failover cluster installation by clicking here before you proceed further.

Following video illustrates Cluster Group resource creation in order to setup MS SQL Server 2005:
Following video illustrates MS SQL Server 2005 Installation on a two node cluster:
For step by step instructions read through the information below.

SQL Server 2005 Enterprise Edition setup


1. Insert the SQL Server 2005 installation CD:
SQL Server setup will autorun. If setup doesn’t start, double click the autorun file in the root of the SQL Server CD 


2. Open File Security Warning
Click Run


3. End User License
Select “I accept the licensing…”, Click Next


4. Installing Prerequisites
Depending on what is already installed, you could also see ‘.NET Framework 2.0’.
Click Install


Click Next


5. System Check


6.Welcome Screen
Click Next


7. System Check - Success
Click Next


8. Installation



Cluster installation
For a cluster versus a standalone installation, you have to check the ‘Create a SQL Server failover cluster’ and Click Next 


9. Advance - Feature Selection
Click Next

10. Instance Name - select 'Default Instance'
Click Next


11. Cluster Only
Virtual Server Name
Enter the Virtual SQL Server name: 
Click Next


12. Enter IP address:
Click Add & Click Next


13. Cluster Only - Group Selection
Select the group used for this SQL installation:
Enter in ‘Data Files’ only the drive letter: *** (ex: E:\)


14. Node Configuration
Select all the nodes that will be owner of the SQL instance.
Click Add, to move them under ‘Selected nodes’.
Click Next

15. Cluster Only - Remote Account
The account listed is the account you used to log on to the server.
Enter the password: ***
Click Next

16. Service account
Enter the information required for the service(s)
Username:
Password:
Domain: 
Click Next



17. Domain Groups
Standalone Only
When installing SQL on a standalone server, the groups required for the SQL installation, will be automatically created locally by the SQL installation program i.e. there is nothing to do here for a standalone installation.

Cluster Only
When installing SQL on a cluster, the groups required for the SQL installation need to be created in Active Directory and entered manually during the installation.


You can use the same AD group for all the services of a SQL instance or specifiy indvidual group for each service. 
Enter the group name for :
SQL Server: 
SQL Server Agent: 

Full-Text Search:
Click Next



18. Authentication mode
Choose Windows Authentication or Mixed
Click Next



19. Collation Settings 
Click Next


20. Usage Report
Click Next


21. Ready to Install
Click Install


AND...NOW... PLEASE BE PATIENT - A LOT OF PATIENCE.


Finish!


Open cluster administrator to verify that SQL was installed in the right cluster group and on the right drive. Resources include: SQL Server, SQL Server Agent, SQL IP Address, SQL Server Fulltext, SQL Network Name, Etc

Congratulations! SQL Server 2005 failover cluster setup is complete.


Read essential steps to be taken post installation of MS SQL Server. Click here for details.

Also check out MS SQL Server 2008 cluster installation guide Click here.

Prerequisites - Microsoft SQL Server 2005 failover cluster install



Microsoft SQL Server requires to communicate over a firewall. The default SQL Server port is 1433, and client ports are assigned a random value between 1024 and 5000

Clients accessing the server will need to be configured to use this port, and any firewall in between the client and the server will need to allow this traffic.

AD service account for the SQL Server service

The AD service account used to start the SQL Server service is NOT a member of the local administrator group. Applies to both installation of a SQL default instance or a SQL named instances.

The AD group is not required for a standalone installation but is mandatory for a cluster installation. For a standalone installation, the installation program will create a local group on the server to be used by SQL.


To read more about Active Directory Objects and Local Policies for Micorsoft Cluster Service and SQL Server failover cluster click here.

Enabling physical address extentions (PAE) and /3GB:

Follow the steps below:
Locate boot.ini file in the c:\ partition.
Remove Read-Only and Hidden attributes.
Execute at the command prompt: attrib –r –s –h c:\boot.ini
Open the Boot.ini file with the Notepad text editor. To add the /PAE /3GB parameters to the ARC path, add the /PAE and /3GB switches like in this example:
multi(0)disk(0)rdisk(0)partition(2)\WINNT="Windows 2003 Server Enterprise Edition" /PAE /3GB
On the File menu, click Save.
Restore the Read-Only attribute to the Boot.ini file.
Execute at the command prompt: C:\>attrib +r +s +h c:\boot.ini
The server needs to be restarted in order for the changes to take effect.

IMPORTANT: "/3GB" should not be used if the SQL Server machine has more than 16 GB of RAM

Confirm all the SQL LUN have been set to 64kb per cluster

This section describes the steps, required to format disks, used for SQL Server database data and log files.
SAN disks used for SQL data, log and backup partitions should be formatted with 64 KB per cluster and 64K offset.
Steps to do:
There must be no partition on the disk. If there is a partition, it needs to be deleted.
Virtual Disk Service: Enable the service, set it to Manual and start the service
Open a command prompt and type
Diskpart if windows 2003 or Diskpar is windows 2000
Type “Select disk number” where number is the actual number of the disk and press enter
Type “create partition primary align = 64” and press enter
If you receive a successful disk creation, continue
If a failure, proceed to the resolution section. The failure can occur on the cluster.
Close the Command prompt
Go to “Start>Programs>Administrative Tools” select “Computer Management” & Select “Disk Management”
Find the newly presented drive by identifying the disk number and size.
Right click and select format
In the format window: Set the “name” and set the “allocation unit size” to 64k
Do not select “perform a quick format”
Virtual Disk Service: Stop the service and set it to Disabled.

Latest Windows Service Pack Installed

Click here to read instructions on how to install Windows Server 2003 SP2.




MSDTC Cluster Configuration

MSDTC service needs to be configured ‘Network’. If it is a clustered installation, it also needs to be clustered. Click hereto read instructions on how to configure MSDTC for cluster configuration.



Cluster Only – Validation

Ensure both COM+ services are running on ALL nodes of the cluster



Check the cluster groups
  • Validate the cluster name and IP address.
  • Check if the SQL Virtual Name and IP address is in use.


Services
  • Ensure MSDTC is clustered and running, it is required for a SQL cluster installation.
  • Ensure the Task Scheduler service is running on all the nodes of the cluster.
  • Ensure both COM+ services are running on ALL nodes of the cluster
All set? Go right ahead with MS SQL Server 2005 installation. All the best. Click here for video and instructions.