'Transact-SQL'에 해당되는 글 32건

  1. SQL의 CPU 성능 측정 단위 확인해볼 것~~
  2. (펌) drop table 삭제했을 때 복구 방법~
  3. Data reset for a DMV
  4. Suspect page 검사하기
  5. SQL Dump 파일 확인 1
  6. DirtyPage DMV
  7. relog 사용 방법
  8. UPDLOCK
  9. group by 빨리 처리하기
  10. How to Recycle SQL Server error logs – 5 Types of logs 1

   

1초 = 1,000ms(밀리초) = 1,000,000μs(마이크로초)

   

sys.dm_exec_query_stats(Transact-SQL)

last_worker_time

bigint

계획이 마지막으로 실행되었을 사용된 CPU 시간(마이크로초 단위 보고되지만 밀리초 단위까지만 정확함)

   

SQL:BatchCompleted 이벤트 클래스

CPU

int

일괄 처리에 사용된 CPU 시간(밀리초)입니다.

   

SET STATISTICS TIME(Transact-SQL)

ms(밀리초)

   

'Transact-SQL' 카테고리의 다른 글

Plan cache, adhoc single-use plan cache 지우고 싶을 때~~  (0) 2013.04.24
SQL json 쿼리  (0) 2013.04.23
(펌) drop table 삭제했을 때 복구 방법~  (0) 2013.02.05
Data reset for a DMV  (0) 2013.01.04
Suspect page 검사하기  (0) 2012.11.15

정말 멋진 폴 아저씨~^^

>> 삭제된 테이블을 로그 파일로 복구하기 입니다.  중요 포인트는 풀백업하고 로그 백업이 되어 있어야 합니다.

http://www.sqlskills.com/blogs/paul/using-fn_dblog-fn_dump_dblog-and-restoring-with-stopbeforemark-to-an-lsn/

로그 백업 전이라면 메모리에 있는 로그 정보 보기 : fn_dblog
로그 백업 파일로 로그 정보 보기 : fn_dump_dblog


 20130205_삭제된테이블복구방법.sql



'Transact-SQL' 카테고리의 다른 글

SQL json 쿼리  (0) 2013.04.23
SQL의 CPU 성능 측정 단위 확인해볼 것~~  (0) 2013.04.15
Data reset for a DMV  (0) 2013.01.04
Suspect page 검사하기  (0) 2012.11.15
SQL Dump 파일 확인  (1) 2012.10.18

Data reset for a DMV

'Transact-SQL' 카테고리의 다른 글

SQL의 CPU 성능 측정 단위 확인해볼 것~~  (0) 2013.04.15
(펌) drop table 삭제했을 때 복구 방법~  (0) 2013.02.05
Suspect page 검사하기  (0) 2012.11.15
SQL Dump 파일 확인  (1) 2012.10.18
DirtyPage DMV  (0) 2012.10.11

Suspect page 검사하기

use msdb

go

   

select * from suspect_pages

http://msdn.microsoft.com/en-us/library/ms174425.aspx

Contains one row per page that failed with a minor 823 error or an 824 error.

   

--> 이벤트 정보 확인

http://msdn.microsoft.com/en-us/library/bb677177.aspx 경고 시스템으로 만들 수 있겠군!!

   

차주언 형 감사해요^^

'Transact-SQL' 카테고리의 다른 글

(펌) drop table 삭제했을 때 복구 방법~  (0) 2013.02.05
Data reset for a DMV  (0) 2013.01.04
SQL Dump 파일 확인  (1) 2012.10.18
DirtyPage DMV  (0) 2012.10.11
relog 사용 방법  (0) 2012.09.28

SQL Dump 파일 확인

  1. DMV 파일 확인

       

DMV를 활용하여 Dump 파일이 생성되었는지 확인이 가능하다.(SQL2008R2 이상+)

두 번에 걸쳐 dump파일이 생성됨을 확인할 수 있다.

   

  1. 디렉토리 확인

   

각 덤프마다 txt, crash dump file, bug check dump

   

Crashdump file 더블 클릭해서 실행하면 미니 덤프으로 요약 정보를 확인할 수 있다.

   

'Transact-SQL' 카테고리의 다른 글

Data reset for a DMV  (0) 2013.01.04
Suspect page 검사하기  (0) 2012.11.15
DirtyPage DMV  (0) 2012.10.11
relog 사용 방법  (0) 2012.09.28
UPDLOCK  (0) 2012.09.20

