Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

Monday, March 26, 2012

Finding and Killing Process's with Transact

Is it possible to create some Transact SQL which will find all the process's
locking a database and then kill those process's (I want to do this as a
precursor to running a database restore, my problem is that sometimes
someone has the database locked running a query and the restore fails as a
result).before restore:
alter database <db> set SINGLE_USER with ROLLBACK AFTER <seconds>
(to view all connected users on db use
select * from sysprocesses where dbid=db_id('db')
kill users with kill <spid> )
"quiglepops" wrote:

> Is it possible to create some Transact SQL which will find all the process
's
> locking a database and then kill those process's (I want to do this as a
> precursor to running a database restore, my problem is that sometimes
> someone has the database locked running a query and the restore fails as a
> result).
>
>|||Here's a script I use... replace <your db> <password> and <server> with your
info.
Let me know if it's useful. Note that it shells out using xp_cmdshell so
you'll need
symin rights.
use master
go
declare @.dbname sysname, @.spid int, @.sqlstring varchar(8000)
set @.dbname = <your db>
Create Table #spid
(
SPID int,
Status varchar(130),
Login varchar(50),
HostName varchar(50),
BlkBy char(5),
DBName varchar(30),
Command varchar(16),
CPUTime int,
DiskIO bigint,
LastBatch varchar(20),
ProgramName varchar(128),
SPID2 int
)
Insert Into #spid
Exec master..sp_who2
Delete From #spid
Where dbname <> @.dbname
Or dbname is null
/************************/
/* Kill all connections */
/************************/
While Exists (Select * From #spid)
Begin
Select @.spid = SPID
From #spid
If @.spid is null
break
-- Clean up the table so it's not processed again
Delete From #spid
Where spid = @.spid
Set @.sqlstring = 'isql /Usa /n /dmaster /Q"kill ' + cast(@.spid as varchar) +
'" /h-1 /P<password> /S<server>'
Exec master..xp_cmdshell @.sqlstring
End
"quiglepops" <dave_quigley@.hotmail.com> wrote in message
news:uTsbBmuWFHA.1508@.tk2msftngp13.phx.gbl...
> Is it possible to create some Transact SQL which will find all the
process's
> locking a database and then kill those process's (I want to do this as a
> precursor to running a database restore, my problem is that sometimes
> someone has the database locked running a query and the restore fails as a
> result).
>|||In SQL Server 2000, you do not have to enumerate and kill all connections
individually. Instead, you can issue the following which will set the
database to single user mode. The option "with rollback immediate" should
automatically terminate all connections and rollback active transactions.
ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
"quiglepops" <dave_quigley@.hotmail.com> wrote in message
news:uTsbBmuWFHA.1508@.tk2msftngp13.phx.gbl...
> Is it possible to create some Transact SQL which will find all the
process's
> locking a database and then kill those process's (I want to do this as a
> precursor to running a database restore, my problem is that sometimes
> someone has the database locked running a query and the restore fails as a
> result).
>|||Thanks for that.
Setting it to Single User mode sounds good, but will it do that when there
are users already in locking the database. Also, will that command on its
own do the job, without me having to find and kill the SPIDS ?
What do I then have to do after the restore to make it available to everyone
again ?
"Aleksandar Grbic" <AleksandarGrbic@.discussions.microsoft.com> wrote in
message news:72376937-9C88-4A0D-972C-558C687FC21F@.microsoft.com...
> before restore:
> alter database <db> set SINGLE_USER with ROLLBACK AFTER <seconds>
> (to view all connected users on db use
> select * from sysprocesses where dbid=db_id('db')
> kill users with kill <spid> )
>
> "quiglepops" wrote:
>
process's
a|||Yes, the IMMEDIATE option should automatically kill all processes (locked or
not). Now that I think about it, the option RESTRICTED_USER may be more
appropriate than SINGLE_USER. This will allow only users with DBO or SA
rights to subsequently connect.
Look up the ALTER DATABASE command in SQL Server Books Online for more
details. If you want, perform a test of this process on another
non-production database like Pubs or Northwind.
After the restore is complete, perform the same command, but with the option
MULTI_USER to allow multiple connections.
"quiglepops" <dave_quigley@.hotmail.com> wrote in message
news:uLQmG0uWFHA.4036@.TK2MSFTNGP10.phx.gbl...
> Thanks for that.
> Setting it to Single User mode sounds good, but will it do that when there
> are users already in locking the database. Also, will that command on its
> own do the job, without me having to find and kill the SPIDS ?
> What do I then have to do after the restore to make it available to
everyone
> again ?
>
> "Aleksandar Grbic" <AleksandarGrbic@.discussions.microsoft.com> wrote in
> message news:72376937-9C88-4A0D-972C-558C687FC21F@.microsoft.com...
> process's
a
as
> a
>|||Thanks for your help guys. The ALTER DATABASE command is perfect. The
scripts are also useful for some of my SQL 7 DB's, so thanks for your help
everyone.
"Armando Prato" <aprato@.REMOVEMEkronos.com> wrote in message
news:uxfiDyuWFHA.4036@.TK2MSFTNGP10.phx.gbl...
> Here's a script I use... replace <your db> <password> and <server> with
your
> info.
> Let me know if it's useful. Note that it shells out using xp_cmdshell so
> you'll need
> symin rights.
> use master
> go
> declare @.dbname sysname, @.spid int, @.sqlstring varchar(8000)
> set @.dbname = <your db>
> Create Table #spid
> (
> SPID int,
> Status varchar(130),
> Login varchar(50),
> HostName varchar(50),
> BlkBy char(5),
> DBName varchar(30),
> Command varchar(16),
> CPUTime int,
> DiskIO bigint,
> LastBatch varchar(20),
> ProgramName varchar(128),
> SPID2 int
> )
> Insert Into #spid
> Exec master..sp_who2
> Delete From #spid
> Where dbname <> @.dbname
> Or dbname is null
>
> /************************/
> /* Kill all connections */
> /************************/
> While Exists (Select * From #spid)
> Begin
> Select @.spid = SPID
> From #spid
> If @.spid is null
> break
> -- Clean up the table so it's not processed again
> Delete From #spid
> Where spid = @.spid
> Set @.sqlstring = 'isql /Usa /n /dmaster /Q"kill ' + cast(@.spid as varchar)
+
> '" /h-1 /P<password> /S<server>'
> Exec master..xp_cmdshell @.sqlstring
> End
>
>
> "quiglepops" <dave_quigley@.hotmail.com> wrote in message
> news:uTsbBmuWFHA.1508@.tk2msftngp13.phx.gbl...
> process's
a
>|||Actually another question. The ALTER DATABASE SET SINGLE_USER WITH ROLLBACK
IMMEDIATE
kills all connections and rolls back straight away.
I want to run this command in a job, then on success in the next step of the
job run the database restore command.
Would it be true to say that some particularly long transactions that would
take a long time to roll back would still be running when the restore
attempts to run,
thus causing a failure, or would it be the case that the job would wait for
the first step to complete (i.e. wait until all transactions, including long
running ones were complete, before proceeding to step 2 and restoring the DB
?
"quiglepops" <dave_quigley@.hotmail.com> wrote in message
news:ekVB5PvWFHA.3712@.TK2MSFTNGP09.phx.gbl...
> Thanks for your help guys. The ALTER DATABASE command is perfect. The
> scripts are also useful for some of my SQL 7 DB's, so thanks for your help
> everyone.
>
> "Armando Prato" <aprato@.REMOVEMEkronos.com> wrote in message
> news:uxfiDyuWFHA.4036@.TK2MSFTNGP10.phx.gbl...
> your
so
varchar)
> +
a
as
> a
>sql

Wednesday, March 21, 2012

Find the Data Bases which can not be Backed up are some resons

hi all.,
How can I find the Data Base which can't backed up for reasons
like Data Base is in the middle of the Restore before
i start Backup Process .
Regards.,
Sri
This probably isn't the best method to use but via Enterprise Manager
under Management you can view the maintenance plan history for the
backup plan and look for the red X by the database name that indicates
a failure for the operation against that database.
You might try selecting directly from the
msdb.dbo.sysdbmaintplan_history table if your plan logs to the
database.
Otherwise there should be log files in the LOG directory.
HTH -- Mark D Powell --
|||Hii Mark.,
Thanks for ur reply .
Can I Get the DataBase which couldn't be backuped using executing
Query or procedure .
I am new to Db management , hence pardon me if any mistakes .
Regards.,
Sridhar
Mark D Powell wrote:
> This probably isn't the best method to use but via Enterprise Manager
> under Management you can view the maintenance plan history for the
> backup plan and look for the red X by the database name that indicates
> a failure for the operation against that database.
> You might try selecting directly from the
> msdb.dbo.sysdbmaintplan_history table if your plan logs to the
> database.
> Otherwise there should be log files in the LOG directory.
> HTH -- Mark D Powell --

Find the Data Bases which can not be Backed up are some resons

hi all.,
How can I find the Data Base which can't backed up for reasons
like Data Base is in the middle of the Restore before
i start Backup Process .

Regards.,

SriThis probably isn't the best method to use but via Enterprise Manager
under Management you can view the maintenance plan history for the
backup plan and look for the red X by the database name that indicates
a failure for the operation against that database.

You might try selecting directly from the
msdb.dbo.sysdbmaintplan_history table if your plan logs to the
database.

Otherwise there should be log files in the LOG directory.

HTH -- Mark D Powell --|||Hii Mark.,

Thanks for ur reply .

Can I Get the DataBase which couldn't be backuped using executing
Query or procedure .

I am new to Db management , hence pardon me if any mistakes .

Regards.,

Sridhar

Mark D Powell wrote:
> This probably isn't the best method to use but via Enterprise Manager
> under Management you can view the maintenance plan history for the
> backup plan and look for the red X by the database name that indicates
> a failure for the operation against that database.
> You might try selecting directly from the
> msdb.dbo.sysdbmaintplan_history table if your plan logs to the
> database.
> Otherwise there should be log files in the LOG directory.
> HTH -- Mark D Powell --

Wednesday, March 7, 2012

Find In...Stored Procedures?

All:
Is there a way to do a "Find" across the text of a set of stored
procedures? (SQL Server 2000)
I am in the process of doing some code refactoring and have eliminated
a column in one of my tables. Now, I want to find all the stored
procedures that use the column name.
Is there a way to do this? Alternatives?
Many thanks,
JohnHow do I find a stored procedure containing <text>?
http://www.aspfaq.com/show.asp?id=2037
AMB
"jpuopolo@.mvisiontechnology.com" wrote:

> All:
> Is there a way to do a "Find" across the text of a set of stored
> procedures? (SQL Server 2000)
> I am in the process of doing some code refactoring and have eliminated
> a column in one of my tables. Now, I want to find all the stored
> procedures that use the column name.
> Is there a way to do this? Alternatives?
> Many thanks,
> John
>|||Look at the syscomments table; it contains the text for your stored
procedures and views.
SLECT *
FROM syscomments
WHERE text like '%[column name]%'
HTH,
Stu|||Stu:
Thanks - worked like a charm.
Best,
John|||Use dbname
go
SELECT OBJECT_NAME(ID) from syscomments
where TEXT like '%columnname%'
Thanks
Hari
SQL Server MVP
"Stu" <stuart.ainsworth@.gmail.com> wrote in message
news:1126359684.486000.4260@.g49g2000cwa.googlegroups.com...
> Look at the syscomments table; it contains the text for your stored
> procedures and views.
> SLECT *
> FROM syscomments
> WHERE text like '%[column name]%'
> HTH,
> Stu
>

Sunday, February 26, 2012

Find blocking process

Hi,
we're having a problem with SQL 2000 and Opta 2000 JDBC driver
where there is large update running and at the same time,
read is blocked for a while.
We're looking for a way to catch this blocking process
and if it last more than 10 minutes, then email or send out a message.
I know sp_lock returns all current locks
but how do you know which one is blocking other processes?

Thanks for your help in advance.neo (second714@.hotmail.com) writes:
> we're having a problem with SQL 2000 and Opta 2000 JDBC driver
> where there is large update running and at the same time,
> read is blocked for a while.
> We're looking for a way to catch this blocking process
> and if it last more than 10 minutes, then email or send out a message.
> I know sp_lock returns all current locks
> but how do you know which one is blocking other processes?

The simplest way is to use sp_who. If a process is blocked, you will
see a non-zero value in the Blk column. This is the spid of the blocker.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Friday, February 24, 2012

Find a name of an index in deadlock situation.

Hi
I have a deadlock occurring.
Using MSSQL 2005 current activity lock screens I can see one process is
waiting for a lock to be released on a Database object. with objectId =
1441294802092032 and type = KEY - so I know I have a lock on an Index
and what table the index belongs to,
But how can I find the name of the index that is blocked?
This was part of the default view in SQL2000 activity manager. I cannot
use object_name (1441294802092032 ).
Pain is cannot even export the details of the locks per process to a
file.
Yitzak
http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
"Yitzak" <terryshamir@.yahoo.co.uk> wrote in message
news:1164814916.178901.38620@.16g2000cwy.googlegrou ps.com...
> Hi
> I have a deadlock occurring.
> Using MSSQL 2005 current activity lock screens I can see one process is
> waiting for a lock to be released on a Database object. with objectId =
> 1441294802092032 and type = KEY - so I know I have a lock on an Index
> and what table the index belongs to,
> But how can I find the name of the index that is blocked?
> This was part of the default view in SQL2000 activity manager. I cannot
> use object_name (1441294802092032 ).
> Pain is cannot even export the details of the locks per process to a
> file.
>

Find a name of an index in deadlock situation.

Hi
I have a deadlock occurring.
Using MSSQL 2005 current activity lock screens I can see one process is
waiting for a lock to be released on a Database object. with objectId = 1441294802092032 and type = KEY - so I know I have a lock on an Index
and what table the index belongs to,
But how can I find the name of the index that is blocked'
This was part of the default view in SQL2000 activity manager. I cannot
use object_name (1441294802092032 ).
Pain is cannot even export the details of the locks per process to a
file.Yitzak
http://blogs.msdn.com/bartd/archive/2006/09/09/747119.aspx
"Yitzak" <terryshamir@.yahoo.co.uk> wrote in message
news:1164814916.178901.38620@.16g2000cwy.googlegroups.com...
> Hi
> I have a deadlock occurring.
> Using MSSQL 2005 current activity lock screens I can see one process is
> waiting for a lock to be released on a Database object. with objectId => 1441294802092032 and type = KEY - so I know I have a lock on an Index
> and what table the index belongs to,
> But how can I find the name of the index that is blocked'
> This was part of the default view in SQL2000 activity manager. I cannot
> use object_name (1441294802092032 ).
> Pain is cannot even export the details of the locks per process to a
> file.
>

Find a name of an index in deadlock situation.

Hi
I have a deadlock occurring.
Using MSSQL 2005 current activity lock screens I can see one process is
waiting for a lock to be released on a Database object. with objectId =
1441294802092032 and type = KEY - so I know I have a lock on an Index
and what table the index belongs to,
But how can I find the name of the index that is blocked'
This was part of the default view in SQL2000 activity manager. I cannot
use object_name (1441294802092032 ).
Pain is cannot even export the details of the locks per process to a
file.Yitzak
http://blogs.msdn.com/bartd/archive.../09/747119.aspx
"Yitzak" <terryshamir@.yahoo.co.uk> wrote in message
news:1164814916.178901.38620@.16g2000cwy.googlegroups.com...
> Hi
> I have a deadlock occurring.
> Using MSSQL 2005 current activity lock screens I can see one process is
> waiting for a lock to be released on a Database object. with objectId =
> 1441294802092032 and type = KEY - so I know I have a lock on an Index
> and what table the index belongs to,
> But how can I find the name of the index that is blocked'
> This was part of the default view in SQL2000 activity manager. I cannot
> use object_name (1441294802092032 ).
> Pain is cannot even export the details of the locks per process to a
> file.
>