Chinaunix首页 | 论坛 | 博客
  • 博客访问: 771315
  • 博文数量: 156
  • 博客积分: 5320
  • 博客等级: 大校
  • 技术积分: 1605
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-09 12:24
文章分类

全部博文(156)

文章存档

2010年(20)

2009年(46)

2008年(21)

2007年(21)

2006年(33)

2005年(10)

2004年(5)

分类: 数据库开发技术

2009-12-09 09:55:20

 

1月26日

Database Maintenance Plans

Database Maintenance Plans for SQL Server 2000

Database Maintenance Plans offer the following features in SQL Server 2000:

1. Backing up databases
2. Reorganization of indexes and data pages
3. Statistics Update
4. Shrinking the database
5. Database integrity checks

The above tasks of the maintenance plans would have associated with respective SQL Agent jobs and also these could be scheduled to suit your needs. Furthermore, these jobs could be created manually also without the help of maintenance plans.

Database Maintenance Plans for SQL Server 2005
In addition to the above mentioned features, SQL Server 2005 Enterprise Edition provides the option of rebuilding the indexes as an online operation. This makes it possible for the indexes to remain online while a rebuild index task is being performed on the database.

ONLINE = { ON OFF }
Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF.
Note: Online index operations are available only in SQL Server 2005 Enterprise Edition.

ON
Long-term table locks are not held for the duration of the index operation. During the main phase of the index operation, only an Intent Share (IS) lock is held on the source table. This enables queries or updates to the underlying table and indexes to continue. At the start of the operation, a Shared (S) lock is held on the source object for a very short amount of time. At the end of the operation, for a short time, an S (Shared) lock is acquired on the source if a nonclustered index is being created; or an SCH-M (Schema Modification) lock is acquired when a clustered index is created or dropped online and when a clustered or nonclustered index is being rebuilt. ONLINE cannot be set to ON when an index is being created on a local temporary table.

OFF
Table locks are applied for the duration of the index operation. An offline index operation that creates, rebuilds, or drops a clustered index, or rebuilds or drops a nonclustered index, acquires a Schema modification (Sch-M) lock on the table. This prevents all user access to the underlying table for the duration of the operation. An offline index operation that creates a nonclustered index acquires a Shared (S) lock on the table. This prevents updates to the underlying table but allows read operations, such as SELECT statements.


