Creating a Database

You can easily create a database using Control Center. In case you want to use a command, below is an example: (this is generated using CC):

CREATE DATABASE HELLOWLD AUTOMATIC STORAGE YES ON 'C:\DB2' ALIAS HWLD USING CODESET UTF-8 TERRITORY US WITH "To Learn DB2";
CONNECT TO HWLD;
CALL sysinstallobjects('policy', 'C', null, null);
--The following command uses the file C:\DB2\policy20071118224330.xml.
CALL POLICY_INSTALLOC('U', 'DB2CommonMED', 'NOP', 'CommonPolicy', 'C:\DB2\policy20071118224330.xml');
CONNECT RESET;
UPDATE DB CFG FOR HWLD USING AUTO_MAINT ON;
UPDATE DB CFG FOR HWLD USING AUTO_TBL_MAINT ON;
UPDATE DB CFG FOR HWLD USING AUTO_RUNSTATS ON;
UPDATE DB CFG FOR HWLD USING AUTO_REORG ON;
UPDATE DB CFG FOR HWLD USING AUTO_DB_BACKUP ON;
UPDATE ALERT CFG FOR DATABASE ON HWLD USING db.db_backup_req SET THRESHOLDSCHECKED YES;
UPDATE ALERT CFG FOR DATABASE ON HWLD USING db.tb_reorg_req SET THRESHOLDSCHECKED YES;
UPDATE ALERT CFG FOR DATABASE ON HWLD USING db.tb_runstats_req SET THRESHOLDSCHECKED YES;


Interesting enough, the command does not work. Below is the error:

SQL1052N The database path "C:\DB2" does not exist.

Explanation:

The path specified in the "" parameter of the command is not
valid. Either there is no path with that name, or a path has been
specified when the DB2_CREATE_DB_ON_PATHS registry variable is disabled
(Windows only).

In a partitioned database environment on Windows or UNIX environments,
each node in the partitioned database group must have the same hard
drive specification (path) available with usable space for the CREATE
DATABASE command to succeed. The hard drive path is specified in the
database manager configuration. If DFTDBPATH is left blank the default
will be the hard drive path where DB2 is installed on the instance
owning machine (db2 installation path).

The command cannot be processed.

User response:

Resubmit the command with the correct database path.

In a partitioned database environment on Windows or UNIX environments,
follow the following steps:
* Determine which hard drive specification (path) is required. The path
is specified in the error message.
* Determine which node/s of the database partition are experiencing the
problem. You can usually find this information in the db2diag.log
file of the instance owning node.
* Correct the drive problem on the node that is experiencing the
problem, or change the drive specification in the database manager
configuration so that the same drive is available and has sufficient
space on each node of the partitioned database group.
* Re-issue the command.
* On Windows if all applications that will access the database are
built on at least Version 9 external APIs then the
DB2_CREATE_DB_ON_PATHS environment variable can be enabled to support
a path as the database path.


The solution is simple, just change 'C:\DB2' to 'C:\' and it will work. The command creates the database in "C:\DB2\NODE0000\HELLOWLD" directory and not at the root. Looks like this is a smart database :-)

5 comments:

Unknown said...

(1) stop the database
(2) run db2set DB2_CREATE_DB_ON_CHANGE=YES
(3) start the database

this will allow you to create the database on the path you specify

Jon Mitchell said...

If I run
db2set DB2_CREATE_DB_ON_PATHS=YES
or
db2set DB2_CREATE_DB_ON_CHANGE=YES
from a command line I get the following:

DBI1302E Invalid parameter detected.

Explanation:

An invalid parameter was used.

User response:

Use the -? option for the usage help message.

What am I doing wrong? I'll try creating my db in c:\. Hopefully that will work.

Unknown said...

The parameter should read
db2set DB2_CREATE_DB_ON_PATH=YES and Not as
db2set DB2_CREATE_DB_ON_PATHS=YES

Unknown said...

Thank You, Thank You, Thank You. I was already near to throw DB2 because of this stupidity, can't create... because of path!!! Thank You, You save my soul, nervs, time and probably a few lives in IBM :)

Personalia R.M. Nova Sragen said...

Thank you