Google Custom Search

Thursday, June 26, 2008

Configuring Peer-to-Peer replication Using TSQL:

This article brings you the easiest way to configure P2P replication using TSQL. Also I assume that the database has been initialized in all nodes participating in the replication.

1. Configure Distributor:
This script needs to be executed against all servers that participates in the replication.

/* Check if distributor database already exists*/
declare @svrname as sysname
select @svrname = @@servername
declare @cnt int
Select @cnt=count(*) from sys.databases where name = 'distribution'
If @cnt>0
begin
Print 'distributor already exists'
End
Else
Begin
Exec sp_adddistributor @distributor=@svrname
Exec sp_adddistributiondb @database='distribution',@security_mode=1
End

2. Create Publication and Subscriber:
This script needs to be executed against all the publisher databases involved in the P2P replication instances. There are few parameters that you might need to change in this script which will be noted so edit the parameters before executing.

/*Add the publisher*/
declare @svrname as sysname
select @svrname = @@servername
/* Add the publisher server now*/

exec sp_adddistpublisher @publisher =@svrname,
@distribution_db = N'distribution',
@security_mode = 1,
@publisher_type = N'MSSQLSERVER'

/* Enable the database for publication*/
declare @dbname varchar(30)
declare @dbcheck sql_variant

/* Check if the database is set as publication*/
/*Set you database name*/
select @dbname = '------' /***** Set Your Database Name Here**************/
select @dbcheck = databasepropertyex(@dbname,'ispublished')
select @dbcheck
if @dbcheck = 0
begin
print 'Database not set as Publisher. Setting as Publisher'
exec sp_replicationdboption @dbname=@dbname,
@optname='publish',
@value='true'
end
else
begin
print 'Database already set as Publisher'
end

/* Add the Publication now*/
declare @pubname varchar(300)
select @pubname = '---------' /********Add Publication Name Here***********/
/*Execute this step against the database which you need to set as publication*/
exec sp_addpublication @publication=@pubname,
@restricted='false',
@sync_method='native',
@repl_freq='continuous',
@allow_push='true',
@allow_pull='true',
@immediate_sync='true',
@allow_sync_tran='false',
@autogen_sync_procs='false',
@retention=60,
@independent_agent='true',
@enabled_for_p2p='true',
@status='active',
@allow_initialize_from_backup='true'
Go

/* Add articles for this Publication*/
/**********This step needs to be executed for each article in the publication***************/
declare @artname varchar(300)
declare @artins varchar(300)
declare @artdel varchar(300)
declare @artupd varchar(300)
select @artname = '-------'/**********Add Article Name Here***************/
select @artins = 'CALL [sp_MSins_'+@artname+']'
select @artdel = 'CALL [sp_MSdel_'+@artname+']'
select @artupd = 'CALL [sp_MSupd_'+@artname+']'

/*Execute this step against the database which you need to set as publication*/
declare @pubname varchar(300)
select @pubname = '----------'/***********Add your publication name here*************/
exec sp_addarticle @publication = @pubname,
@article = @artname,
@source_owner = N'dbo',
@source_object = @artname,
@type = N'logbased',
@description = N'',
@creation_script = N'',
@pre_creation_cmd = N'none',
@schema_option = 0x00000000000044F7,
@identityrangemanagementoption = N'manual',
@destination_table = @artname,
@destination_owner = N'dbo',
@status = 16,
@vertical_partition = N'false',
@ins_cmd = @artins,
@del_cmd = @artdel,
@upd_cmd = @artupd
Go

/*Add the Subscriber*/
declare @pubname varchar(300)
select @pubname = '----------'/***********Add your publication name here*************/
declare @dbname varchar(30)
select @dbname = '----------'/***********Add your Subscriber database name here*************/
declare @subname varchar(30)
select @subname = '----------'/***********Add your Subscriber Server name here*************/

exec sp_addsubscription @publication = @pubname,
@subscriber = @subname,
@destination_db = @dbname,
@sync_type = 'replication support only'
Go

/*Add the Subscriber Agents*/
declare @pubname varchar(300)
select @pubname = '----------'/***********Add your publication name here*************/
declare @dbname varchar(30)
select @dbname = '----------'/***********Add your Subscriber database name here*************/
declare @subname varchar(30)
select @subname = '----------'/***********Add your Subscriber Server name here*************/

exec sys.sp_addpushsubscription_agent
@publication = @pubname,
@subscriber = @subname,
@subscriber_db = @dbname,
@subscriber_security_mode = 1,
@frequency_type = 64,
@frequency_interval = 1,
@frequency_relative_interval = 1,
@frequency_recurrence_factor = 0,
@frequency_subday = 4,
@frequency_subday_interval = 5,
@active_start_time_of_day = 0,
@active_end_time_of_day = 235959,
@active_start_date = 0,
@active_end_date = 0,
@dts_package_location = N'Distributor'

