• Lock 테이블 확인

select t.relname,l.locktype,page,virtualtransaction,pid,mode,granted 
from pg_locks l, pg_stat_all_tables t
where l.relation=t.relid order by relation asc;

  • Lock 삭제

select pg_cancel_backend(pid);


-- TABLE 용량


SELECT CONVERT(VARCHAR(30), MIN(o.name)) AS t_name

     , LTRIM(STR(SUM(reserved) * 8192.0 / 1024.0, 15, 0) + ' KB') AS t_size

FROM   sysindexes i

           INNER JOIN sysobjects o ON o.id = i.id

WHERE  i.indid IN (0, 1, 255)

   AND o.xtype = 'U'

GROUP BY

       i.id

ORDER BY

       -- t_name ASC

       SUM(reserved) * 8192.0 / 1024.0 DESC



-- TABLE 건수


SELECT o.name

     , i.rows

FROM   sysindexes i

           INNER JOIN sysobjects o ON i.id = o.id

WHERE  i.indid < 2

   AND o.xtype = 'U'

ORDER BY

       i.rows DESC



출처: http://akbory.tistory.com/2 [惡보리]




--임시테이블 변수 선언

DECLARE @테이블_변수 TABLE (TABLE_NM VARCHAR(60), COL_NM VARCHAR(100));


--일반 변수 선언

DECLARE @임시필드변수1 VARCHAR(60), @임시필드변수2 VARCHAR(60);


--테이블 변수에 데이터 담기

INSERT @테이블_변수 SELECT 필드1, 필드2 FROM 원본_검색_테이블


-- 커서 선언

DECLARE SEL_CUR CURSOR FOR SELECT * FROM @테이블_변수;


OPEN SEL_CUR;

FETCH NEXT FROM SEL_CUR INTO @임시필드변수1, @임시필드변수2

PRINT '------------------------------- START -------------------------------'

WHILE @@FETCH_STATUS = 0 

BEGIN

BEGIN TRAN;

PRINT '[' + @임시필드변수1 + '] [' + @임시필드변수2 + '] 작업시작';

/*

작업할 내용

*/


FETCH NEXT FROM SEL_CUR INTO @임시필드변수1, @임시필드변수2;

END;

PRINT '------------------------------- END ---------------------------------'

CLOSE SEL_CUR;

DEALLOCATE SEL_CUR;

+ Recent posts