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

Creating and configuring DB2 non-partitioned databases

We will discuss here how to create a single-partitioned database, which is sufficient for most database applications and is the most common configuration for small- to medium-sized databases.

If you plan on having a Business Intelligence (BI) database, you should be planning for a partitioned database. You can estimate one processor core for every 300 GB of data. We will cover this topic in Chapter 3, DB2 Multipartitioned Databases—Administration and Configuration

Getting ready

Gather as much technical information as you can about the hardware or virtual machine(s) you have at your disposal, for this database. Identify in which instance you will create your database, and ensure you will have enough memory and disk space for what you need.

Identify the location where you will create the table spaces (filesystems for Unix platforms, disk drives on Windows servers) and how much available space you will have. Make sure the instance owner has read and write permission in the directory that you will specify for your new database.

Best practices in the industry recommend separating data, indexes, lobs, and transaction logs on separate filesystems (or disk drives, on Windows systems). Depending on your installation, a filesystem can be defined as a single virtual disk on a NAS/SAN RAID 5 device, or a logical volume, spread on many physical disk drives. Check with your storage administrator for the best configuration—get as many disks/spindles as possible.

Decide on a data strategy—consider the database's mission and growth potential. Allow for possible partitioning, or table partitioning. MDC could also be a possible avenue. Decide on a naming convention for mount points and databases. The effort you spend on planning will save much time and money down the road.

Now perhaps you just want to get to the matter right away. We'll create a simple database; I'll explain the details as we go along.

How to do it...

  1. Log in as the target instance owner.

    Start Control Center and make sure the instance is started. Or, start the instance from the command line:

    [db2inst1@nodedb21 ~]$ db2start SQL1063N DB2START processing was successful.
    
  2. Choose the instance.

    Expand the All Systems node in the left pane of the Control Center. Choose the node and instance.

    How to do it...
  3. Create the database.

    Right-click on the Databases folder. A pop-up menu appears; select Create Database and start with the Standard option. We'll use default options for now.

How to do it...
  • We'll create a database called NAV, located in /data/db2, with the same alias. You can add a comment if you wish; I would suggest putting in the name by which the users know this database. Since they probably don't know the database name as NAV, we'll put in Aviation Geo Data.
How to do it...
  • We will also select Let DB2 manage my storage (automatic storage); this will enable DB2 to use automatic storage.

Note

Avoid prefixing schema, table spaces, or database objects with db2, ibm, sys, or syscat. This may induce confusion with objects belonging to DB2. When installing the DBMS, DB2 will ask you to create an instance called db2inst1, by default. You can safely use this instance name or bypass this step and create one later with your own naming convention.

How it works...

DB2 creates and catalogs a database for us. It's basically an empty shell with a catalog, user space, and temporary space. This database will have to be customized to fit your needs.

There's more...

Here are some features to consider before creating a database; some cannot be changed easily when created, so, if you want to change settings, you may even have to export the data, recreate the database with the new settings, and then reimport the data.

Command preview

While creating the database with the Create Database Wizard, there will be a summary report of the operation when DB2 is about to create your database.

Command preview

A Show command button lets you preview the create database command. You can click on Finish to execute the command now, or do it later on.

Command preview

You can copy this command and paste it into a script, so you can create the database manually from the command line, if you wish.

Automatic storage

With automatic storage, DB2 simplifies database file maintenance. DB2 uses the storage path you put in the default directory and manages automatically all table space containers for the database. You may add storage paths; DB2 will create, extend, or add containers in these storage paths. You don't have to worry about container file naming convention or extending containers to allow for free space.

In DB2 Express C version and Enterprise Server Edition (ESE), automatic storage is the default option present in the Control Center's create database dialog. Once a database is created with automatic storage, it cannot be reset after creation. Note the command used for an automatic storage database. No table space definitions are required, since DB2 will create the three main table spaces, CATALOG, USER, and SYSTEM Temporary table spaces.

CREATE DATABASE NAV
AUTOMATIC STORAGE YES
ON '/data/db2'
DBPATH ON '/data/db2'
ALIAS NAV
USING CODESET UTF-8
TERRITORY CA
COLLATE USING SYSTEM
PAGESIZE 4096
WITH 'Aviation Geo Data';

All that is needed for maintenance is to check for filesystem availability. Fortunately, there are tools in DB2 to help you do this; we'll see this later with the health monitor.

Perhaps you have your own naming convention and prefer to manage containers yourself; in that case, automatic storage should be off. With the Control Center, you just have to select I want to manage my space manually, on the first screen. You can create a database using the command center with the AUTOMATIC STORAGE NO option or manually from the command line, using a script. Note the three required table spaces and their container definitions:

CREATE DATABASE NAV AUTOMATIC STORAGE NO ON '/data/db2' ALIAS NAV USING CODESET UTF-8 TERRITORY CA COLLATE USING SYSTEM PAGESIZE 8 K CATALOG TABLESPACE MANAGED BY DATABASE USING ( FILE '/data/db2/db2inst1/NODE0000/nav/catalog.dbf' 6400 ) AUTORESIZE YES MAXSIZE 500 M USER TABLESPACE MANAGED BY DATABASE USING ( FILE '/data/db2/db2inst1/NODE0000/nav/user.dbf' 6400 ) AUTORESIZE YES MAXSIZE 500 M TEMPORARY TABLESPACE MANAGED BY DATABASE USING (
FILE '/data/db2/db2inst1/NODE0000/nav/temp.dbf' 6400 ) AUTORESIZE YES MAXSIZE 500 M;