Saturday, June 14, 2008

Will Update Shortly

Hey Guys,

I have come up with lot of articles on Replication, Performance, Architecture and High availability solutions of SQL Server 2005. I will be posting them shortly. Just to keep you updated that there will be lot of articles sooner in this blog.

Monday, May 5, 2008

SQL Server JOB deletion ERROR

I have found in discussion forums regarding the error given below when you try to delete a job that was part of maintenance.

The DELETE statement conflicted with the REFERENCE constraint "FK_subplan_job_id". The conflict occurred in database "msdb", table "dbo.sysmaintplan_subplans", column 'job_id'.
The statement has been terminated. (.Net SqlClient Data Provider)



This error is caused not in all systems in some and it depends. I have tried to replicate the error but it would be always unsuccessful. Anyways the solution to can be handled with the script given below.

SCRIPT

declare @jobname varchar(100)

select @jobname='PASS YOUR NAME OF THE JOB'

delete from msdb.dbo.sysmaintplan_log
where plan_id in(
select plan_id from msdb..sysmaintplan_subplans
where job_id in(
select job_id from sysjobs where name =@jobname))

delete from sysmaintplan_subplans
where job_id in(
select job_id from sysjobs where name =@jobname)

Then you can delete your job. Hope this post helps you.

Wednesday, April 9, 2008

Testing Cluster Configuration:

Most people never like to test what they can done. Assuming that things have been done perfectly which results in a situtation of panic sometimes. So i thought that i could let you all know the steps to check after completing a cluster configuration.

1. Check if the Nodes are available and able to ping each other.
2. Check if you are able to reach the nodes from the client machines both with the names and IP address.
3. Try validating a failover and check if it failsover successfully. This can be done as given in the topic Validation Failover.
4. Check if all the disks are seen in the cluster group. This is the place most DBAs could go wrong. They might not have added the disks as dependencies in their configuration. To check and add disks as dependecies look on the topic Disk resources in cluster.
5. Verify error log and event viewer log.
6. Try connecting to the SQL Server management studio to check if it succedds.

Validating Failover:

1. Start Cluster Administrator.
2. In the left pane, expand Groups, right-click a cluster group, select the Move Group option, and finally select a node to move the resource group.
If the failover is functioning properly, the owner of the resources will change to the new node name.
3. Repeat step 2 to move the resource to all other nodes of the server cluster.

Disk resources in cluster:

1. Start Cluster Administrator.
2. Select the group that contains the disk resource you want to use with SQL Server Services.
3. Make sure the disk resource is owned by the node you are currently logged on to..
4. In the right pane, select the disk resource, right-click, select Change Group, and then select
the group that contains your SQL Server.
5. When prompted to confirm the move action, click Yes.
6. Once again, you will be prompted to confirm the disk resource move to the other group, Click Yes.
The disk will now be moved to the target group.
7. Take the SQL Server resource offline.
8. Right-click the SQL Server resource, and select Properties; alternatively,
double-click the resource. Select the Dependencies tab. Click Modify.
9. In the Modify Dependencies dialog box, select the new disk resource listed under Available
Resources. And move that resource to Dependencies;
10. The Dependencies tab will now show that the disk is added as a dependency of the
resource. Click Apply. Click OK.
11. Bring the offline resources online. SQL Server will be able to use the newly added disk.

Tuesday, April 8, 2008

Renaming a Failover Clustering Instance of SQL Server

Can you rename the SQL virtual name in a Cluster? The answer for this in SQL Server 2005 is abviously Yes. New to SQL Server 2005 is the ability to rename a clustered instance of SQL Server without having to uninstall and reinstall it.

Follow these steps:

1. Start Cluster Administrator.
2. Select the resource group that has the SQL Server resources.
3. Take the SQL Server service offline.
4. Right-click the SQL Server Network Name resource, and select Properties; alternatively, double-click the resource.
5. Select the Parameters tab of the resource’s properties page
6. Enter the new name of the failover clustering resource and click Apply.
7. Select the General tab. Change the name of the resource to include the new name you configured
in step 6. Click OK.
8. Bring the SQL Server resources online.
9. Ping the new name of the SQL Server failover clustering instance. If the name cannot be
resolved, you will have to flush your DNS cache by issuing these three commands in succession:
ipconfig /flushdns
ipconfig /registerdns
and nbtstat –RR.
10. Start SQL Server Management Studio, and connect with the new instance name. If this succeeds,
the change has been done successfully.
11. For a final verification, you can also run a SELECT @@SERVERNAME query, which should reflect the name change.

Note:
You can only rename the SQL Server virtual Name and not the instance name and this operation involves some down time.

Monday, April 7, 2008

Getting Information on SQL Server Clustering

SQL Server 2005 aruably gives the best resources to see if the instance is clustered or not. And if so, what are the properties of the cluster. The DMVs that are related to the Cluster can be used for this. These DMVs are very useful for a new DBA joining a company who can easily find out the environment and the disk details without needing for a proper document on place.

