官术网_书友最值得收藏!

Configuring automatic database maintenance

The automatic maintenance of the database involves tools to simplify your administration tasks. You can configure this option anytime after you create the database.

Basically, you define maintenance schedules:

  • online: Period of low activity to allow for runstats
  • offline: Period when there is no activity (no user connecting), for backups and reorgs

You also define maintenance activities:

  • backups: DB2 determines if a backup is needed and schedules it during maintenance windows (offline)
  • reorgs: Used to reorganize tables for optimal table space use (offline)
  • runstats: Makes sure DB2 has a quantitative view of data for its optimizer to produce best results (online)

You can have configured notifications on maintenance jobs.

Getting ready

Identify the best time for maintenance windows, when there is low or no activity on this database. Choose which maintenance activities you want.

For backups, prepare your strategy first, between online or offline backups. In case you want online backups and have circular logging on this database, DB2 will offer to change this and will do an online backup, so you may want to plan ahead to allow time for the backup to complete.

Choose a destination for automatic backups. If it's on disk, have a separate directory for automatic backups. Choose people to be notified; for mail or pager mail notifications, you will have to obtain the SMTP server address. Make sure the server on which the database runs can send e-mails.

How to do it...

  1. Choose the database you want to manage:

    Choose a database and right-click on it; select Configure Automatic Maintenance.

  2. Select maintenance type:

    You can disable or change automation settings. Leave on Change automation settings and click Next.

  3. Configure maintenance windows:

    We define here the maintenance windows and customize the schedules for online and offline maintenance. Click on Change; define here an online maintenance window outside of work hours from 9:00 a.m. till 6:00 p.m., from Monday through Friday then click Ok. You can also define here an offline maintenance window outside of work hours from 0:00 a.m. till 11:00 p.m., Saturday and Sunday and then click Ok. We'll be back in the maintenance windows definition, so click Next.

  4. Manage your Notification List:

    The screen Manage your Notification List helps you set up your contact list for e-mails, or pagers. For the sake of brevity, I'll just give a quick description for these screens. Click on Manage Contacts, choose your SMTP server, and add your contacts manually or import them from another server. When you return to the Notification list, choose the contacts who will receive mails for Database Health notification, and click Next.

  5. Select the maintenance activity.
How to do it...

You can select any activity and configure its settings.

  • Backups:

    You can let DB2 decide the frequency for backups or customize the settings yourself. You can choose the backup location in the same fashion as an ordinary backup and can choose whether you want an online or offline backup. We'll leave it off for now, until we discuss backups later on.

  • Reorgs:

    When you select Configure Settings, you can tell DB2 to include all tables, or select table scope by using the simple filter and fill in the conditions (such as name, schema, and so on), or by writing your own where clause with the custom filter. On the Table scope tab, just select All tables and do not include system tables.

    Click on the Reorganization options tab, and check the following options:

    Use a system temporary table space with a compatible page size

    Keep, for the compression data dictionary

    Offline Index reorganization mode.

    Click on Ok.

  • Runstats:

    On the Table scope tab, just select All tables—do not include system tables. Click on Ok, and when back on Maintenance activity, click Next.

    Review the automatic maintenance settings, and click Finish.

How it works...

DB2 automatically knows if maintenance is required and will do it in the next available maintenance window.

There's more...

You can obtain the same result by creating tasks in the task center. This is useful if you want to schedule specific hours for some tasks or make sure that, say, a backup is done without having DB2 evaluate if it's needed or not.

Backups

If you send backup to disks, you should have a separate directory for automatic maintenance backups. DB2 will automatically prune backup images, so, if you scheduled backups via the task center or other tools such as cron or other manual backups, make sure to save them in another directory, otherwise they will be deleted.

If you select an online backup and the database is configured with circular logging, DB2 will offer to change this and will do an online backup right away. Automatic backups results will be sent to db2diag.log. There are more advanced methods for backups; we will cover these in Chapter 7, DB2 Backup and Recovery.

Reorgs

DB2 Reorgs defragment table and index data. Automatic reorgs, before DB2 v9.7, were done in place. You needed to have enough space for a table and its copy on the same table space and could not tell DB2 to use a temporary table space. In DB2 v9.7, you now need to have a system temporary table space large enough for the largest table.

Reorg results are sent to db2diag.log.

Runstats

The Runstats utility gathers table and index statistics and information for the SQL optimizer. DB2 uses this information for its optimizer, and chooses the best path for each SQL query. With the automatic maintenance, you don't have to worry about being notified by development about new tables, and indexes, since they'll all be picked up for runstats (depending on the table scope you selected).

There is a downside to this. This utility is useful for small tables, since statistics are collected on the whole table. For large tables several Gigabytes in size, this could generate problems. You can override the default statistics settings for a table by setting a statistics profile. We'll discuss this in Chapter 13, DB2 Tuning and Optimization.

Runstat results are sent to db2diag.log.

See also

主站蜘蛛池模板: 牡丹江市| 日喀则市| 萨迦县| 新余市| 益阳市| 阳原县| 金沙县| 马边| 綦江县| 湟源县| 富川| 石柱| 毕节市| 梁平县| 伊金霍洛旗| 驻马店市| 永定县| 桦南县| 赣榆县| 扶沟县| 旅游| 汕尾市| 张家港市| 长阳| 平遥县| 濮阳市| 安义县| 惠州市| 石阡县| 桂平市| 五河县| 康马县| 古田县| 金沙县| 宁蒗| 滨海县| 苍山县| 林西县| 兴仁县| 措美县| 天峨县|