日志:物理日志,逻辑日志(两者的的默认大小不合理)
设置物理/逻辑日志:
显示日志信息:onstat -l
物理日志:保存数据的前映象
逻辑日志:保存数据库的变化(现在的数据库都是先写日志数据库)
设置物理日志:默认保存在rootdbs中,创建新的表空间,更改物理日志到新的位置
mkdir -p /disk/sdb6/dbs
chown informix:informix /disk/sdb6/dbs
touch /disk/sdb6/dbs/phydbs
chmod 660 /disk/sdb6/dbs/phydbs
chown informix:informix /disk/sdb6/dbs/phydbs
(informix用户)onspaces -c -d phydbs -o 0 -s 102400 -p /disk/sdb6/dbs/phydbs
更改物理日志到新的位置:
onparams --help
onparams -p -s 102000 -d phydbs -y size:要小一点
逻辑日志(主要考量事务处理:20G):一个正常运行数据库至少要有3个逻辑日志
删除所有的现有逻辑日志,指到新的位置(表空间)
一般是先添加新的逻辑日志,再删除已有的逻辑日志。
touch /disk/sdb6/dbs/logdbs1
chmod 660 /disk/sdb6/dbs/logdbs1
chown informix:informix /disk/sdb6/dbs/logdbs1
touch /disk/sdb6/dbs/logdbs2
chmod 660 /disk/sdb6/dbs/logdbs2
chown informix:informix /disk/sdb6/dbs/logdbs2
(informix用户)
onspaces -c -d logdbs1 -o 0 -s 51200 -p /disk/sdb6/dbs/logdbs1
onspaces -c -d logdbs2 -o 0 -s 51200 -p /disk/sdb6/dbs/logdbs2
添加新的逻辑日志:
onparams -a -d logdbs1 -s 51000 -i
onparams -a -d logdbs2 -s 51000 -i
onstat -l
删除逻辑日志:
onparams -d -l 2 -y
ontape -a --手动备份逻辑日志
ontape -c --持续备份逻辑日志
ontape -s -L 0
ontape -s -L 1
ontape -s -L 2
临时空间:用来做排序的,对性能优化非常重要(临时表),默认放在rootdbs中
从配置文件中设置(参数文件)
onstat -c |grep TEMP
临时空间要设置多个,自动并行处理,同时往多个里面写,可提高性能
DBSPACETEMP默认使用rootdbs空间,需要修改
onspace --help
touch /disk/sdb6/dbs/tempdbs1
chmod 660 /disk/sdb6/dbs/tempdbs1
chown informix:informix /disk/sdb6/dbs/tempdbs1
touch /disk/sdb6/dbs/tempdbs2
chmod 660 /disk/sdb6/dbs/tempdbs2
chown informix:informix /disk/sdb6/dbs/tempdbs2
onspaces -c -t -d tempdbs1 -o 0 -s 51200 -p /disk/sdb6/dbs/tempdbs1
onspaces -c -t -d tempdbs2 -o 0 -s 51200 -p /disk/sdb6/dbs/tempdbs2
修改配置文件:
vi onconfig.inst3
DBSPACETEMP tempdbs1,tempdbs2 --逗号分开,不能有空格
onmode -ky
oninit -vy
使用OAT工具查看temp空间的使用情况。
在表空间中添加新的块:
touch /disk/sdb6/dbs/rootdbs1
chmod 660 /disk/sdb6/dbs/rootdbs1
chown informix:informix /disk/sdb6/dbs/rootdbs1
onspaces -a rootdbs -p /disk/sdb6/dbs/rootdbs1 -o 0 -s 102400
索引:提高查询速度,类似于书的目录
查询的方式:
1、全表扫描 select * from t1 where id=100;
2、索引查询
dbaccess - -
database java01
create table t1
(
id int,
name varchar(200)
) in tbs1;
create procedure proc01()
returning varchar(20);
define i int;
begin
for i=1 to 10000
insert into t1 values (i,'user_'||i);
end for;
end;
return 'OK';
end procedure;
execute procedure proc01();
select count(1) from t1;
set explain on avoid_execute;
set explain file to '/home/informix/plan.out';
select * from t1 where id=100; --以块为单位把该表的所有块读到内存,进行比较(以扩展为单位读进内存 1 extend=8块)
cmd:
tail -f /home/informix/plan.out &
create index tl_idx1 on t1(id ase/desc) in tbs2; --新开窗口执行该语句(本窗口被设置为avoid_execute)
select * from t1 where id=100; 先找索引为100的块,只用读取一行。
informix中的索引:B树算法 B+树算法
索引是保存数据的,索引段
保存的数据:索引列,rowid
rowid:物理路径
表有表段
select first 10 id,name,rowid from t1;
rowid是存在的,只是在informix中不直接使用
select * from t1 where rowid=257;
t1_idx1:id,rowid(查询id=100,找到第一条,再找第二条,直到不是100的才停止向下扫描)
索引是排序的(默认ASC排序),不用整个索引都扫描
建索引是危险的动作:需要排序,临时表空间,io访问(不忙的时候再去创建索引)
单列索引,符合索引(把最经常查询的放前面
create table t2
(
id int,
name varchar(20),
age int,
email varchar(50)
);
insert into t2 values(1,'u1',11,'u1@abc.com');
insert into t2 values(2,'u2',12,'u2@abc.com');
select * from t2;
create index t2_idx1 on t2 (id,age,name) in tbs2;
select * from t2 where id=1 and age=11 and name='u1';
select * from t2 where id=1;
select * from t2 where age=11;
select * from t2 where name='u1';
select * from t2 where id=1 and age=11;
select * from t2 where id=1 and name='u1';
select * from t2 where age=11 and name='u1';
看执行计划,是否有使用index查询?
索引因子(因其有排序,update,delete时都有排序调整动作):
drop index t2_idx1;
create index t2_idx1 on t2(name desc) fillfactor 60;
select * from t1 where id=1;
select * from t1 where id !=1;
并不是有了索引所有的操作都必须使用索引查询,用不用索引由优化器决定。有的查询在不使用索引的情况下会更快。优化器:基于成本的优化器。
根据统计数据计算:采样数据
如果没有手动采样,informix会自动采样
手动采样:update statistics for table t2;
唯一性索引:
创建主键时,自动生成索引(主键索引)
create table t09
(
id serial primary key,
name varchar(20) unique,
email varchar(50) not null,
age int check(age >=0 and age <= 150),
city varchar(20) default 'haerbing'
);
create table t011
(id serial references t09(id),
math int check(mach >=0 and mach <= 100)
);
student
id=1 name='jack';
score(references student(id))
id=1 90
录入:先student,后score
删除:先score,后student
create table t012
(
id int primary key constraint pk01
);
create table t023
(
id serial primary key constraint pk02,
name varchar(20) unique constraint pk3,
email varchar(50) not null constraint pk4,
age int check(age >=0 and age <= 150) constraint pk05,
city varchar(20) default 'haerbing'
);
create table t033(
id int,
name varchar(20)
);
alter table t033 add constraint primary key(id);
如果有约束和触发器同时存在,约束先生效,约束也是数据库对象,是有名称的,不指定名称,系统自动生成。
大量数据的导入:
create table t023
(
id serial primary key constraint pk02,
name varchar(20) unique constraint pk3,
email varchar(50) not null constraint pk4,
age int check(age >=0 and age <= 150) constraint pk05,
city varchar(20) default 'haerbing'
);
create index t023_idx1 on t023(name);
drop index t023_idx1; --在导入数据后再重新创建该index
alter table t023 disable constraint pk03; --禁用约束(主键约束没有必要禁用),enable
导入数据使用自身携带的工具,不要使用程序导入
导出表定义:
dbschema -t t1 -d java01
dbschema -t t1 -d java01 >t1.sql
dbschema -t all -d java01 >t1.sql --导出所有表的定义
dbschema -q -t all -d java01 >all.sql --导出所有表的定义(不要开头的说明信息)
dbaccess - -
create database java11 with buffered log;
dbaccess java11 < all.sql --只是导入了表结构,数据没有导入
导出数据:
dbaccess java01 -
unload to '/home/informix/t1.sql' select * from t1;
unload to '/home/informix/t11.sql' delimiter '|' select * from t1;
导入数据:删除索引,禁用约束
select count(1) from t1;
load from '/home/informix/t1.sql' insert into t1;
delete from t1;
load from '/home/informix/t11.sql' delimiter '|' insert into t1;
dbaccess 环境变量字符集:
term
termcap
lang
lang_all
onmonitor:字符界面的监控工具。
OAT工具:
(root:)
cd $INFORMIXDIR/OAT
netstat -an|grep 8080
http://192.168.109.130:8080/(注意代理服务器设置)
点击admin不是login,输入安装oat时设置的用户和密码admin/admin
admin->Add Connection:
Informix Server inst3
Host Name 192.168.109.130
Port 40000
Username informix
Password password
单表比较大时(海量数据):分片和分区技术(只查找某个分区的数据,分散IO)
先前的做法:
t1 in tbs1
t2 in tba2
让t1表中的数据保存在不同的表空间上
分片:每个fragment要在不同的空间上
1、采用循环算法
create table h1
(
id int,
name varchar(20)
)
fragment by round robin in tbs1,tbs2; --导出schema的时候,也带有这些信息(导入的目标库也要有tbs1和tbs2,才能导入)
2、表达式算法
create table h2
(
id int,
name varchar(20)
)
fragment by expression
(id<10) in tbs1,
(id>10) in tbs2;
3、
create table h3 --报错,每个片段使用一个独立的表空间
(
id int,
name varchar(20)
)
fragment by expression
(id<10) in tbs1,
(id>10) in tbs1;
分区表:
1、
create table h4
(
id int,
name varchar(20)
)
partition by expression
(id<10) in tbs1,
(id>10) in tbs2;
2、
create table h5 --不同分区可在相同的表空间上
(
id int,
name varchar(20)
)
partition by expression
partition part1 (id<10) in tbs1,
partition part2 (id>10) in tbs1
;
设置物理/逻辑日志:
显示日志信息:onstat -l
物理日志:保存数据的前映象
逻辑日志:保存数据库的变化(现在的数据库都是先写日志数据库)
设置物理日志:默认保存在rootdbs中,创建新的表空间,更改物理日志到新的位置
mkdir -p /disk/sdb6/dbs
chown informix:informix /disk/sdb6/dbs
touch /disk/sdb6/dbs/phydbs
chmod 660 /disk/sdb6/dbs/phydbs
chown informix:informix /disk/sdb6/dbs/phydbs
(informix用户)onspaces -c -d phydbs -o 0 -s 102400 -p /disk/sdb6/dbs/phydbs
更改物理日志到新的位置:
onparams --help
onparams -p -s 102000 -d phydbs -y size:要小一点
逻辑日志(主要考量事务处理:20G):一个正常运行数据库至少要有3个逻辑日志
删除所有的现有逻辑日志,指到新的位置(表空间)
一般是先添加新的逻辑日志,再删除已有的逻辑日志。
touch /disk/sdb6/dbs/logdbs1
chmod 660 /disk/sdb6/dbs/logdbs1
chown informix:informix /disk/sdb6/dbs/logdbs1
touch /disk/sdb6/dbs/logdbs2
chmod 660 /disk/sdb6/dbs/logdbs2
chown informix:informix /disk/sdb6/dbs/logdbs2
(informix用户)
onspaces -c -d logdbs1 -o 0 -s 51200 -p /disk/sdb6/dbs/logdbs1
onspaces -c -d logdbs2 -o 0 -s 51200 -p /disk/sdb6/dbs/logdbs2
添加新的逻辑日志:
onparams -a -d logdbs1 -s 51000 -i
onparams -a -d logdbs2 -s 51000 -i
onstat -l
删除逻辑日志:
onparams -d -l 2 -y
ontape -a --手动备份逻辑日志
ontape -c --持续备份逻辑日志
ontape -s -L 0
ontape -s -L 1
ontape -s -L 2
临时空间:用来做排序的,对性能优化非常重要(临时表),默认放在rootdbs中
从配置文件中设置(参数文件)
onstat -c |grep TEMP
临时空间要设置多个,自动并行处理,同时往多个里面写,可提高性能
DBSPACETEMP默认使用rootdbs空间,需要修改
onspace --help
touch /disk/sdb6/dbs/tempdbs1
chmod 660 /disk/sdb6/dbs/tempdbs1
chown informix:informix /disk/sdb6/dbs/tempdbs1
touch /disk/sdb6/dbs/tempdbs2
chmod 660 /disk/sdb6/dbs/tempdbs2
chown informix:informix /disk/sdb6/dbs/tempdbs2
onspaces -c -t -d tempdbs1 -o 0 -s 51200 -p /disk/sdb6/dbs/tempdbs1
onspaces -c -t -d tempdbs2 -o 0 -s 51200 -p /disk/sdb6/dbs/tempdbs2
修改配置文件:
vi onconfig.inst3
DBSPACETEMP tempdbs1,tempdbs2 --逗号分开,不能有空格
onmode -ky
oninit -vy
使用OAT工具查看temp空间的使用情况。
在表空间中添加新的块:
touch /disk/sdb6/dbs/rootdbs1
chmod 660 /disk/sdb6/dbs/rootdbs1
chown informix:informix /disk/sdb6/dbs/rootdbs1
onspaces -a rootdbs -p /disk/sdb6/dbs/rootdbs1 -o 0 -s 102400
索引:提高查询速度,类似于书的目录
查询的方式:
1、全表扫描 select * from t1 where id=100;
2、索引查询
dbaccess - -
database java01
create table t1
(
id int,
name varchar(200)
) in tbs1;
create procedure proc01()
returning varchar(20);
define i int;
begin
for i=1 to 10000
insert into t1 values (i,'user_'||i);
end for;
end;
return 'OK';
end procedure;
execute procedure proc01();
select count(1) from t1;
set explain on avoid_execute;
set explain file to '/home/informix/plan.out';
select * from t1 where id=100; --以块为单位把该表的所有块读到内存,进行比较(以扩展为单位读进内存 1 extend=8块)
cmd:
tail -f /home/informix/plan.out &
create index tl_idx1 on t1(id ase/desc) in tbs2; --新开窗口执行该语句(本窗口被设置为avoid_execute)
select * from t1 where id=100; 先找索引为100的块,只用读取一行。
informix中的索引:B树算法 B+树算法
索引是保存数据的,索引段
保存的数据:索引列,rowid
rowid:物理路径
表有表段
select first 10 id,name,rowid from t1;
rowid是存在的,只是在informix中不直接使用
select * from t1 where rowid=257;
t1_idx1:id,rowid(查询id=100,找到第一条,再找第二条,直到不是100的才停止向下扫描)
索引是排序的(默认ASC排序),不用整个索引都扫描
建索引是危险的动作:需要排序,临时表空间,io访问(不忙的时候再去创建索引)
单列索引,符合索引(把最经常查询的放前面
create table t2
(
id int,
name varchar(20),
age int,
email varchar(50)
);
insert into t2 values(1,'u1',11,'u1@abc.com');
insert into t2 values(2,'u2',12,'u2@abc.com');
select * from t2;
create index t2_idx1 on t2 (id,age,name) in tbs2;
select * from t2 where id=1 and age=11 and name='u1';
select * from t2 where id=1;
select * from t2 where age=11;
select * from t2 where name='u1';
select * from t2 where id=1 and age=11;
select * from t2 where id=1 and name='u1';
select * from t2 where age=11 and name='u1';
看执行计划,是否有使用index查询?
索引因子(因其有排序,update,delete时都有排序调整动作):
drop index t2_idx1;
create index t2_idx1 on t2(name desc) fillfactor 60;
select * from t1 where id=1;
select * from t1 where id !=1;
并不是有了索引所有的操作都必须使用索引查询,用不用索引由优化器决定。有的查询在不使用索引的情况下会更快。优化器:基于成本的优化器。
根据统计数据计算:采样数据
如果没有手动采样,informix会自动采样
手动采样:update statistics for table t2;
唯一性索引:
创建主键时,自动生成索引(主键索引)
create table t09
(
id serial primary key,
name varchar(20) unique,
email varchar(50) not null,
age int check(age >=0 and age <= 150),
city varchar(20) default 'haerbing'
);
create table t011
(id serial references t09(id),
math int check(mach >=0 and mach <= 100)
);
student
id=1 name='jack';
score(references student(id))
id=1 90
录入:先student,后score
删除:先score,后student
create table t012
(
id int primary key constraint pk01
);
create table t023
(
id serial primary key constraint pk02,
name varchar(20) unique constraint pk3,
email varchar(50) not null constraint pk4,
age int check(age >=0 and age <= 150) constraint pk05,
city varchar(20) default 'haerbing'
);
create table t033(
id int,
name varchar(20)
);
alter table t033 add constraint primary key(id);
如果有约束和触发器同时存在,约束先生效,约束也是数据库对象,是有名称的,不指定名称,系统自动生成。
大量数据的导入:
create table t023
(
id serial primary key constraint pk02,
name varchar(20) unique constraint pk3,
email varchar(50) not null constraint pk4,
age int check(age >=0 and age <= 150) constraint pk05,
city varchar(20) default 'haerbing'
);
create index t023_idx1 on t023(name);
drop index t023_idx1; --在导入数据后再重新创建该index
alter table t023 disable constraint pk03; --禁用约束(主键约束没有必要禁用),enable
导入数据使用自身携带的工具,不要使用程序导入
导出表定义:
dbschema -t t1 -d java01
dbschema -t t1 -d java01 >t1.sql
dbschema -t all -d java01 >t1.sql --导出所有表的定义
dbschema -q -t all -d java01 >all.sql --导出所有表的定义(不要开头的说明信息)
dbaccess - -
create database java11 with buffered log;
dbaccess java11 < all.sql --只是导入了表结构,数据没有导入
导出数据:
dbaccess java01 -
unload to '/home/informix/t1.sql' select * from t1;
unload to '/home/informix/t11.sql' delimiter '|' select * from t1;
导入数据:删除索引,禁用约束
select count(1) from t1;
load from '/home/informix/t1.sql' insert into t1;
delete from t1;
load from '/home/informix/t11.sql' delimiter '|' insert into t1;
dbaccess 环境变量字符集:
term
termcap
lang
lang_all
onmonitor:字符界面的监控工具。
OAT工具:
(root:)
cd $INFORMIXDIR/OAT
netstat -an|grep 8080
http://192.168.109.130:8080/(注意代理服务器设置)
点击admin不是login,输入安装oat时设置的用户和密码admin/admin
admin->Add Connection:
Informix Server inst3
Host Name 192.168.109.130
Port 40000
Username informix
Password password
单表比较大时(海量数据):分片和分区技术(只查找某个分区的数据,分散IO)
先前的做法:
t1 in tbs1
t2 in tba2
让t1表中的数据保存在不同的表空间上
分片:每个fragment要在不同的空间上
1、采用循环算法
create table h1
(
id int,
name varchar(20)
)
fragment by round robin in tbs1,tbs2; --导出schema的时候,也带有这些信息(导入的目标库也要有tbs1和tbs2,才能导入)
2、表达式算法
create table h2
(
id int,
name varchar(20)
)
fragment by expression
(id<10) in tbs1,
(id>10) in tbs2;
3、
create table h3 --报错,每个片段使用一个独立的表空间
(
id int,
name varchar(20)
)
fragment by expression
(id<10) in tbs1,
(id>10) in tbs1;
分区表:
1、
create table h4
(
id int,
name varchar(20)
)
partition by expression
(id<10) in tbs1,
(id>10) in tbs2;
2、
create table h5 --不同分区可在相同的表空间上
(
id int,
name varchar(20)
)
partition by expression
partition part1 (id<10) in tbs1,
partition part2 (id>10) in tbs1
;