<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Stop_queries&amp;feed=atom&amp;action=history</id>
		<title>Stop queries - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Stop_queries&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Stop_queries&amp;action=history"/>
		<updated>2013-05-22T05:07:58Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Stop_queries&amp;diff=3315&amp;oldid=prev</id>
		<title>Connor: Created page with &quot;&lt;p&gt;Here you are shown how to find long running queries&lt;/p&gt; &lt;p&gt;and to kill them stopping them from using up database resources and&lt;/p&gt; &lt;p&gt;therefore allowing the database to res...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Stop_queries&amp;diff=3315&amp;oldid=prev"/>
				<updated>2012-08-08T11:12:58Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;p&amp;gt;Here you are shown how to find long running queries&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;and to kill them stopping them from using up database resources and&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;therefore allowing the database to res...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;p&amp;gt;Here you are shown how to find long running queries&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;and to kill them stopping them from using up database resources and&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;therefore allowing the database to respond quicker.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;div class='ht'&amp;gt;&lt;br /&gt;
&amp;lt;div class=params&amp;gt;schema:scott&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='tidy'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='setup'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
It is surprisingly easy to produce long running queries.&lt;br /&gt;
They can be produced mainly through incorrectly written queries&lt;br /&gt;
such as ones missing a JOIN function when it is needed.&lt;br /&gt;
Luckily though Oracle, Postgres, MySQL and SQLServer have commands&lt;br /&gt;
that allow the user to find and terminate these processes. &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-oracle'&amp;gt;&lt;br /&gt;
SELECT username, sid, serial#, TO_CHAR(sysdate, 'YYYY-MM-DD HH24:MI:SS')&amp;quot;CURRENT&amp;quot;,&lt;br /&gt;
       TO_CHAR(logon_time,'YYYY-MM-DD HH24:MI:SS')&amp;quot;LOGON&amp;quot;,&lt;br /&gt;
       (sysdate - logon_time)*24*60&amp;quot;MINS&amp;quot;&lt;br /&gt;
  FROM V$SESSION&lt;br /&gt;
  WHERE (sysdate - logon_time)*24*60 &amp;gt; 1&lt;br /&gt;
    AND username is not NULL&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-mysql'&amp;gt;&lt;br /&gt;
SHOW PROCESSLIST&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-sqlserver'&amp;gt;&lt;br /&gt;
USE master&lt;br /&gt;
SELECT spid, nt_username, &lt;br /&gt;
       datediff(s, logon_time, GETDATE())&lt;br /&gt;
  FROM sysprocesses&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-postgres'&amp;gt;&lt;br /&gt;
SELECT datid, datname, usename, procpid,&lt;br /&gt;
       backend_start&lt;br /&gt;
  FROM pg_stat_activity&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-oracle&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;To kill a session in Oracle use: ALTER SYSTEM KILL SESSION 'sid,serial'&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-mysql&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;To terminate a session in MySQL use: KILL 'Id'&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-sqlserver&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;To kill a process in sqlserver use: EXEC ('kill Spid')&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-postgres&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;To kill a session in Postgres use: # kill -INT 'procpid'&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Hacks Ref}}&lt;/div&gt;</summary>
		<author><name>Connor</name></author>	</entry>

	</feed>