DirtyPage DMV

Bufferpool 영역에서 dirty page 정보를 확인할 수 있는 DMV.

SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

-- http://www.sqlskills.com/BLOGS/PAUL/post/Inside-the-Storage-Engine-Whats-in-the-buffer-pool.aspx

select sysObj.name,
(CASE WHEN ([is_modified] = 1) THEN 'Dirty' ELSE 'Clean' END) AS 'Page State',
* 
from sys.dm_os_buffer_descriptors bufferDescriptors
INNER JOIN sys.allocation_units AllocUnits ON bufferDescriptors.allocation_unit_id = AllocUnits.allocation_unit_id
INNER JOIN sys.partitions Partitions ON AllocUnits.container_id = Partitions.hobt_id
INNER JOIN sys.objects sysObj ON Partitions.object_id = sysObj.object_id
WHERE bufferDescriptors.database_id = DB_ID()
AND sysObj.is_ms_shipped = 0		-- ##. 개체가 내부 SQL Server 구성 요소로 만들어집니다.
go	


'Transact-SQL' 카테고리의 다른 글

Suspect page 검사하기  (0) 2012.11.15
SQL Dump 파일 확인  (1) 2012.10.18
relog 사용 방법  (0) 2012.09.28
UPDLOCK  (0) 2012.09.20
group by 빨리 처리하기  (0) 2012.09.11

relog 사용 방법

>> relog 사용 방법 정리

http://blogs.msdn.com/b/granth/archive/2008/09/23/relogging-perfmon-binary-log-files-to-sql.aspx

http://laigo.kr/635




for %a in (*.blg) DO osql -o NUL -b -E -S (JUDYDBA-D\SQL2012) -d PDB -Q "EXIT(SELECT COUNT([GUID]) FROM DisplayToID WHERE DisplayString = '%a')" & IF NOT ERRORLEVEL 1 relog %a -f SQL -o SQL:PDB!%a


-oSQL:  ODBC DSN 이름 ! 유일식별자 GUID



굿... 성능 로그 파일들을 DB에 손쉽게 넣을 수가 있다니 얼마나 편한가~~


'Transact-SQL' 카테고리의 다른 글

SQL Dump 파일 확인  (1) 2012.10.18
DirtyPage DMV  (0) 2012.10.11
UPDLOCK  (0) 2012.09.20
group by 빨리 처리하기  (0) 2012.09.11
How to Recycle SQL Server error logs – 5 Types of logs  (1) 2012.09.03

UPDLOCK

어제 SQL Tag 채팅도중에 오랜만에 UPDLOCK에 대해서 논의했다. 정리해보았다.

UPDLOCK 정의


UPDLOCK : 테이블을 읽는 중 공유 잠금 대신 업데이트 잠금을 사용하며 명령문이나 트랜잭션이 끝날 때까지 보유됩니다. UPDLOCK을 사용하면 다른 트랜잭션이 읽는 것을 차단하지 않고 데이터를 읽을 수 있고 마지막으로 읽은 후 데이터가 변경되지 않으며 나중에 업데이트할 수 있습니다.


TEST(민석형 Test Script)


use test
go
-- Trace flag 3604 is to print the output in query window
-- Trace flag 1200 get a detailed report of all locks acquired by each SQL statement 
DBCC TRACEOFF(3604,1200) WITH NO_INFOMSGS 
go 

if object_id ('tblx') is not null 
drop table tblx 
go 

create table tblx 
(idx int 
,c1 int 
) 
go 

create clustered index cl_tblx on tblx (idx) 
go 

insert into tblx values (1,1) 
insert into tblx values (2,2) 
go 

select * from tblx 
go 

if @@trancount > 0 
rollback tran 
go 

DBCC TRACEON(-1,3604,1200) WITH NO_INFOMSGS
go 

-- session 1
declare @c1 int 
set @c1 = 0 

begin tran 

select @c1 = c1 from tblx with(updlock) where idx =1 

print @c1

update tblx set c1 = c1+1 
where idx =1 

waitfor delay '00:00:005' 
commit
go

-- session 2
declare @a int 
set @a = 0 
begin tran 
select @a =c1 from tblx with(updlock) where idx =1 
print @a 
go