To check if the instance is clustered:

select SERVERPROPERTY('IsClustered')

If this returns 1 then your environment is clustered.

To check the computer name of the node owning the cluster

Select SERVERPROPERTY('ComputerNamePhysicalNetBIOS')

The following DMVs would can be used for the cluster information.

sys.dm_os_cluster_nodes
This will return a row for each node in the failover cluster instance configuration. If the current instance is a failover clustered instance, it returns a list of nodes on which this failover cluster instance (formerly ‘virtual server’) has been defined. If the current server instance is not a failover clustered instance, it returns an empty rowset.

Sample Output:

SQLCLUSN1
SQLCLUSN2

sys.dm_io_cluster_shared_drives

This will return the information such as drive name of each of the shared drives if the current server instance is a clustered server. If the current server instance is not a clustered instance it returns an empty rowset.

Sample Output:

D
L
T
X

Saturday, February 23, 2008

SQL 2005 Edition Comparision

SQL Server 2005 comes with different editions with each having features that are either available in the other or not. This document lists the comparison of the features available between the different editions
http://www.sql-articles.com/index.php?page=articles/edcomp.htm

Isolation Levels

This article provides an easy-to-understand view of what ‘Isolation Levels’ really mean and when to use which level. ‘Isolation Level’ is a setting that decides how data which is a part of an ongoing transaction is made visible to other transactions.

http://www.sql-articles.com/index.php?page=articles/isolevel.htm

Locks & Locking Hints

Locking, Locks and Deadlocks are words that a developer/DBA does not want to hear in real life but still there are possibilities that we hear them because of some bad code written. This article takes you on to the type of locks available in SQL server and the ways of avoiding them using the hints available. Before getting into know the types of locks and the hints available, let us see what is meant by a lock and a deadlock.

http://www.sql-articles.com/index.php?page=articles/lhints.htm

Moving System Databases

There are lots of articles, Links and sites that describe how to move system databases from the SQL default location to the location described by the DBA but still lot of users find difficult while moving them and land up in trouble. So I thought that I would just do a graphical way of moving the databases so that the users can use the same and enjoy the task.

http://www.sql-articles.com/index.php?page=articles/msysdb.htm

Upgrading to SQL Server 2005

As we all know that Microsoft has released SQL Server 2005 sometime back and is planning to release the next version KATMAI before end of 2008. Also it has announced the end of life cycle support for SQL Server 2000. It’s high time that we start with upgrading our instances with SQL Server 2005 and upgrade before the life cycles support ends.

http://www.sql-articles.com/index.php?page=articles/usql.htm

Query Plans & Planguides

Most developer DBAs have tough time tuning TSQL part of the database and application. And most people leave in middle of it either frustrated or can’t go beyond that. Here is a simple look on how to use the query hints and plan guides to tune the TSQL part of your database and application.

http://www.sql-articles.com/index.php?page=articles/query_plans.html

Memory Management in SQL Server

I have heard people asking me how SQL Server manages memory. The answer to this was very difficult with SQL Server earlier versions. And with SQL Server 2005 it has been simpler to explain and understand. SQL Server by default installation manages memory dynamically and has settings that it can well negotiate with the operating system for the need of memory. Let us look into the depth of the SQL Server memory management.

Read more of this on http://www.sql-articles.com/index.php?page=articles/memory_management.html

Check Identity

This will list out identity columns in a Database. This is compatible to SQL 2005 only.
http://www.sql-articles.com/index.php?page=Scripts/check_idenity.php

Connection Property

This script will list out the current connection properties on SQL 2005.

http://www.sql-articles.com/index.php?page=Scripts/conn_prop.php


Database Details

This will list out the Database properties of your database in sql server. This is compatible to SQL 2000 and 2005. Before you use the script make sure you have given the databasename for the parameter @dbname.

http://www.sql-articles.com/index.php?page=Scripts/db_details.php

Index Details for Tables

This script will list out the details of the indexes in a table.This is compatible to SQL 2000 and 2005.
http://www.sql-articles.com/index.php?page=Scripts/index_details.php

Permission List

This script gives a detailed information about permission for users in a database. This output lists Object name, Schema name, user name and permission. This is compatible only to SQL 2000.
http://www.sql-articles.com/index.php?page=Scripts/permission_list.php

Permission List SQL 2005

This script gives a detailed information about permission for users in a database. This output lists Object name, Schema name, user name and permission. This is compatible only to SQL 2005.

http://www.sql-articles.com/index.php?page=Scripts/permission_list_2005.php

Scripting User level Permission - SQL2000

This script gives a out script that can be used to script out the exising user permissions in a database.This is compatible only to SQL 2000.Don't forget to change the database name in paramert @dbname before using the script.

http://www.sql-articles.com/index.php?page=Scripts/scrip_user_00.php