The frequency of these tasks and which tasks are needed need to be performed need to be decided on the following factors:
1. Importance of the database in question
2. Size of the database
3. Maintenance window frequency
4. Load on the server
5. Whether it is an OLTP or OLAP database or both
6. The kind of transactions that take place on the database (Point 5 and 6 would decide how often index reorganization/index rebuild/statistics updates are required and whether a shrink database/file is required
----------------------------------------

          ISO9002文档编号:GSANYI - ZYSKJHSZX - 01

    1.在数据库服务器(NTSERVER)上,点 [ 开始 ] - [ 程序 ] - [ Microsoft SQL Server 7.0]- [ Enterprise Manager ] ,打开企业管理器。
    2.点项目前的 [+] ,依次弹开 [ Console Root ] - [ Microsoft SQL Servers ] - [ SQL Server Group ] - [ NTSERVER(Windows NT)] - [ Management ] ,单击 [ Database Maintenance Plan ] 。如果已有曾经创建好的规划,则在右面窗口中可看到。
3.单击右键,点菜单中的 [ New Maintenance Plan...] ,启动数据库维护规划向导“Database Maintenance Plan Wizard ”,从向导界面上可看到,它可以做下述工作:
(1) 执行数据库完整性检查(Run database integrity checks);
(2) 更新数据库统计信息(Update database statistcs);
(3)执行数据库备份(Perform database backups)。
4.单击 [下一步] ,选择数据库:
(1) 全部数据库All databases;
(2) 所有的系统数据库All system databases(master,model,and msdb);
(3) 所有的用户数据库All user databases(all databases other than master,model,and msdb);
(4) 指定下列数据库These databases:(anyisys、zw0001、zw0002等等)。
5.单击 [下一步] ,进入数据库优化信息 [ Update Data Optimization Information ] 界面;
复选项(1):重组数据页及索引页(Reorganize data and index pages):
    单选项①:用剩余空间的初始大小重组数据页;
    单选项②:改变每页的自由空间百分比至一特定值(例如10%)。
复选项(2):从数据库文件移除未用空间(Remove unused space from database files):
    当增长至超过至一特定值(例如 50 MB),
    自由空间的数值在压缩后保留至数据的特定值(例如 10%)。
定期执行时刻列表(Schedule):缺省为在每周日的1点钟发生(Occurs every 1 week(s) on Sunday, at 1:00:00.)。可按 [ Change ] 按钮来改变频度及时间(后文详述)。
6.单击 [ 下一步 ] ,进入数据库完整性检查(Database Integrity Check)界面,数据库完整性测试能发现由于硬件及软件错误引的不一致性:
复选项(1):检查数据库完整性:
    单选项①:包括索引
        可选项:尝试修复较小的错误(Attempt to repair any minor problems)
    单选项②:排除索引
复选项(2):在备份前进行下述测试(即定期执行时刻表,详情略)
7.单击 [ 下一步 ] ,进入具体指定数据库备份规划(预防失败及数据丢失)界面:
复选项(1):备份数据库作为维护规划的一部分
    可选项:确定完成存储备份文件的备份位置上的备份的完整性,
        单选项①:Tape (磁带)
        单选项②:Disk(磁盘)
复选项(2):执行时刻表:缺省为每周日二点钟(Occurs every 1 week(s) on Sunday, at 2:00:00.),可按 [ Change ] 按钮改变。
按 [ Change ] 按钮,进入循环任务时间表编辑(Edit Recurring Job Schedule)界面:
Occurs(发生在):
(1) ⊙Daily(日):
                 Every [ 1 ]days(每多少天) 缺省为每 1天。
(2) ⊙Weekly(周):
                 Every [ 1 ]weeks(每多少周)  缺省为每 1 周,
                 复选项:每周中的星期几(从周一至周日),缺省为星期天:
                         □Mon □Tue □Wed □Thur □Fri □Sat □Sun
(3)⊙Monthly(月):
       单选项:⊙Day [ 1 ] of [ 1 ] Month(s)
                 若干月的若干天(缺省为1);
               ⊙The [ 1st ] [ Sunday ] of [ 1 ] months
                 若干月的第几个星期几(缺省为一个月中第一个星期天)。
Daily frequency(按日的频度):
(1) ⊙ Occurs once at:[ 02:00 AM ] ,在每天凌晨两点执行一次(缺省),时间可点微调按钮或直接输入来更改。
(2) ⊙ Occurs every :[ 1 ] Hour(s) / Minute(s) 每若干小时或若干分钟发生。
          Starting [ 02:00 AM ]      开始时段(缺省为凌晨02时)
          Ending at: [ 23:59 PM ]    结束时段(缺省为晚上23时59分)
Duration(持续的时间):
  Start [ Mon2001- 4-16] (开始日期缺省为当前系统日期:例如2001年4月16日星期一)
  ⊙ End date:[ Mon2001- 4-16] 结束日期(缺省为当前系统日期)
  ⊙ No end date  (不限定结束日期)。
8.点 [ 下一步 ] ,进入“确定备份磁盘路径”界面,
要存储备份文件的路径:
    单选项①:使用缺省备份路径;
    单选项②:使用此路径:X:(SQL Server 的安装盘符)\MSSQL7\BACKUP,可按路径编辑框后的方块按钮来另外指定路径(例如:E:\anyi_db_bak\)。
复选项(1):为每个数据库创建一个子文件夹;
复选项(2):删除比指定期限更旧的文件:4 week(s)  (缺省为4个星期),可更改为其他期限;
备份文件类型:缺省为“BAK”
备注:磁盘备份文件名一般为系统自动给出,诸如:ZW9001_db_200104121730.BAK,其中“200104121730”是时间戳。
9.点 [ 下一步 ] ,进入“确定事务日志备份规划”界面:
复选项(1):备份事务日志作为维护规划的一部分
    可选项:确定完成存储备份文件的备份位置上的备份的完整性
        单选项①:Tape (磁带)
        单选项②:Disk(磁盘)
复选项(2):执行时刻表:缺省为每周的星期一至星期六的零时整(Occurs every 1 week(s) on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, at 0:00:00.),可更改。
10.点 [ 下一步 ] ,进入“确定备份磁盘路径”界面,
要存储备份文件的路径:
    单选项①:使用缺省备份路径;
    单选项②:使用此路径:X:(SQL Server 的安装盘符)\MSSQL7\BACKUP,可按路径编辑框后的方块按钮来另外指定路径(例如:E:\anyi_db_bak\)。
复选项(1):为每个数据库创建一个子文件夹;
复选项(2):删除比指定期限更旧的文件:4 week(s)  (缺省为4个星期),可更改为其他期限;
备份文件扩展名:缺省为“TRN”
备注:磁盘备份文件名一般为系统自动给出,诸如:ZW9001_tlog_200104121730.TRN,其中“200104121730”是时间戳。
11.点 [ 下一步 ] ,确定存储由维护规划引起的报告的路径:
复选项(1):在下列路径写报告至文本文件:缺省为C:\MSSQL7\LOG,可更改。
    可选项:删除旧于下述期限的文本报告:缺省为 4 Week(s) 可更改。
复选项(2):将报告文件E-mail至指定操作员(如果)。
12.点 [ 下一步 ] ,设置维护历史,执行活动的记录可存储在维护规划执行的服务器上,与 / 或另外的(远程)服务器上:
本地:
    复选项:将历史写入此服务器上的msdb.dbo.sysdbmaint_plan_history表中。
        可选项:将该规划历史表中的行数限制至:1000行(缺省),可更改。
远程服务器:
    加至msdb.dbo.sysdbmaint_plan_history表中的历史记录在远程服务器上。Windows NT身份认证模式用于登录远程服务器。
复选项:写历史至服务器:可按按钮来选择远程SQL Server。
    可选项:将该规划历史表中的行数限制至:1000行(缺省),可更改。
13.点 [ 下一步 ] ,完成规划设置向导(Completing the Database Maintenance Plan Wizard),指定规划的名称(Plan Name):DB Maintenance Plan4(缺省),可自行录入。
检查一遍信息后,按 [ 完成 ] 按钮,系统会提示如下信息:Successfully created the maintenance plan,然后按 [ 确定 ] 即可。
14.要确保上述规划执行,首先要保证MS SQL Server Agent服务是启动的。可按如下步骤来检查或启动该服务:
点 [ 开始 ] – [ 程序 ] – [ Microsoft SQL Server 7.0 ] – [ SQL Server Service Manager],在服务管理器窗口中,点 [ Services : Ms SQL Server ] 下拉按钮,选 [ SQL Server Agent ] ,如果看到红色方块标志,表示该服务目前为停止状态,可按 [ Start / Contin ] 按钮来启动它;启动状态为绿色三角形标志。
15.要修改规划的设置,可按下述步骤:
点 [ 开始 ] – [ 程序 ] – [ Microsoft SQL Server 7.0 ] – [ Enterprise Manager ] ,运行企业管理器,依次弹开SQL Server 至 [ Database Maintenance Plans ] ,将其单击,在右面窗口中的规划项目行上单击右键,点 [ Properties ] ,可看到6个设置页面,分别为:
(1)General             (2)Optimizations             (3)Integrity
(4)Complete Backup     (5)Transaction Log Backup     (6)Reporting
阅读(2164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~