Today we share another case: no SQL counter exists but you find some number counters from Perfmon.
You need to rebuild the counter, try the below action plan:
1. run cmd
2. cd \windows\system32
3. lodctr /R
BACKUP DATABASE [DAILY LEARNING] TO BLOG [QIUSHIYANG.COM]
Today we share another case: no SQL counter exists but you find some number counters from Perfmon.
You need to rebuild the counter, try the below action plan:
1. run cmd
2. cd \windows\system32
3. lodctr /R
Perfmon counter is handy tool for DBA to glance what happening in OS/Instance level. As DBA, you’d better to make sure related perfmon counters exist daily. Rebuild missing counter may request restart instance or reboot server, you may have difficulty to do so when you operating a critical system during business hour.
Today we share case 1: You can’t find the perfmon counter when you install 32bit SQL Server on 64bit OS. (We call it WOW- Windows on Windows).
Uhhhh, the best practice is to install 64bit SQL Server instead of 32bit on 64bit hardware. But if you have no choice or this is a legacy system..
1. Stop Performance Logs & Alerts services.
2. Run regedit. Find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysmonLog, change ImagePath from “%SystemRoot%\System32\smlogsvc.exe” to “%SystemRoot%\SysWow64\smlogsvc.exe”.
3. Start Performance Logs & Alerts services.
4. Run perfmon from %systemroot%\SysWOW64\perfmon.exe.
5. Create the log.
—- script to check each database’s space usage and size of next growth(MB)
—- for sql 2005 and later version
exec
sp_msforeachdb
‘USE[?];exec sp_spaceused’
—- here we use the undocumented sp_msforeachdb
go
select
db_name(database_id)
as DB_NAME,
name as
File_Name,
case is_percent_growth
when 1
then size * growth / 100.0 /128
—-use 100.0 to trigger the implicit data conversion
when 0
then growth /128.0
end
as Next_Growth_MB
from
sys.master_files
go
Last month I attended “the Microsoft SQL Server 2008 R2 Administration Training for SAP” hosted by our friend Cameron Gardiner in Hong Kong. During the session, Cameron showed us the benchmark results. (http://www.sap.com/solutions/benchmark/sd2tier.epx) I read the doc and noted the server configuration like “… 8 processors / 80 cores / 160 threads… ” Wait a second, 160 threads with 80 cores, HyperThread enabled?
In the old day we were told that HyperThread was not a good idea on SQL box. For more details you can read http://blogs.msdn.com/b/slavao/archive/2005/11/12/492119.aspx . More precise saying, it depends. But I saw HyperThread causing performance down before, around year 2009. I then discussed with Cameron if this the known best practice for SAP on SQL. The answer was yes, but the reason was for the new CPU architecture like Nehalem, Hyper-Threading is reintroduced along with an L3 Cache missing from most Core-based microprocessors. SAP was benefited by Hyper-Threading.
So my understandings:
1) Tradeoff of HyperThread is the shared processor cache may be emptied by one thread.
2) Processor cache is not so important as the old day due to the new CPU technology.
3) We can enjoy the benefit of HyperThread more safely.
Of cause it depends, you should test how your application performing in your own box.
HTH.
6 yrs ago i wrote lots of T-SQL SP using old-school error handling way like:
DECLARE @ErrCode int
SET @@ErrCode = 0
–begin tran here
SELECT @ErrCode = @@ERROR
IF @ErrCode = 0
BEGIN
– stmt here
SELECT @ErrCode = @@ERROR
END
–
IF @ErrCode <> 0
– rollback tran here
ELSE
– commit tran here
It’s very boring to write such block again and again.. and the code becomes very dirty to read.
After SQL2k5, we can use TRY … CATCH … block to handle exception like other decent language as C#/Java!
———
Test script for nested SP
CREATE PROC Error01
AS
BEGIN TRY
DECLARE @X INT
SET @X = 1/0 — make some error
END TRY
BEGIN CATCH
PRINT ‘Error Detected 1′
SELECT ERROR_NUMBER() ERNumber,
ERROR_SEVERITY() Error_Severity,
ERROR_STATE() Error_State,
ERROR_PROCEDURE() Error_Procedure,
ERROR_LINE() Error_Line,
ERROR_MESSAGE() Error_Message
DECLARE @ERNumber int
DECLARE @Error_Severity int
DECLARE @Error_State int
DECLARE @Error_Message varchar(5000)
SELECT @ERNumber = ERROR_NUMBER(),
@Error_Severity = ERROR_SEVERITY() ,
@Error_State = ERROR_STATE(),
@Error_Message = ERROR_MESSAGE()
RAISERROR (@Error_Message,@Error_Severity,@Error_State)– haven’t found out how to pass error # yet
END CATCH
go
CREATE PROC Error02
AS
BEGIN TRY
EXEC Error01
END TRY
BEGIN CATCH
PRINT ‘Error Detected 2′
SELECT ERROR_NUMBER() ERNumber,
ERROR_SEVERITY() Error_Severity,
ERROR_STATE() Error_State,
ERROR_PROCEDURE() Error_Procedure,
ERROR_LINE() Error_Line,
ERROR_MESSAGE() Error_Message
END CATCH
GO
EXEC Error02
GO
– The result :
Error Detected 1
ERNumber Error_Severity Error_State Error_Procedure Error_Line Error_Message
———– ————– ———– —————- ———– ———————————
8134 16 1 Error01 6 Divide by zero error encountered.
(1 row(s) affected)
Error Detected 2
ERNumber Error_Severity Error_State Error_Procedure Error_Line Error_Message
———– ————– ———– —————- ———– ———————————
50000 16 1 Error01 26 Divide by zero error encountered.
(1 row(s) affected)
Conclusion:
1. It’s easier to write error handling code in 2k5. Thinking in the same way as C#.
2. Error handling code should be placed at the end of the script.
3. Be careful for trans control.
I do some tests below to see the behavior of translation savepoint when I considering nested SP.
Test 1
———-
SET NOCOUNT ON
CREATE TABLE TranTest
(
ID int IDENTITY(1,1) PRIMARY KEY,
Txt varchar(50)
)
go
BEGIN TRAN tran01
INSERT INTO TranTest(Txt)
values(‘Tran 01′)
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 first time’)
ROLLBACK TRAN tran02 — Rollback here
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 second time’)
COMMIT TRAN tran01
SELECT * FROM TranTest
go
DROP TABLE TranTest
GO
–Result
ID Txt
———– ————————————————–
1 Tran 01
3 Tran 02 second time
This test tells me that when the begin of translation being committed, all the savepoint between it will be committed too. But those changes in already rollback savepoint won’t be saved.
Test 2
————–
SET NOCOUNT ON
CREATE TABLE TranTest
(
ID int IDENTITY(1,1) PRIMARY KEY,
Txt varchar(50)
)
go
BEGIN TRAN tran01
INSERT INTO TranTest(Txt)
values(‘Tran 01′)
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 first time’)
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 second time’)
ROLLBACK TRAN tran02
COMMIT TRAN tran01
SELECT * FROM TranTest
go
DROP TABLE TranTest
GO
–result
ID Txt
———– ————————————————–
1 Tran 01
2 Tran 02 first time
This test tells me that the savepoint could be same name, and when rollback savepoint the most recent one will be rollbacked..
Test 3
——————
SET NOCOUNT ON
CREATE TABLE TranTest
(
ID int IDENTITY(1,1) PRIMARY KEY,
Txt varchar(50)
)
go
BEGIN TRAN tran01
INSERT INTO TranTest(Txt)
values(‘Tran 01′)
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 first time’)
SAVE TRAN tran02
INSERT INTO TranTest(Txt)
values(‘Tran 02 second time’)
COMMIT TRAN tran02 — try to commit savepoint
COMMIT TRAN tran01 — COMMIT others change
SELECT * FROM TranTest
go
DROP TABLE TranTest
GO
–Result
Msg 3902, Level 16, State 1, Line 16
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
ID Txt
———– ————————————————–
1 Tran 01
2 Tran 02 first time
3 Tran 02 second time
The last test tells me that ONLY Translation could be committed! When you trying to commit a savepoint, the whole translation will be committed. And if you select @@trancount, you can see the # is less 1 now.
Conclusion:
1. SELECT @TC = @@trancount to see if to open a new translation or a savepoint.
2. Check if @TC = 0 when trying to commit a translation. If @TC <>0, that means the translation is not started by this SP, but outer SP..
3. Rollback to Savepoint everytime error happens.
As a field support engineer, I learn different things from different customers and I’d like to write them down to share with you, SQL Server DBA/Dev. Hope this help.