예전에 UPDLOCK을 써서 사용했던 기억이 난다. 그때는 잠금이 오래 걸려 잠금 대기 상태에서 timeout이 발생했던 기억이 난다. 내부적으로 사용하는 SP중에 잠금을 많이 잡아 먹는 로직이 있어서 잠금 타임아웃 흑흑...  


참고자료

UPDLOCK 힌트를 사용 하는 경우 PRB: 교착 상태가 발생할 수 있습니다.
http://support.microsoft.com/kb/179362/ko
Introduction to Locking in SQL Server
http://sqlindian.com/2012/07/06/deadlock-due-to-parallelism/ 
http://www.sqlteam.com/article/introduction-to-locking-in-sql-server

'Transact-SQL' 카테고리의 다른 글

DirtyPage DMV  (0) 2012.10.11
relog 사용 방법  (0) 2012.09.28
group by 빨리 처리하기  (0) 2012.09.11
How to Recycle SQL Server error logs – 5 Types of logs  (1) 2012.09.03
ORIGINAL_LOGIN() 와 SUSER_SNAME() 차이  (0) 2012.07.30

group by 빨리 처리하기


민석형 자료를 보면서 정리.

http://sqlsql.tistory.com/194


use test
go

set statistics time on
go

select cast(CAST ( getdate() as float)as int)		-- (현재) 날짜값을 정수형으로 반환
select cast(CAST ( getdate() -1 as float)as int)	-- (현재) 날짜값을 정수형으로 반환

-- 대부분 처리 방법
select 
	convert(char(8), d, 112)
,COUNT(*) 
from dbo.tblx
where d between '2012-09-11' and '2012-09-11 23:59:59'
group by convert(char(8), d, 112)
order by 1
go

-- #. 빠른 처리 방법
SELECT
 CONVERT(datetime,cast(CAST (d as float)as int))
,COUNT(*) 
FROM dbo.tblx WITH(NOLOCK)
where d between '2012-09-11' and '2012-09-11 23:59:59'
GROUP BY cast(CAST (d as float)as int)
order by 1
option (maxdop 1)

--SQL Server 구문 분석 및 컴파일 시간: 
--   CPU 시간 = 0ms, 경과 시간 = 5ms.

--(1개 행이 영향을 받음)

-- SQL Server 실행 시간: 
-- CPU 시간 = 889밀리초, 경과 시간 = 878밀리초

--(1개 행이 영향을 받음)

-- SQL Server 실행 시간: 
-- CPU 시간 = 281밀리초, 경과 시간 = 293밀리초


 

'Transact-SQL' 카테고리의 다른 글

relog 사용 방법  (0) 2012.09.28
UPDLOCK  (0) 2012.09.20
How to Recycle SQL Server error logs – 5 Types of logs  (1) 2012.09.03
ORIGINAL_LOGIN() 와 SUSER_SNAME() 차이  (0) 2012.07.30
쥑이는 SCRIPT  (0) 2012.06.28

http://mssqlfun.wordpress.com/2012/07/26/how-to-recycle-sql-server-error-logs-5-types-of-logs/


1) Recycle SQL Error log

exec msdb..sp_cycle_errorlog

2) Recycle SQL Agent Error log

exec msdb..sp_cycle_agent_errorlog

3) Recycle(rollover) SQL Server Default trace

EXEC sp_configure ‘default trace’, 0 RECONFIGURE

EXEC sp_configure ‘default trace’, 1 RECONFIGURE

4) Recycle SQLFT#.Log

http://msdn.microsoft.com/en-us/library/ms142495(SQL.105).aspx
the Full-Text Search crawl logging facility creates and maintains a crawl log, which is a plain text file

a. Before 2008 – restart the indexer

b. After 2008 – no way to cycle to full text log without restarting SQL server

5) Recycle FDLAUNCHERRORLOG
SQL Full-text Filter Daemon Service Error Log (FDLAUNCHERRORLOG)
http://blogs.msdn.com/b/sqlserverfaq/archive/2010/04/06/how-to-move-fdlauncherrorlog-from-one-location-to-another-in-sql-2008.aspx

a. Restart FDLauncher service

'Transact-SQL' 카테고리의 다른 글

UPDLOCK  (0) 2012.09.20
group by 빨리 처리하기  (0) 2012.09.11
ORIGINAL_LOGIN() 와 SUSER_SNAME() 차이  (0) 2012.07.30
쥑이는 SCRIPT  (0) 2012.06.28
sp_configure 마지막 변경일  (0) 2012.05.15