深刻的教训――SQLServer关于TempDB的使用(二)

2014-11-23 22:20:36 · 作者: · 浏览: 29
4/17 12:40:29

40

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:40:09

30

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:39:45

23

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:39:23

26

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:39:02

6

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:38:39

6

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:38:17

10

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:37:54

13

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:37:32

16

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:37:10

6

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:36:49

6

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:36:27

10

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:36:05

10

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:35:44

10

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:35:22

10

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:34:59

43

1,024.00

数据文件自动增长

tempdev_1

2014/4/17 12:34:37

50

1,024.00

数据文件自动增长

tempdev_2

2014/4/17 12:34:08

23

1,024.00

数据文件自动增长

tempdev_0

2014/4/17 12:33:35

20

1,024.00

导致原因

查询语句未指定删选条件,语句如下:

--得到流水,因数据敏感问题,已将字段使用’xx’代替。
IF EXISTS (SELECT *
           FROM   tempdb..sysobjects
           WHERE  id = Object_id(N'tempdb..#t_scfw')
                  AND type = 'U')
  DROP TABLE #t_scfw;

IF NOT EXISTS (SELECT *
               FROM   tempdb..sysobjects
               WHERE  id = Object_id(N'tempdb..#t_scfw')
                      AND type = 'U')
  SELECT tsvr.*,
         bsl.xx AS xxx,
         bsl.xx,
         bsl.xx
  INTO   #t_scfw
  FROM   #t1 AS tsvr
         JOIN t2 AS bsl
           ON tsvr.xx = bsl.xx
              AND tsvr.xx = bsl.xx
              AND tsvr.xx = bsl.xx
              AND tsvr.xx = bsl.xx
              AND bsl.xx > 0; 

总结

由于tempdb是存储在SSD上,且总大小为270G。所以,在显式使用临时表时一定要注意数据大小。避免把tempdb空间耗尽,影响整个SQLServer的正常运行。好在设置了tempdb的最大空间,并且最大空间小于SSD硬盘的最大容量,不然服务器的盘就会挂掉,从而导致服务器宕机,多么痛的领悟!切忌犯如此低级错误,作下此文提醒和鞭策自己,凡事三思而后行