DB2 简明运维手册
DB2最新维护手册
![DB2最新维护手册](https://img.taocdn.com/s3/m/b48279c308a1284ac850435f.png)
DB2维护手册目录DB2维护手册 (1)一、DB2入门-数据库实例 (5)二、DB2日常维护日操作 (20)1、检查管理服务器是否启动 (21)2、检查DB2实例是否已经启动 (21)3、查看表空间状态是否正常 (21)4、查看表的状态 (22)5、查看磁盘空间 (23)6、检查存储管理软件是否正常 (23)7、检查数据库备份是否正常 (24)8、检查归档日志是否正确归档了 (24)9、查看缓冲池的命中率 (24)10、查看当前运行最频繁的SQL,其命中率是否正常 (24)11、查看当前连接的应用程序,有没有非法连接 (25)12、检查有没有死锁 (25)13、对表和索引进行RUNSTATS (25)14、检查表是否需要重组 (25)15、对需要重组的表进行重组 (26)三、DB2日常维护月操作 (27)1、查看DB2日志 (27)2、检查备份和日志是否都保存好了 (27)四、DB2日常维护季度操作 (27)1、通过快照监控器,查看系统性能如何 (27)2、数据库补丁级别 (28)五、注意事项 (28)1、不要删除活动日志文件 (28)2、注意交易日志存储空间 (28)3、按照系统的实际工作量配置日志空间 (29)4、设置正确数据库代码页 (29)5、检查许可证(L ICENSE)安装情况 (30)6、创建数据库前调整好系统时间 (30)7、不要随便执行CHOWN (CHMOD)–R(UNIX/L INUX) (30)8、在归档日志模式下使用LOAD记得加NONRECOVERABLE参数 (31)六、附:以脱机方式重组表 (31)七、附:索引重组 (32)八、收集和更新统计信息的准则 (35)九、附:使用CLP 捕获数据库运行状况快照 (39)十、IBM DB2 日常维护汇总 (41)十一、DB2常用命令集 (51)一、DB2入门-数据库实例在本文中,我使用DB2 来指代DB2 通用数据库V8.1 for UNIX、Linux 和Windows。
IBM DB2 for z OS 版本12 8 2015 手册说明书
![IBM DB2 for z OS 版本12 8 2015 手册说明书](https://img.taocdn.com/s3/m/dd927c854128915f804d2b160b4e767f5acf80a1.png)
1. REXX program 2. JCL to execute the program 3. Sample spreadsheet that you can use for output data
With the advent of the System z13 processor that can support very large memory, customers and IBM account teams are wondering if there is a relatively quick and easy way to determine if larger memory would be suitable.
DB2: Setup BPOOL REXX
Systemபைடு நூலகம்Affected Recommendation Type
All but only done once ☐ Availability Performance ☐ Recovery ☐ Process ☐ Security
BPOOL REXX for DB2 for z/OS
Judy Ruby-Brown, DB2 zGrowth (ATS) Mark Rader, DB2 zGrowth (ATS)
Paul Fletcher (IMS and DB2 for z/OS Product Introduction Manager)
Go through the following DB2 recommendations using the references in the table of contents
db2数据库运维常用命令集
![db2数据库运维常用命令集](https://img.taocdn.com/s3/m/84d0805a767f5acfa1c7cdde.png)
db2数据库运维常用命令集在执行如下命令时,需要首先在客户端运行中输入db2cmd进行初始化或者su到db2的实例下操作。
一、常识性命令1、db2 connect to <数据库名> --连接到本地数据库名db2 connect to <数据库名> user <用户名> using <密码> --连接到远端数据库2、 db2 force application all --强迫所有应用断开数据库连接3、db2 backup db db2name<数据库名称> --备份整个数据库数据db2 restore db --还原数据库4、db2 list application --查看所有连接(需要连接到具体数据库才能查看)5、db2stop --停止数据库 db2start --启动数据库6、create database <数据库名> using codeset utf-8 territory CN --创建数据库使用utf-8编码7、db2 catalog 命令db2 catalog tcpip node <接点名称> remote <远程数据库地址> server <端口号> --把远程数据库映射到本地接点一般为50000db2 catalog db <远程数据库名称> as <接点名称> at node PUB11 --远程数据库名称到本地接点db2 CONNECT TO <接点名称> user <用户名> using <密码> --连接本地接点访问远程数据库8、数据库导出db2look -d <数据库名> -u <用户> -e -o <脚本名称>.sql --导出数据库的表结构,其中用户空间一般为db2admin/db2inst2db2look -d <数据库名> -u <用户> -t <表1> <表2> -e -o <脚本名称>.sql --导出数据库中表1和表2的表结构db2move <数据库名> export --导出数据库数据db2move <数据库名> export -tn <表1>,<表2> --导出数据库中表和表数据9、数据库导入db2 -tvf <脚本名称>.sql --把上述导出的表结构导入到数据库表结构db2move <数据库名> load -lo replace --把上述“db2move <数据库名> export “导出的数据导入到数据库中并把相同的数据替换掉在实际使用过程中,如果用到db2自增主键,需要使用by default,而不是always,功能是一样的,但这样在数据移植时候会很方便!10、db2 connect reset 或 db2 terminate --断开与数据库的连接11、db2set db2codepage=1208 --修改页编码为120812、db2 describe table <表名> --查看表结构13、db2 list tables --查看数据库中所有表结构db2 list tables for system --列出所有系统表14、db2 list tablespaces --列出表空间15、fetch first 10 rows only --列出表中前10条数据例如:select * from <表名> fetch first 10 rows only16、coalesce(字段名,转换后的值) --对是null的字段进行值转换例如:select coalesce(id,1) from <表名> --对表中id如果为null转换成1二、导入数据:1、以默认分隔符加载,默认为“,”号db2 "import from btpoper.txt of del insert into btpoper"2、以指定分隔符“|”加载db2 "import from btpoper.txt of del modified by coldel| insert into btpoper"三、卸载数据:1、卸载一个表中全部数据db2 "export to btpoper.txt of del select * from btpoper"db2 "export to btpoper.txt of del modified by coldel| select * from btpoper"2、带条件卸载一个表中数据db2 "export to btpoper.txt of del select * from btpoper wherebrhid='907020000'"db2 "export to cmmcode.txt of del select * from cmmcode where codtp='01'"db2 "export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp='01'"四、查询数据结构及数据:db2 "select * from btpoper"db2 "select * from btpoper where brhid='907020000' and oprid='0001'"db2 "select oprid,oprnm,brhid,passwd from btpoper"五、删除表中数据:db2 "delete from btpoper"db2 "delete from btpoper where brhid='907020000' or brhid='907010000'"六、修改表中数据:db2 "update svmmst set prtlines=0 where brhid='907010000' and jobtp='02'"db2 "update svmmst set prtlines=0 where jobtp='02' or jobtp='03'"七、联接数据库db2 connect to btpdbs八、清除数据库联接db2 connect reset 断开数据库连接db2 terminate 断开数据库连接db2 force applications all 断开所有数据库连接九、备份数据库1、 db2 backup db btpdbs2、 db2move btpdbs exportdb2look -d btpdbs -e -x [-a] -o crttbl.sql十、恢复数据库1、 db2 restore db btpdbs without rolling forward2、 db2 -tvf crtdb.sqlcrtdb.sql文件内容:create db btpdbs on /db2catalogdb2 -stvf crttbl.sqldb2move btpdbs import十一、DB2帮助命令:db2 ?db2 ? restroedb2 ? sqlcode (例:db2 ? sql0803) 注:code必须为4位数,不够4位,前面补0十二、bind命令:将应用程序与数据库作一捆绑,每次恢复数据库后,建议都要做一次bind(1) db2 bind br8200.bnd(2) /btp/bin/bndall /btp/bnd/btp/bin/bndall /btp/tran/bnd十三、查看数据库参数:db2 get dbm cfgdb2 get db cfg for btpdbs十四、修改数据库参数:db2 update db cfg for btpdbs using LOGBUFSZ 20db2 update db cfg for btpdbs using LOGFILSIZ 5120改完后,应执行以下命令使其生效:db2 stopdb2 start其他常用命令还有:db2 set schema btp 修改当前模式为"btp"db2 list tablespaces show detail 查看当前数据库表空间分配状况db2 list tablespace containers for 2 show detail 查看tablespace id=2使用容器所在目录db2 list applicationdb2 list db directory 列出所有数据库db2 list active databases 列出所有活动的数据库db2 list tables for all 列出当前数据库下所有的表db2 list tables for schema btp 列出当前数据库中schema为btp的表db2 list tablespaces show detail 显示数据库空间使用情况删除一个实例:# cd /usr/lpp/db2_07_01/instance# ./db2idrop InstName列出所有DB2实例:# ./db2ilist为数据库建立编目$ db2 catalog db btpdbs on /db2catalog取消已编目的数据库btpdbs$ db2 uncatalog db btpdbs查看版本# db2level显示当前数据库管理实例$ db2 get instance设置实例系统启动时是否自动启动。
DB2使用手册
![DB2使用手册](https://img.taocdn.com/s3/m/926be75be55c3b3567ec102de2bd960590c6d944.png)
DB2使⽤⼿册第⼀部分DB2系统管理命令1. Db2有域,实例,和数据库三层的概念。
2.查看数据库服务器中有⼏个数据库。
包括⽹络中数据库的引⽤。
进⼊数据库安装⽬录下的bin⽬录:C:\Program Files\IBM\SQLLIB\BIN执⾏db2 list database directory命令3.查看命令选项说明list command options4.查看运⾏的数据库服务器中关联了多少个引⽤程序对数据库的访问。
进⼊数据库安装⽬录下的bin⽬录:C:\Program Files\IBM\SQLLIB\BINdb2 list applications命令可以通过db2 force application(进程id) 杀死对应的进程。
5.如何强制断开应⽤程序和数据库的连接。
进⼊数据库安装⽬录下的bin⽬录:C:\Program Files\IBM\SQLLIB\BIN⾏下列的命令 db2 force applications 可以强制断开应⽤程序和数据库的连接。
6.如何备份数据库进⼊db2的操作环境,然后运⾏backup database 数据库别名 user ⽤户名 using 密码命令7.停⽌数据库的服务器。
进⼊数据库安装⽬录下的bin⽬录:C:\Program Files\IBM\SQLLIB\BIN或db2操作环境中,如果在db2操作环境中必须通过的db2 terminate命令终结db2操作环境中启动的所有⼦进程(即停⽌所有命令⾏处理器回话)再执⾏db2stop命令。
注意:在执⾏此命令的时候,必须没有应⽤程序或⽤户和数据库连接。
可以在执⾏停⽌命令之前查看于db2服务器连接的应⽤程序和⽤户。
然后执⾏牵制断开命令断开连接的数据库和⽤户。
8.如何从旧版本中把数据库迁移到新的安装版本中(在新版数据库种运⾏下列代码)1. 验证数据库是否可以被迁移。
⽤db2ckmig命令,db2ckmig /e 数据库别名 /l 验证信息保存路径 /u ⽤户名 /p 密码1. 执⾏数据库的迁移命令MIGRATE database 数据库别名 user ⽤户名 using 密码命令9.启动DB2服务器进⼊数据库安装⽬录下的bin⽬录:C:\Program Files\IBM\SQLLIB\BIN或db2操作环境中执⾏db2start命令10.关于命令⾏编辑器的使⽤使⽤命令⾏编辑器之前要连接到⼀个数据库。
DB2操作手册汇总
![DB2操作手册汇总](https://img.taocdn.com/s3/m/46cfd73376eeaeaad0f33017.png)
DB2数据库系统文档中创软件工程股份有限公司金融事业部二○○二年一月目录§ 1 DB2数据库的安装 (4)§2 配置环境变量和修改相应文件 (8)§2.1设置环境变量 (8)§2.2配置HACMP (9)§3 设计物理数据库 (12)§3.1数据在磁盘阵列上的存放原则 (12)§3.2具体的分布情况如下表所示 (12)§4 建立数据库 (13)§4.1建立BANK2数据库 (13)§4.2创建BANK2数据库的表空间 (13)§4.3创建UDF (14)§4.4建立数据库表 (15)§4.5验证创建的正确性 (17)§5 数据库参数调整 (18)§5.1日志参数 (18)§5.2修改共享内存 (19)§6 常用文件说明 (21)§7 常用命令 (23)§7.1常用管理命令 (23)§7.2常用SQL语句 (26)§8 附录 (27)§8.1数据库配置文件 (27)§8.2实例配置文件 (29)§8.3备份方案 (31)§8.3.1 数据库的备份 (31)§8.3.2使用BACKUP命令注意事项 (33)§8.3.3 数据库的恢复 (33)§ 1 DB2数据库的安装1.注册为具有超级用户权限的用户(root)2.将标有“DB2 UDB V7.1 for AIX”的软件光盘插入驱动器3.输入如下命令,以创建一个目录来安装该 CD-ROM:# mkdir -p /cdrom 其中 cdrom 表示 CD-ROM 安装目录。
输入如下命令,来分配 CD-ROM 文件系统:# smitty fs4.选择文件系统5.选择添加/更改/显示/删除文件系统6.选择CDROM 文件系统7.选择添加 CDROM 文件系统8.在弹出窗口中,输入如下项作为安装点:/cdrom9.通过输入以下命令来安装 CD-ROM 文件系统: smit mountf10.在文件系统名称字段中输入值。
DB2 Automation Tool v4.1 for z OS 自动化数据库维护指南说明书
![DB2 Automation Tool v4.1 for z OS 自动化数据库维护指南说明书](https://img.taocdn.com/s3/m/b03554edd0f34693daef5ef7ba0d4a7303766c72.png)
Automated End-to-End Database MaintenanceOctober 2011Automated End-to-EndDatabase MaintenanceHow to reduce your DB2 workloadand improve data availability usingDB2 Automation Tool v4.1 for z/OSJennifer NelsonProduct Specialist / Product ManagerRocket Software, Inc.C ONTENTSList of Figures (iii)1Today’s data challenges (1)2Automating database maintenance is the solution (1)2.1Conditional Maintenance (2)2.2Generate utility JCL automatically (4)2.3Using the DB2 administrative task scheduler to automatically executeutility JCL (8)3Evolve your strategy with an intelligent solution (12)References (xiii)L IST OF F IGURESFigure 1: Exceptions enable you to find what objects to include (2)Figure 2: Example - REORG exceptions (3)Figure 3: Integrating custom exceptions (4)Figure 4: Job Profiles are comprised of objects, exceptions and utilities (5)Figure 5: Build your Job Profile in batch or online (5)Figure 6: Automatically generating utility JCL (6)Figure 7: Result of batch Job Profile (6)Figure 8: Objects that match the exceptions are written to the TRIGGERS DD (7)Figure 9: Generated utility JCL contains only objects that match the exceptions (7)Figure 10: All utilities in the Utility Profile are generated into the utility JCL (8)Figure 11: DB2 Administrative Task Scheduler accessible via DB2 Automation Tool v4.1 (9)Figure 12: Adding JCL job to the scheduler (9)Figure 13: Generating JCL in DB2 Automation Tool and adding to Scheduler (10)Figure 14: Execute JCL at a specific time or during an interval (10)Figure 15: Utility JCL can also be added to the Scheduler (11)Figure 16: Schedule the resultant utility JCL with different parameters (12)1 Today’s data challengesAccording to industry experts, the amount of data is exploding in structured data, replicated data and unstructured data – all of which can be stored in a database such as DB2 forz/OS The amount of data stored in DB2 for z/OS is more than doubling every two years..At the same time, most DB2 for z/OS applications are global non-stop, requiring almost100% accessibility. These circumstances place heavy demands on the amount of timerequired to execute critical maintenance that, if not done, affects the performance of yourbusiness critical applications and your bottom line.Add to the challenge of exponential data growth, the current economic environment isshrinking the operational budgets of most companies. You need to justify each and everysoftware purchase. Companies are often operating with reduced IT staff dealing with anincreased workload. Maintaining optimal performance of your databases is as important to data application availability as ensuring a network remains online and available for non-stop business use. Database maintenance can be more time-consuming than you mightthink. Consider the following questions as they apply to your database maintenance:•Is your database maintenance routine? Routine database maintenance doesn’t mean that it is easy, quick or cost-effective.•Do you run a third party application? Often times, packaged vendor JCL is not optimized or timely. For example, your vendor JCL could use syntax that does notfollow best practices or routinely collect statistics, take an image copy or performREORGs on objects whether they’re needed or not.•What if an object doesn’t need specific maintenance, such as an image copy? Do you take one anyway just in case?•What if an object needs maintenance, but is either being skipped for maintenance or has the wrong maintenance run? Do you run the utility now, or do you wait untillater?•Will you be able to fit all of your critical maintenance jobs within the batch window?What happens if objects don’t have maintenance applied?•Is your maintenance process automated? How much time and effort is required by your staff?• Are there situations that require your DBA staff to interrupt other tasks to intervene and manage the maintenance window?2 Automating database maintenance is thesolutionCreating a strategy for running routine maintenance and automating that maintenance can help your DBA staff focus on more business critical tasks, while application data remainsavailable for business. The IBM DB2 Automation Tool for z/OS provides the solution toyour data maintenance challenges and moreover lets you have control of your objects,data availability and applications. It determines which objects need what maintenancewhen according to your business specifications. Using exception criteria to detect whichobjects or group of objects need what maintenance is an efficient way to locate only those objects in need; you no longer need to run packaged vendor utility JCL. With the DB2Automation Tool v4.1, exception jobs can be automatically run at intervals you determineby integrating with the DB2 Administrative Task Scheduler. By scheduling the exceptionjob to execute automatically at regular intervals to evaluate your objects, you will alwaysknow what objects need which maintenance. And, you will be able to automate executingthe utility jobs, eliminating any unnecessary DBA intervention. This paper will help anyone who is familiar with the DB2 Automation Tool learn how to use the DB2 AdministrativeTask Scheduler to fully automate database maintenance.2.1 Conditional MaintenanceWith over 180 exceptions, DB2 Automation Tool can help you find just those objects thatneed maintenance. Do you need to trigger an image copy only when certain conditionsoccur? Or do you need to trigger a reorg with a combination of conditions? The DB2Automation Tool Exceptions Profiles can help. Exception Profiles are simply a re-usablecollection of exceptions, or conditions, against which to evaluate objects. They can be used with any set of objects, called Object Profiles, to generate any kind of utility JCL.For example, the real time stats exceptions CLUSTERSENS and SCANACCESS can beused to evaluate when a REORG should take place. In the screen shot below, the column S contains an ‘A’ for the SCANACCESS exception, which is an AND condition. This means that both the CLUSTERSENS condition and the SCANACCESS condition must be metbefore the object will be included in the utility.Figure 1: Exceptions enable you to find what objects to include.Scrolling right will display an explanation of the exceptions, as shown below. With acomplete description of the exception conditions, you can make a comprehensive decision on which exceptions to set to trigger just the objects you need.Figure 2: Example - REORG exceptions.Select any combination of DB2 catalog statistics, SYSCOPY information, MVS catalog statistics, DB2 display status information or real time exception conditions to trigger just the objects that meet those criteria. Optionally, you can have the DB2 Automation Tool run a RUNSTATS utility to evaluate your object using current statistics. You can elect to store the new statistics by setting UPDATE to ALL, ACCESSPATH, or SPACE. You can also set UPDATE to NONE to enable only the Exception Profile to evaluate current statistics but not store those values in the catalog.The Automation Tool is also flexible enough to allow you to supply input that is not defined in the product. This can be a user-supplied formula, user-written REXX exec, assembled load module or stored procedure with your customized exceptions to evaluate against your objects. You provide the load module name, REXX exec name, or stored procedure name you want to execute as shown in the example below. The load module or REXX exec is loaded into memory once and called for each object within the associated Object Profile. The stored procedure can be called in three different ways, depending on what you want it to do and how you want it to process your objects. You may elect to process your stored procedure either before the DB2 Automation Tool exception criteria evaluation occurs, as the criteria and objects are being evaluated, or after the evaluation has completed. Enter your stored procedure name in the appropriate field where you want the DB2 AutomationTool to run the stored procedure.Figure 3: Integrating custom exceptions.Combine your own exceptions in a load module, REXX exec or stored procedure with any of the exceptions provided by DB2 Automation Tool to meet your needs. This level ofscalability and flexibility lets you tailor the DB2 Automation Tool to meet your company’sneeds.2.2 Generate utility JCL automaticallyThe DB2 Automation Tool can help with the frequency of when your objects are evaluated whether it’s once a week or daily for your business-critical objects. The DB2 AutomationTool can be executed as needed or placed in a scheduler to be executed at regularintervals with no intervention from the DBA.To generate utility JCL, a Job Profile must contain at least one Object Profile, which is a re-usable list of objects, and one Utility Profile, which is a list of utilities for which you want to generate JCL. This enables you to generate a utility for all objects within an Object Profile.But to conditionally generate utility JCL for only objects that meet or exceed exceptioncriteria, an Exception Profile must be added to the Job Profile. Using this method, you can easily generate utility JCL for only those objects that need maintenance, enabling you tosave on CPU consumption and reducing the amount of elapsed time required to runmaintenance, thus improving data availability.If, for example, you must take an image copy each week for just those objects that need it, you can re-run the Job Profile that contains the exception criterion for running an imagecopy and see which objects are generated into the utility JCL. That utility JCL can then be added to a job scheduler, such as the DB2 administrative task scheduler, to run during the next maintenance window.In this example below, the Job Profile contains three pieces of information: the ObjectProfile called “Reorg Avoidance Objs”, a set of utilities and corresponding options in aUtility Profile called “Reorg Avoidance Util”, and a set of exception criteria in an Exception Profile called “Reorg Avoidance Excp”.Figure 4: Job Profiles are comprised of objects, exceptions and utilities.In this example, the Job Profile “Batch Evaluation” is being generated to run in batch mode. This means that each time this Job Profile is “built”, a batch job will be created. This batch job, called REORGB, will evaluate the objects in the Object Profile against the exception criteria in the Exception Profile. Any object that matches the exceptions will be generatedinto the utility JCL, which is also created when running this batch job.Figure 5: Build your Job Profile in batch or online.The second pop-up window enables you to specify the PDS data set and member nameinto which the resultant utility JCL will be generated.Figure 6: Automatically generating utility JCL.The JCL to evaluate the objects is presented in an ISPF edit panel to review. It is this JCL that you can add to a scheduler to execute at regular intervals. By running this batch JCL job regularly, you can be sure that only those objects that need a REORG run will be included.Figure 7: Result of batch Job Profile.When the JCL is executed, DB2 Automation Tool evaluates the objects against the exceptions defined in the Exception Profile. In the screen shot below, the TRIGGERS DD in the job output lists the exceptions defined in the Exception Profile, and lists those objects that met or exceeded the defined exception. In this example, the tablespace AUOCOPY met both the CLUSTERSENS exception and the SCANACCESS exception and will therefore be included in the utility JCL.Figure 8: Objects that match the exceptions are written to the TRIGGERS DD.As a result, the utility JCL is built with the tablespace AUOCOPY included in the utility JCL.First, a RUNSTATS utility is generated, as shown in the screen shot below.Figure 9: Generated utility JCL contains only objects that match the exceptions.Further down in the utility JCL, the REORG TABLESPACE utility is generated and showstablespace AUOCOPY included in the REORG TABLESPACE utility as well. The utilitiesRUNSTATS and REORG TABLESPACE were inlcuded in the Utility Profile. Anycombination of the available DB2 utilities can be generated.Figure 10: All utilities in the Utility Profile are generated into the utility JCL.The resultant utility JCL can then be executed on demand, or added to a job scheduler to run during a specific batch window. Job Profiles can be created to build utility JCL fortaking image copies, for updating statistics, for running REORGs or for any other routinemaintenance your company requires.By running a Job Profile at regular intervals to look for objects that need maintenance and to generate utility JCL, routine database maintenance can be much less manual and error-prone and allow your DBA staff to pursue other tasks.2.3 Using the DB2 administrative task scheduler toautomatically execute utility JCLDo you have a job scheduler to run the Job Profiles or the resultant utility JCL in batch? Or do you manually run the utility JCL as needed? The generated utility jobs created by DB2 Automation Tool can be manually added to any job scheduler by the user. But if you arerunning on DB2 v8 or higher, you can now integrate DB2 Automation Tool v4.1 with theDB2 Administrative Task Scheduler and automatically execute any JCL. By selectingoption 12 from the main DB2 Automation Tool menu, you can invoke the Db2administrative task scheduler to add a job to the scheduler.Figure 11: DB2 Administrative Task Scheduler accessible via DB2 Automation Tool v4.1.From the DB2 Admin Task Scheduler panel, you can create a new batch job to execute during a specific time interval, view the results of a task that has already run, update atask, or delete a task.Figure 12: Adding JCL job to the scheduler.The benefit of integrating with the DB2 administrative task scheduler is when you buildyour Job Profile as shown in the screen shot below.Figure 13: Generating JCL in DB2 Automation Tool and adding to Scheduler.When building your Job Profile that evaluates exceptions and generates maintenance utility JCL, the options ‘Schedule Job’ and ‘Update Options’ enables you to add your Job Profile to the DB2 administrative task scheduler so that it will run at regular intervals, or just once; which ever method you choose.In the example below, the Job Profile “Batch Evaluation” is being added to the DB2 administrative task scheduler. The options presented on this panel are specific to the DB2 administrative task scheduler, and their descriptions can be found in the DB2 Administration Guide.The fields Begin Timestamp and End Timestampe enable you to define the exact time you want to execute this JCL. However, since we want this Job Profile to run at regular intervals, the Interval Options have been defined instead. This batch JCL will execute every Saturday of the month throughout the year at 12 noon to evaluate the objects in the corresponding Object Profile that need a RUNSTATS and a REORG run.Figure 14: Execute JCL at a specific time or during an interval.The values in the Point in Time fields are:Position 1: Minute. Valid values are 0 through 59.Position 2: Hour. Valid values are 1 through 23.Position 3: Day of the Month. Valid values are 1-31.Position 4: Month. Valid values are 1 through 12, where 1 is January. Three-character strings are also allowed, i.e., JAN, FEB, etc.Position 5: Day of the week. Valid values are 0 through 7, where 0 or 7 is Sunday. Three-character strings are also allowed, i.e., SUN, SAT, etc.Ranges and lists are allowed. Ranges are simply two values separated by a hyphen, and mean all values are inclusive. Lists are simply two or more values separated by a comma, and mean only those values are included.When you have completed adding the Job Profile to the DB2 administrative task scheduler, you can then add the utility JCL jobs to the DB2 administrative task scheduler, too. You will see the same 2 options as before, ‘Schedule Job’ and ‘Update Options’.Figure 15: Utility JCL can also be added to the Scheduler.When the panel Schedule DB2 Admin Task is displayed, you will specify when the resultant maintenance utility JCL should be run. Remember that the previous DB2 admin task panel enabled you to define when to run the Job Profile that evaluates your obejcts against the exception criteria and generates utility JCL. This time, you are defining when to run the actual utilities themselves.In this example, the generated maintenance utility jobs will run between the hours of midnight and 3 AM each Sunday. The field ‘Exectution Threads’ specifies that up to 5 jobs can run at once.Figure 16: Schedule the resultant utility JCL with different parameters.3 Evolve your strategy with an intelligentsolutionThe maintenance utility jobs that were generated by DB2 Autiomation Tool can now bescheduled and automatically run with DB2 Automation Tool’s interface to the DB2administrative task scheduler. Now, you can automate your database maintenancestrategy with DB2 Automation Tool from start to finish; from finding which objects to include to generating and submitting utility JCL. And your DBA intervention can be reduced to aminimum, allowing you to spend your time on other business critical tasks, while stillrunning important database maintenance in the background. The combination of DB2Automation Tool v4.1 for z/OS and the DB2 Administrative Scheduler allow you to fullyautomate your database maintenance to achieve maximum control and availability of your critical DB2 objects, while minimizing the system and staff resources that cost you time andmoney.R EFERENCESIBM DB2 Automation Tool for z/OS v4.1 User’s Guide, SC19-3494-00IBM DB2 Version 9.1 for z/OS Administration Guide, SC18-9840-00IBM DB2 10 for z/OS Administration Guide, SC19-2968-00®© Copyright IBM Corporation 2011IBM United States of AmericaProduced in the United States of AmericaAll Rights ReservedThe e-business logo, the eServer logo, IBM, the IBM logo,OS/390, zSeries, SecureWay, S/390, Tivoli, DB2, Lotus and WebSphere are trademarks of International Business Machines Corporation in the United States, other countries or both.Lotus, Lotus Discovery Server, Lotus QuickPlace, Lotus Notes, Domino, and Sametime are trademarks of Lotus Development Corporation and/or IBM Corporation.Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in the United States, other countries or both.Other company, product and service names may be trademarks or service marks of others.INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PAPER “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. Information in this paper as to the availability of products (including portlets) was believed accurate as of the time of publication. IBM cannot guarantee that identified products (including portlets) will continue to be made available by their suppliers.This information could include technical inaccuracies or typographical errors. Changes may be made periodically to the information herein; these changes may be incorporated in subsequent versions of the paper. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this paper at any time without notice. Any references in this document to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk.IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to:IBM Director of LicensingIBM Corporation4205 South Miami BoulevardResearch Triangle Park, NC 27709 U.S.A.。
DB2手册
![DB2手册](https://img.taocdn.com/s3/m/8c9f8533e2bd960590c67797.png)
1前言 (7)2DB2专有名词解释 (7)2.1I NSTANCE(实例) (7)2.2DB2A DMINISTRA TION S ERVER(管理服务器) (7)2.3C ONTAINER(容器) (7)2.4DRDA (7)2.5DARI (7)2.6SPM (7)2.7FCM (7)2.8ADSM (7)2.9DCE (7)3DB2编程 (8)3.1建存储过程时C REATE 后一定不要用TAB键 (8)3.2使用临时表 (8)3.3从数据表中取指定前几条记录 (8)3.4游标的使用 (9)3.5类似DECODE的转码操作 (9)3.6类似CHARINDEX查找字符在字串中的位置 (10)3.7类似DATEDIF计算两个日期的相差天数 (10)3.8写UDF的例子 (10)3.9创建含IDENTITY值(即自动生成的ID)的表 (10)3.10预防字段空值的处理 (10)3.11取得处理的记录数 (10)3.12从存储过程返回结果集(游标)的用法 (11)3.13类型转换函数 (12)3.14存储过程的互相调用 (12)3.15C存储过程参数注意 (12)3.16存储过程FENCE及UNFENCE (12)3.17SP错误处理用法 (12)3.18V ALUES的使用 (13)3.19给SELECT 语句指定隔离级别 (13)3.20A TOMIC及NOT A TOMIC区别 (13)3.21C及SQL存储过程名称都要注意长度 (13)3.22怎样获得自己的数据库连接句柄 (13)3.23类似于ORACLE的N AME PIPE (14)3.24类似于ORACLE的TRUNCATE清表但不记日志的做法 (14)3.25用CLI编程批量的INSERT (14)4DB2一些不好的限制 (17)4.1临时表不能建索引 (17)4.2CURSOR不能定义为WITH UR(可以但...) .. (17)4.3CURSOR ORDER BY以后不能FOR UPDATE (17)4.4程序中间不能自由改变隔离级别 (17)4.5UPDATE 不能用一个表中的记录为条件修改另一个表中的记录。
《db2基础操作手册》PPT课件
![《db2基础操作手册》PPT课件](https://img.taocdn.com/s3/m/710ed2eb67ec102de3bd8934.png)
Y
Pred1和Pred2都是可索引的,指相同索引的列
N
除了(c1=a or c1=b)外,他可以被认为是c1 in(a,b)
Not Pred1
N
或者任何的等价形式:Not between,Not in,Not like等等。
28
29 数据约束
数据库中数据的完整性或有效性极其重要。确保插入数据库的数据的有效性非常困难 ,DB2 提供了定义某些可并入数据库的基于规则的约束或检查的能力。在 DB2 中,可 使用以下检查来最小化将错误数据插入表中的风险:
设置 Db2 update dbm cfg using param value Db2 update db cfg for db_name using param value
11
12 连接到数据库
服务器端配置
设置db2 profile registry的参数DB2COMM,如: Db2set db2comm=tcpip
null],..)
• 根据已有的表创建新表:
A:create table tab_new like tab_old B:create table tab_new as select col1,col2… from tab_old definition only
24
25
表空间
三种表空间
常规表空间 长表空间 临时表空间
8
9 Db2 profile registries
可以设置不同的级别
Instance/global/user/
instance node/instance profile
使用db2set命令,可以显示,修改,删除
db2set –all显示所有设置的
某工商局DB2Q复制配置维护手册范本
![某工商局DB2Q复制配置维护手册范本](https://img.taocdn.com/s3/m/c11adc2c011ca300a6c39068.png)
1、Q复制规划1.1主机和DB2的相关设置信息logging模式(归档日志模式)1.2Websphere MQ的相关配置信息1.3Q复制的配置信息1.4复制队列映射属性1.5通道测试cd /usr/mqm/samp/bin./amqsput SYSA.SENDQ QMSYSA./amqsget SYSB.RECVQ QMSYSB2、mq用户创建创建用户mqm和组mqm,并把组mqm加入到用户db2inst1和db2fenc1中。
3、mq software install解压缩mq软件,用smitty installp安装,创建大小50G的mqmvg 、mqmlv和文件系统mqm,挂载点/var/mqm,/var/mqm/log4、mq 队列和通道创建在dbsvr04上执行setclock dbsvr01进行与dbsvr01的时间同步,需要在/etc/hosts中添加dbsvr01和IP。
由于MQ的需要在dbsvr01和dbsvr04中/etc/hosts添加相互的IP和name 信息。
Service ip 和 service name 也要添加。
Dbsvr04:/etc/hosts:10.0.1.41 dbsvr0110.0.1.44 dbsvr0410.0.1.45 dbserver //hacmp 中service IPMQ测试:Dbsvr01:$ crtmqm -q venus.queue.managerWebSphere MQ queue manager created.Creating or replacing default objects for venus.queue.manager.Default objects statistics : 58 created. 0 replaced. 0 failed. Completing setup.Setup completed.$ strmqmWebSphere MQ queue manager 'venus.queue.manager' starting.5 log records accessed on queue manager 'venus.queue.manager' during the log replay phase.Log replay for queue manager 'venus.queue.manager' complete. Transaction manager state recovered for queue manager 'venus.queue.manager'.WebSphere MQ queue manager 'venus.queue.manager' started.$ runmqsc5724-H72 (C) Copyright IBM Corp. 1994, 2008. ALL RIGHTS RESERVED. Starting MQSC for queue manager venus.queue.manager.define qlocal (orange.queue)1 : define qlocal (orange.queue)AMQ8006: WebSphere MQ queue created.end2 : endOne MQSC command read.No commands have a syntax error.All valid MQSC commands were processed.$ cd /usr/mqm/samp/bin/$ ./amqsput ORANGE.QUEUESample AMQSPUT0 starttarget queue is ORANGE.QUEUEabcddsfsdsdfdsenddbsvr04:$ crtmqm -q venus.queue.managerWebSphere MQ queue manager created.Creating or replacing default objects for venus.queue.manager.Default objects statistics : 58 created. 0 replaced. 0 failed. Completing setup.Setup completed.$ $ strmqmWebSphere MQ queue manager 'venus.queue.manager' starting.5 log records accessed on queue manager 'venus.queue.manager' during the log replay phase.Log replay for queue manager 'venus.queue.manager' complete. Transaction manager state recovered for queue manager'venus.queue.manager'.WebSphere MQ queue manager 'venus.queue.manager' started.$ runmqsc5724-H72 (C) Copyright IBM Corp. 1994, 2008. ALL RIGHTS RESERVED. Starting MQSC for queue manager venus.queue.manager.define qlocal (orange.queue)1 : define qlocal (orange.queue)AMQ8006: WebSphere MQ queue created.:::end2 : endOne MQSC command read.No commands have a syntax error.All valid MQSC commands were processed.$ cd /usr/mqm/samp/bin$ ./amqsput ORANGE.QUEUESample AMQSPUT0 starttarget queue is ORANGE.QUEUEadsfsdfdsfsdfsdfsSample AMQSPUT0 end$$ ./amqsget ORANGE.QUEUESample AMQSGET0 startmessage <adsfsdfdsfsdfsdfs>dbsvr01:crtmqm -lc -d SYSA.XMITQ -u DEADLETTER -lp 20 -ls 10 -lf 10240 QMSYSA //创建MQ队列strmqm QMSYSA //起队列管理器endmqlsr -m QMSYSA //停队列管理器ps -ef | grep mq //查看队列管理器nohup runmqlsr -t tcp -p 1453 -m QMSYSA & //起监听ps –ef|grep lsr // 查看监听进程endmqm QMSYSA //停队列endmqlsr //停监听dltmqm QMSYSA //删除管理队列runmqsc QMSYSA //起MQ资源DEFINE QREMOTE('SYSA.SENDQ') RNAME('SYSB.RECVQ') RQMNAME('QMSYSB') XMITQ('SYSA.XMITQ')DEFINE QLOCAL('SYSA.XMITQ') USAGE(XMITQ) MAXDEPTH(1000000) DEFPSIST(YES)DEFINE QLOCAL('DEADLETTER') USAGE(NORMAL) MAXDEPTH(500000)ALTER QMGR DEADQ('DEADLETTER')DEFINE CHL ('SYSAtoSYSB') CHLTYPE(SDR) TRPTYPE(TCP) CONNAME('10.0.1.44(1454)') XMITQ('SYSA.XMITQ') DISCINT (0) BATCHSZ (200)START CHANNEL ('SYSAtoSYSB')DEFINE CHL ('SYSBtoSYSA') CHLTYPE(RCVR) TRPTYPE(TCP) BATCHSZ(200)DEFINE QLOCAL('SYSA.ADMINQ') MAXDEPTH(500000) DEFPSIST(YES)DEFINE QLOCAL('SYSA.RESTARTQ') MAXDEPTH(500000) DEFPSIST(YES)End*************************runmqsc QMSYSAdis chstatus('SYSAtoSYSB') //显示running 通道状态正常dis chstatus('SYSAtoSYSB')1 : dis chstatus('SYSBtoSYSA')AMQ8417: Display Channel Status details.CHANNEL(SYSBtoSYSA) CHLTYPE(RCVR)CONNAME(10.0.1.44) CURRENTRQMNAME(QMSYSB) STATUS(RUNNING)SUBSTATE(RECEIVE)dis chstatus('SYSBtoSYSA')2 : dis chstatus('SYSBtoSYSA')AMQ8417: Display Channel Status details.CHANNEL(SYSBtoSYSA) CHLTYPE(RCVR)CONNAME(10.0.1.44) CURRENTRQMNAME(QMSYSB) STATUS(RUNNING)SUBSTATE(RECEIVE)*************************runmqsc QMSYSBdis chstatus('SYSBtoSYSA')runmqchl -c SYSAtoSYSB -m QMSYSA //如果没有错误信息显示,表明该channel成功运行runmqchl -c SYSBtoSYSA -m QMSYSA //如果没有错误信息显示,表明该channel 成功运行********************************修改queue manager的CCSID:strmqmrunmqscdisplay qmgr // 检查当前queue manager的CCSID值alter qmgr ccsid(437)end*************************dbsvr04:crtmqm -lc -d SYSB.XMITQ -u DEADLETTER -lp 20 -ls 10 -lf 10240 QMSYSB strmqm QMSYSBnohup runmqlsr -t tcp -p 1454 -m QMSYSB &runmqsc QMSYSBDEFINE QLOCAL('SYSB.RECVQ') MAXDEPTH(1000000) DEFPSIST(YES)DEFINE QREMOTE('SYSA.ADMINQ') RNAME('SYSA.ADMINQ') RQMNAME('QMSYSA') XMITQ('SYSB.XMITQ')DEFINE QLOCAL('SYSB.XMITQ') MAXDEPTH(1000000) USAGE(XMITQ) DEFPSIST(YES)DEFINE QLOCAL('DEADLETTER') USAGE(NORMAL) MAXDEPTH(500000)ALTER QMGR DEADQ('DEADLETTER')DEFINE CHL ('SYSBtoSYSA') CHLTYPE(SDR) TRPTYPE(TCP) CONNAME('10.0.1.45(1453)') XMITQ('SYSB.XMITQ') DISCINT (0) BATCHSZ (200)START CHANNEL ('SYSBtoSYSA')DEFINE CHL ('SYSAtoSYSB') CHLTYPE(RCVR) TRPTYPE(TCP) BATCHSZ(200)DEFINE QMODEL('IBMQREP.SPILL.MODELQ') DEFSOPT(SHARED) MAXDEPTH(1000000) MSGDLVSQ(FIFO) DEFTYPE(PERMDYN)end****************************nohup runmqlsr -t tcp -p 1454 -m QMSYSB & //起监听runmqsc QMSYSBdis chstatus('SYSBtoSYSA') //显示running 通道状态正常dis chstatus('SYSBtoSYSA')dis chstatus('SYSAtoSYSB')1 : dis chstatus('SYSAtoSYSB')AMQ8417: Display Channel Status details.CHANNEL(SYSAtoSYSB) CHLTYPE(RCVR)CONNAME(10.0.1.45) CURRENTRQMNAME(QMSYSA) STATUS(RUNNING)SUBSTATE(RECEIVE)dis chstatus('SYSBtoSYSA')2 : dis chstatus('SYSBtoSYSA')AMQ8417: Display Channel Status details.CHANNEL(SYSBtoSYSA) CHLTYPE(SDR)CONNAME(10.0.1.45(1453)) CURRENTRQMNAME(QMSYSA) STATUS(RUNNING)SUBSTATE(MQGET) XMITQ(SYSB.XMITQ)EN)*********************************************修改队列管理器中的字符集命令:首先打开命令行窗口。
0300_DB2运维
![0300_DB2运维](https://img.taocdn.com/s3/m/5d20e811866fb84ae45c8d5e.png)
数据库备份
• 例子:
BACKUP DATABASE sample ONLINE TO /backup INCLUDE LOGS 对数据库sample进行数据库和日志的在线备份 OFFLINE为默认模式,因此在线必须指明ONLINE INCLUDE LOGS选项只适用于ONLINE
表空间备份
• 例子:
数据库备份
• 语法:
BACKUP DATABASE database-alias [USER username [USING password]] [TABLESPACE (tblspace-name [{,tblspacename} ... ])][ONLINE][INCREMENTAL [DELTA]] [USE {TSM | XBSA} [OPEN num-sess SESSIONS][OPTIONS {options-string | options-filename}]] [WITH num-buff BUFFERS] [BUFFER buffer-size] [PARALLELISM n] [COMPRESS [COMPRLIB libname [EXCLUDE]] [COMPROPTS options-string]][UTILPRIORITY [priority] [{INCLUDE |EXCLUDE} LOGS] [WITHOUT PROMPTING]
IMPORT的命令 • IMPORT FROM filename OF filetype [LOBS lob[{,lobFROM lob-path [{,lob-path}...]] [ALLOW filetypeNO/WRITE ACCESS] [MODIFIED BY filetype[{filetypemod [{filetype-mod}...]] [MESSAGES messagemessage-file][COMMITCOUNT n/AUTOMATIC] [RESTARTCOUNT n]insert_createn]insert_create-statment
中国移动DB2数据库安全配置手册.doc
![中国移动DB2数据库安全配置手册.doc](https://img.taocdn.com/s3/m/e3b876f30508763231121249.png)
密级:文档编号:项目代号:中国移动DB2数据库安全配置手册Version 1.0中国移动通信有限公司二零零四年拟制: 审核: 批准: 会签: 标准化:版本控制分发控制目录第一章目的与范围 (1)1.1目的 (1)1.2适用范围 (1)1.3数据库类型 (1)第二章数据库安全规范 (1)2.1操作系统安全 (1)2.2帐户安全 (2)2.3密码安全 (2)2.4访问权限安全 (2)2.5日志记录 (2)2.6加密 (3)2.7管理员客户端安全 (3)2.8安全补丁 (3)2.9审计 (3)第三章数据库安全配置手册 (4)3.1DB2数据库安全配置方法 (4)3.1.1 基本漏洞加固方法 (4)3.1.2 特定漏洞加固方法 (10)第四章附录:数据库安全问题及解决方案 (13)4.1数据库安全问题 (13)4.1.1 数据安全基本需求 (13)4.1.2 数据安全风险 (15)4.1.3 业界采用的安全技术 (17)1.1.4DB2的安全解决之道 (18)4.2DB2安全解决方案–提供端到端的安全体系结构 (19)4.2.1 DB2 安全机制 (19)4.2.2 托管环境的安全 (21)4.2.3 网络中的安全——基于标准的公共密钥体系结构(PKI) (21)4.2.4 先进的用户和安全策略管理 (23)第一章目的与范围1.1 目的为了加强中国移动集团下属各公司的网络系统安全管理,全面提高中国移动集团下属各公司业务网和办公网的网络安全水平,保证网络通信畅通和信息系统的正常运营,提高网络服务质量,特制定本方法。
本文档旨在于规范中国移动集团下属各公司对DB2数据库进行的安全加固。
1.2适用范围本手册适用于对中国移动集团下属各公司业务网和办公网系统的数据库系统加固进行指导。
1.3数据库类型数据库类型为DB2 EEE。
第二章数据库安全规范2.1 操作系统安全要使数据库安全,首先要使其所在的平台和网络安全。
然后就要考虑操作系统的安全性。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DB2 简明运维手册
数据库启动
数据库正常启动的流程包括两个步骤,
首先启动数据库实例,在root用户下切换到实例用户su - db2inst1,执行命令db2start
然后激活对应的数据库,执行命令: db2 activate db 数据库名。
直到出现:
则数据库成功启动。
数据库停止
停止数据库使用如下命令:
在root用户下切换到实例用户su - db2inst1,执行命令db2stop force,
直到出现:
则数据库停止成功。
数据库参数
DB2的参数分为实例级参数和数据库级参数,以及实例注册变量
实例级参数:
主要设置实例使用的TCP/IP端口,查看实例端口通过命令:db2 get dbm cfg
数据库实例注册变量:
确认设置了通信协议为TCPIP,命令如下:
如果没有设置则通过命令db2set DB2COMM=tcpip进行设置。
数据库参数
确认内存自动调整已经打开,
否则连接到数据库并执行db2 update db cfg for sample using
SELF_TUNING_MEM ON设置
数据库的缺省日志参数为
如果需要修改日志参数,可以通过命令
db2 udpate db cfg for 数据库名using 参数名参数值
例如增大备用日志文件数量到50,则可以通过命令修改
创建数据库
在实例用户下,执行
db2 "create <数据库名> on <目标路径> using codeset UTF-8 territory cn"
这样创建的数据库缺省页面大小(pagesize)为4K(4096),字符集为UTF-8,如果要使用GBK字符集,则把UTF-8修改为GBK即可。
创建缓冲池(bufferpool)
为了使用与缺省页面大小不一致的表空间,例如缺省页面大小为4K,但是需要使用32K页的表空间,就必须先创建页面大小为32K的缓冲池,命令如下:db2 "create bufferpool bp32k pagesize 32768"
bp32k为缓冲池的名字,通常每种页面大小创建一个缓冲池即可,例如8K页面的缓冲池可以命名为bp8k。
缓冲池缺省为自动调整大小,如果需要限定使用内存,则使用alter命令,如下:
db2 "alter bufferpool bp32k size <页面数量> "
<页面数量>为目标内存大小/页面大小,例如要为32K的bufferpool分配2GB内存,则:
<页面数量>=2 * 1024 * 1024 / 32 = 65536
创建表空间
如果创建数据库默认页面大小的表空间,并且选择系统自动管理的模式,则使用命令:
db2 "create tablespace <表空间名>"
以创建32K页面大小为例,假定已经存在32K的缓冲池bp32k。
创建自动存储管理的表空间,使用命令:
db2 "create tablespace <表空间名> pagesize 32768 bufferpool bp32k"
如果要指定使用文件系统,例如/db2data/tbs_1.dat作为容器,则使用命令:
db2 "create tablespace <表空间名> pagesize 32768 bufferpool bp32k managed by database using (file '/db2data/tbs_1.dat' 10G) "
默认表空间都是自动增长的方式,如果需要限定表空间使用的最大空间,则使用命令:
db2 "alter tablespace <表空间名> maxsize 20G"
以上为创建正常数据表空间。
创建系统临时表空间命令:
db2 "create system temporary tablespace tbs_sys_tmp pagesize 32768 bufferpool bp32k"
创建用户临时表空间命令(在存储过程中定义临时表的话需要用户临时表空间):db2 "create user temporary tablespace tbs_sys_tmp pagesize 32768 bufferpool bp32k"
数据库备份
脱机备份:
需要先停库,然后备份,
db2 "force application all"
db2 deactivate db <数据库名>
db2 "backup db <数据库名> to <目标目录>
联机备份
联机备份需要数据库的日志为归档模式,可以通过查看数据库日志确认是否为联机备份模式
db2 backup db <数据库名> online to <目录>
在备份目录下将生成备份的文件,例如:
SAMPLE.0.DB2.DBPART000.20130326105907.001
数据库恢复
db2 restore <数据库名> from <目录> taken at <时间戳>
上述命令中,<目录>为存放备份文件的位置,<时间戳>为备份文件的第5段信息,例如备份文件名为:
SAMPLE.0.DB2.DBPART000.20130326105907.001
则时间戳为20130326105907。
如果DB2数据库日志模式为归档模式,那么DB2数据库的状态将处于Rolling forward Pending状态,需要进行前滚并终止。
db2 rolling forward db <数据库名> to end of logs and complete.
对于更加复杂的备份恢复情况,请查看DB2信息中心。
数据库全库导出(逻辑备份)和迁移
创建一个目录,例如/db2export,确保实例用户有读写权限,然后cd到该目录下,使用命令:
db2move <数据库名> export -u <用户名> -p <密码>
<用户名>和<密码>为访问数据库的用户和密码。
数据库可以是在本地,也可以是在远端。
导出数据库所有的对象(表、视图、索引、存储工程等)定义(DDL)
db2look -d <数据库名> -e -t <数据库名>.ddl
迁移到新的数据库
将上述导出的数据库目录上传到目标新数据库服务器上,并cd到该目录下,先导入数据并自动创建表
db2move <数据库名> import
这个过程将自动创建表并记录日志,因此要注意设置较大的日志参数,通常可以修改LOGSEND参数为较大值,(LOGPRIMARY+LOGSECOND)*LOGFILSIZ即为总日志大小,必须大于最大的单表大小。
否则import将失败。
数据导入后再创建数据库中的对象
db2 -tvf <数据库名>.ddl
然后更新统计信息
db2 "export to runstats.sql of del modified by nochardel select 'runstats on table ' || trim(tabschema) || '.' || trim(tabname) || ';' from syscat.tables where tabschema not in ('SYSCAT','SYSIBM','SYSIBMADM','SYSSTAT','SYSTOOLS') and type <> 'V'"; db2 -tvf runstats.sql
单表数据导出导入
数据导出为逗号分割的文本文件可以用命令:
db2 "export to <文件名> of del select * from <表名>"
导入数据
db2 "import from <文件名> of del replace into <表名>
上面为清空表后导入数据,如果是追加导入,则:
db2 "import from <文件名> of del insert into <表名>
数据库故障
出错时需要记录的信息:
当数据库发生异常错误时,将出错信息记录下来,或者进行截屏保存。
查看数据库实例级错误信息日志,日志文件位于数据库实例用户目录下sqllib/db2dump/db2diag.log。
并联系IBM技术支持电话:
800-810-1818
400-810-1818
需要提供客户代码。
常见错误处理:
最常见的错误是Transaction Log is Full即数据库日志满了,处理方法是根据交易涉及的数据量大小适当增大数据库日志,修改db2 update db cfg for 数据库名using LOGSECOND 50。
如果大部分交易的日志量都超过了LOGPRIMARY 参数,则增大LOGPRIMARY参数值。