Tip

The file size in the create database command is in pages; you cannot specify M or G for megabytes or gigabytes.

Adaptive self-tuning memory

Adaptive self-tuning memory, introduced with v9.1, removes the burden on the DBA to tune memory utilization. It is enabled, by default, for single partition databases. This allows DB2 to automatically distribute memory allocation for buffer pools, lock lists, package cache, and sort memory. For example, when less memory is required from buffer pools, it can be freed from buffer pools to allow more space for sort memory.

File and directory permission on database objects

When instance and database directory permissions are created by DB2, you should not modify any of those. With automatic storage, you would normally find the database files under the following directory hierarchy:

File and directory permission on database objects

Let's explain the directory hierarchy we just saw earlier:

UNIX links

You can define your containers or storage path in DB2 to point to a symbolic link. The operating system will follow it through. In this example, I moved a container but left a symbolic link to point to the new container location.

Use this carefully in sandbox environments first. This can be useful to get you out of a disk-based issue with minimum impact.

For example:

[db2inst1@nodedb21 ~]$ db2 connect to nav Database Connection Information Database server = DB2/LINUXX8664 9.7.4 SQL authorization ID = DB2INST1 Local database alias = NAV [db2inst1@nodedb21 ~]$ db2 quiesce database immediate DB20000I The QUIESCE DATABASE command completed successfully.

On the Linux command line, go to another filesystem, to which the instance owner has write access (/data1, in our case):

[db2inst1@nodedb21 ~]$ cd /data1

Create a directory to move a container to:

[db2inst1@nodedb21 data1]$ mkdir -p db2/db2inst1/NODE0000/nav

Go to this directory and copy the original container there:

[db2inst1@nodedb21 data1]$ cd db2/db2inst1/NODE0000/nav [db2inst1@nodedb21 nav]$ cp /data/db2/db2inst1/NODE0000/nav/nav_tbls.dbf

Go back to the original directory and rename the original container:

[db2inst1@nodedb21 data1]$ cd /data/db2/db2inst1/NODE0000/nav/ [db2inst1@nodedb21 nav]$ mv nav_tbls.dbf nav_tbls.dbf.scrap

Create a link:

[db2inst1@nodedb21 nav]$ ln -s /data1/db2/db2inst1/NODE0000/nav/nav_tbls.dbf nav_tbls.dbf 

Confirm link is done:

[db2inst1@nodedb21 nav]$ ls -al nav_tbls.dbf lrwxrwxrwx 1 db2inst1 dba 45 2011-07-01 16:29 nav_tbls.dbf -> /data1/db2/db2inst1/NODE0000/nav/nav_tbls.dbf 

Bring the database back on line:

[db2inst1@nodedb21 ~]$ db2 unquiesce database; DB20000I The UNQUIESCE DATABASE command completed successfully. 

If you query a table in that table space, the data will be there.

Make sure you use this feature wisely, as part of a well thought-out plan; otherwise, this introduces another level of complexity. You may want to use automatic storage instead.

Default codeset

The default codeset is UTF-8, except when defined otherwise. This cannot be changed after creation.

Territory

The default territory is US, except when defined otherwise. This cannot be changed after creation. The combination of the codeset and territory or locale values must be valid.

Collate using

The default setting is SYSTEM. Ensure this setting is compatible with codeset and territory. This cannot be changed after creation.

Control files

There are no equivalent commands to manipulate control files in DB2. In our example, you will find them in /data/db2/db2inst1/NODE0000/SQL00003/.

The following files reflect the equivalent of Oracle's control file information. These files should not be tampered with. db2rhist.asc and db2rhist.bak contain historic information about backups, restores, and other changes to the database. db2tschg.his contains a history of table space changes. For each log file, it contains information that helps to identify which table spaces are affected by the log file. This information is used for table space recovery. You can browse it with a text editor.

The log control files contain information about active logs. The files, SQLOGCTL.LFH.1 and its mirror copy, SQLOGCTL.LFH.1, are located, in our example, in /data/db2/db2inst1/NODE0000/SQL00003/SQLOGDIR, which contains the actual log files.

SQL00003 is a directory containing db2 configuration files for the NAV database. Other databases will be mapped to SQL0000x, according to the respective order of database creation. These log control files will be used by db2 when processing recovery, to determine the starting point in the logs to begin the recovery.

See also

  • Creating database from existing backup recipe in this chapter
  • Chapter 3, DB2 multipartitioned databases—Administration and Configuration
主站蜘蛛池模板: 成武县| 上蔡县| 行唐县| 措勤县| 济阳县| 阳东县| 吉安市| 武安市| 揭东县| 文山县| 望江县| 北辰区| 天全县| 曲阜市| 南陵县| 凌云县| 鸡西市| 宁蒗| 通渭县| 图们市| 潮安县| 苗栗市| 贺兰县| 成武县| 景德镇市| 虎林市| 华坪县| 探索| 婺源县| 黎川县| 偏关县| 长阳| 宁海县| 桦南县| 蒙山县| 图片| 灵台县| 黎川县| 奉化市| 策勒县| 双峰县|