db2操作 连接、备份、恢复db2
先deactivate后再start standby再primary
报错不能启动hadr standby的时候,先restore,但是别rollback,直接start hadr as standby
先把hadr起来后再推icm
1、先把所有的库的hadr stop了
2、把primary的库离线备份
3、在副节点db2stop force ,再start(可以保证是处于deactivate(其实db2 DEACTIVATE DATABASE cinder就行)的状态,然后再restore)
4、db2 get db cfg for ceilodb2 | grep "Path to log files" 删除得到的文件夹里面所有文件比如得到node/ 就rm -rf node/*
5、在副节点restore(千万别rollback)
6、在副节点start hadr as standby
7、db2 ACTIVATE DATABASE cinder
8、在主节点start hadr as primary
db2默认需要切换到db2inst1这个默认用户才能执行操作
[root@localhost instance]# su - db2inst1
[db2inst1@localhost ~]$ db2start
[db2inst1@localhost ~]$ db2 force application all
[db2inst1@localhost ~]$ db2stop
[db2inst1@localhost DB2]$ db2stop force
显示所有的实例
[db2inst1@localhost ~]$ db2ilist
显示当前的实例
[db2inst1@localhost ~]$ db2 get instance
删除一个实例(注:需切换到root用户权限下)
[root@localhost ~]# cd /opt/ibm/db2/V9.7/instance
[root@localhost instance]# pwd
/opt/ibm/db2/V9.7/instance
[root@localhost instance]# ./db2idrop db2inst1
DBI1070I Program db2idrop completed successfully.
列出当前实例中有哪些数据库
[root@localhost instance]# su - db2inst1
[db2inst1@localhost ~]$ db2 list db directory
创建数据库
[root@localhost instance]# su - db2inst1
[db2inst1@localhost ~]$ db2 create database test
连接数据库
[db2inst1@localhost ~]$ db2 connect to test
注:用密码情况下格式[db2inst1@localhost ~]$ db2 connect to test user username using password
db2 connect to <database> user <username> using <password>
列出当前实例中所有激活的数据库
[root@localhost ~]# su - db2inst1
[db2inst1@localhost ~]$ db2 list active databases
查看表的空间
[db2inst1@localhost ~]$ db2 list tablespaces [ show detail ]
列出数据库中所有用户表
[db2inst1@localhost ~]$ db2 connect to test
[db2inst1@localhost ~]$ db2 list tables
创建表
[db2inst1@localhost ~]$ db2 "create table student (id int,fname varchar(30),age int)"
向表student中添加数据信息
[db2inst1@localhost ~]$ db2 "insert into student values (1,'Tom',22)"
显示表student所有的信息
[db2inst1@localhost ~]$ db2 "select * from student"
更新数据
[db2inst1@localhost ~]$ db2 "update student set age=22 where fname='Sunrier'"
查看表student结构
[db2inst1@localhost ~]$ db2 describe table student
[db2inst1@localhost ~]$ db2 "describe select * from student"
修改一个表的字段类型(如表people中的fname字段把varchar(30)改为varchar(28))
[db2inst1@localhost ~]$ db2 describe table people
[db2inst1@localhost ~]$ db2 "alter table people alter column fname set data type varchar(28)"
向一个表添加字段(如向表people中添加备注信息字段notes;向表people中添加分数字段score)
格式:db2 "alter table <tablename> add <columnname> <datatype>"
[db2inst1@localhost ~]$ db2 "alter table people add notes varchar(100)"
显示当前数据库连接有哪些应用程序
[root@localhost ~]# su - db2inst1
[db2inst1@localhost DB2]$ db2 list application
导出表中的数据
以DEL格式导出
db2 "export to teacher.txt of del select * from teacher"
db2 "export to teacher_bak.txt of del modified by coldel| select * from teacher"
[db2inst1@localhost ~]$ ls
db2inst1 sqllib Sunrier teacher.sql TEST.0.db2inst1.NODE0000.CATN0000.20120817103306.001
[db2inst1@localhost ~]$ db2 "export to teacher.txt of del select * from teacher"
SQL3104N The Export utility is beginning to export data to file
"teacher.txt".
备份数据库(如防止表误操作)
格式:db2 backup db <database name> [ to <dir name> ]
[db2inst1@localhost ~]$ db2 backup db test
SQL3105N The Export utility has finished exporting "2" rows.
恢复数据库(如将一个表删除后,通过删除前的备份文件恢复)
格式:db2 restore db <database name> [ from <dir name> ]
database name:表示恢复的数据库名
from <dir name>:表示为从哪个目录路径下恢复,为可选项,默认在当前目录下
[db2inst1@localhost ~]$ db2 connect to test
注:如果想把恢复的数据库更改为新的数据库名,则格式如下
db2 restore db <database name> [ from <dir name> into <new database name> ]
例:db2 restore db test from /home/db2inst1/Sunrier into testdb
或者db2 restore db test from "/home/db2inst1/Sunrier" into testdb
.查看test数据库备份的历史记录
格式:db2 list history backup all for <database name>
[db2inst1@localhost ~]$ db2 list history backup all for test
查看错误码信息
[db2inst1@localhost ~]$ db2 ? 22003
SQLSTATE 22003: A numeric value is out of range.
======================================back up ========================================
db2 list db directory
1、离线全备份
db2 force application all
1)、首先确保没有用户使用DB2:
db2 list applications for db sample
2)、停掉数据库并重新启动,以便断掉所有连接:
db2stop force
db2start
3)、执行备份命令:(使用TSM作为备份的介质)
db2 backup db sample use tsm
备份成功,将会返回一个时间戳。
4)、检查备份成功:
db2 list history backup all for sample 可以看到多了这个备份的纪录。
db2adutl query 命令也可以看到返回值。
5、恢复数据库
db2 restore db GLANCE from /var/wenbin/backup
当恢复后需要连接数据库的时候报错
Last login: Wed Jan 30 02:23:23 2013
[root@localhost ~]# su - db2inst1
[db2inst1@localhost ~]$ db2 connect to sample
SQL1117N A connection to or activation of database "SAMPLE" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
####这个提示是说需要前滚期间的日志才能激活数据库
执行下面的语句:
db2 rollforward db GLANCE to end of logs and stop
db2start
2.停止数据库
db2stop
3.连接数据库
db2 connect to o_yd user db2 using pwd
4.读数据库管理程序配置
db2 get dbm cfg
5.写数据库管理程序配置
db2 update dbm cfg using 参数名 参数值
6.读数据库的配置
db2 connect to o_yd user db2 using pwd
db2 get db cfg for o_yd
7.写数据库的配置
db2 connect to o_yd user db2 using pwd
db2 update db cfg for o_yd using 参数名 参数值
8.关闭所有应用连接
db2 force application all
db2 force application ID1,ID2,,,Idn MODE ASYNC
(db2 list application for db o_yd show detail)
9.备份数据库
db2 force application all
db2 backup db o_yd to d:
(db2 initialize tape on \\.\tape0)
(db2 rewind tape on \\.\tape0)
db2 backup db o_yd to \\.\tape0
10.恢复数据库
db2 restore db o_yd from d: to d:
db2 restore db o_yd from \\.\tape0 to d:
11.绑定存储过程
db2 connect to o_yd user db2 using pwd
db2 bind c:\dfplus.bnd
拷贝存储过程到服务器上的C:\sqllib\function目录中
12.整理表
db2 connect to o_yd user db2 using pwd
db2 reorg table ydd
db2 runstats on table ydd with distribution and indexes all
13.导出表数据
db2 export to c:\dftz.txt of del select * from dftz
db2 export to c:\dftz.ixf of ixf select * from dftz
14.导入表数据
import from c:\123.txt of del insert into ylbx.czyxx
db2 import to c:\dftz.txt of del commitcount 5000 messages c:\dftz.msg insert into dftz
import from vipmobiles.txt of del method p(1) insert into tgzvipmobiles(mobileno)
db2 import to c:\dftz.ixf of ixf commitcount 5000 insert into dftz
db2 import to c:\dftz.ixf of ixf commitcount 5000 insert_update into dftz
db2 import to c:\dftz.ixf of ixf commitcount 5000 replace into dftz
db2 import to c:\dftz.ixf of ixf commitcount 5000 create into dftz (仅IXF)
db2 import to c:\dftz.ixf of ixf commitcount 5000 replace_create into dftz (仅IXF)
db2 –tf 批处理文件名
(文件中每一条命令用 ;结束)
16.自动生成批处理文件
建文本文件:temp.sql
select ‘runstats on table DB2.’ || tabname || ‘ with distribution and detailed indexes all;’ from syscat.tables where tabschema=’DB2′ and type=’T';
db2 –tf temp.sql>runstats.sql
17.自动生成建表(视图)语句
在服务器上:C:\sqllib\misc目录中
db2 connect to o_yd user db2 using pwd
db2look –d o_yd –u db2 –e –p –c c:\o_yd.txt
18.其他命令
grant dbadm on database to user bb
20 db2look –d ylbx –u db2admin –w –asd –a –e –o a.txt21. 显示当前用户所有表
22.列出所有的系统表
23.查看表结构
db2 describe select * from user.tab
db2操作 连接、备份、恢复db2的更多相关文章
- RedHat安装DB2详细步骤(附卸载、备份恢复步骤)
1.创建用户组和用户 说明: 步骤1 以root用户登录需要安装DB2的服务器. 步骤2 创建用户组和用户. # su -root # groupdel db2grp # groupdel db2fg ...
- (转)Db2 备份恢复性能问题诊断与调优
原文:https://www.ibm.com/developerworks/cn/analytics/library/ba-lo-backup-restore-performance-issue-ju ...
- DB2备份恢复schema
场景:日常中开发同步生成环境或者环境切换都需要进行表结构.存储.数据等等的迁移,本文为表.视图.包.函数.存储等统一备份及恢复的操作. 备份: 登录数据库所在服务器,或者可远程连接需备份数据库的服务器 ...
- db2安装配置备份还原
环境 cenos 7.0 db2版本 db2_v101_linuxx64_expc.tar 安装db2 解压db2 tar zxvf db2_v101_linuxx64_expc.tar cd exp ...
- db2数据库的备份与还原
前言: 数据备份的重要性: 提高系统的高可用性和灾难可恢复性:(在数据库系统崩溃的时候,没有数据库备份怎么办!) 使用数据库备份还原数据库是数据库系统崩溃时提供数据恢复最小代价的最优方案:(总不能让客 ...
- DB2表空间重定向恢复数据库实战
DB2的备份恢复有点坑,当源系统和目标系统的路径设置不同时,要手动进行重定向恢复,本文是我一次实战操作之后总结的过程,仅供参考. 一.发出重定向恢复命令 DB2 RESTORE DB TO " ...
- db2的离线备份和还原
db2cmd中运行命令 1.做一个离线备份(db2cmd)mstsc—>db2cmd db2 connect to mydb #连接数据库 db2 lis ...
- MySQL基于mysqldump及lvmsnapshot备份恢复
一.备份对象 数据 配置文件 代码:存储过程,存储函数,触发器 跟复制相关的配置 二进制日志文件 二.备份工具 mysqldump:逻辑备份工具 InnoDB热备.MyISAM温备.Aria温备 备份 ...
- 删库到跑路?还得看这篇Redis数据库持久化与企业容灾备份恢复实战指南
本章目录 0x00 数据持久化 1.RDB 方式 2.AOF 方式 如何抉择 RDB OR AOF? 0x01 备份容灾 一.备份 1.手动备份redis数据库 2.迁移Redis指定db-数据库 3 ...
随机推荐
- Linux - 常用Shell快捷键
Common Shortcut Key 用途 快捷键 说明 光标移动 Ctrl + a 把光标移到行首 Ctrl + e 把光标移到行尾 Ctrl + x 在 EOL 和当前位置移动光标 输入编辑 C ...
- 将excel导入mysql(使用navicat)
excel: 注: 1.mysql里建立一张跟excel一样的表结构的表(包含id) 2.excel最好没有任何格式,只是纯值,不然会出现导入不了的错误 ----------------------- ...
- 使用aspose.cell动态导出多表头 EXCEL
效果图: 前台调用: using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...
- [Solution] NPOI操作Excel
NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目.使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 ...
- 图片轮播(淡入淡出)--JS原生和jQuery实现
图片轮播(淡入淡出)--js原生和jquery实现 图片轮播有很多种方式,这里采用其中的 淡入淡出形式 js原生和jQuery都可以实现,jquery因为封装了很多用法,所以用起来就简单许多,转换成j ...
- thread_Disruptor
转自 知乎 https://zhuanlan.zhihu.com/p/21355046 order从client端传入,decode后进行matching,一旦存在可成交的价格,就要publish到t ...
- 字符串 --- KMP Eentend-Kmp 自动机 trie图 trie树 后缀树 后缀数组
涉及到字符串的问题,无外乎这样一些算法和数据结构:自动机 KMP算法 Extend-KMP 后缀树 后缀数组 trie树 trie图及其应用.当然这些都是比较高级的数据结构和算法,而这里面最常用和最熟 ...
- 2015年百度之星初赛(1) --- F 矩形面积
矩形面积 Problem Description 小度熊有一个桌面,小度熊剪了很多矩形放在桌面上,小度熊想知道能把这些矩形包围起来的面积最小的矩形的面积是多少. Input 第一行一个正整数 T, ...
- 解决PL/SQL查询结果乱码的问题
首选查询oracle服务端的编码,然后将客户端NLS_LANG设置成和Oralce服务端一样的编码即可. 1.检查服务器编码: 执行SQL语法: select * from v$nls_paramet ...
- 大话设计模式-->模板方法设计模式
在学习java的过程中,我们肯定听到过设计模式这名词,在行业中有这么一句话,若您能熟练的掌握23种设计模式,那么你便是大牛! 好了,废话不多说,今天我跟大家分享一下23种设计模式之一的 模板方法 设 ...