数据库备份与恢复
onconfig 参数
TAPEDEV 设置成STDIO.
备份:
ontape -s -L 0 -t STDIO -F|gzip -f > /databk/ontape0.gz 恢复:
gunzip -c /databk/ontape0.gz|ontape -r -t STDIO
onmode –mGo to multi-user on-line
设置informix环境变量
? FORCE_DDL_EXEC
开启:SET ENVIRONMENT FORCE_DDL_EXEC \关闭:SET ENVIRONMENT FORCE_DDL_EXEC off
强制执行alter fragment 语句,所有其他正在使用该表的事物将会回滚。
如何注册外部存储过程
强制锁表
LOCK TABLE table-name IN MODE table-name:表名称。
SHARE:允许读表中数据,但不允许作任何修改
EXCLUSIVE:禁止其他任何形式访问表
每次只能对表琐定一次;事务处理过程中,BEGIN WORK后立即执行LOCK TABLE以取代记录级加锁,COMMIT WORK和 ROLLBACK WORK语句取消所有对表的加锁;若没有事务处理,锁将保持到用户退出或执行UNLOCK为止。
例:lock table tabname in exclusive mode;
next extent size allocation
The number of kilobytes that the database server allocates for a next extent is, in general, equal to the size of a next extent, as specified in the SQL statement CREATE TABLE. However, the actual size of the next-extent allocation might deviate from the specified size because the allocation procedure takes into account the following three factors: ? ? ?
Number of existing extents for this tblspace
Availability of contiguous space in the chunk and dbspace Location of existing tblspace extents
Extent Size Doubling: extent size自动翻倍
如果一张静态表或者用户自定义的临时表已经有16个extent,后续的extent大小会自动加倍。 例如创建表时设置的next size为20K,那么数据库分配的前16个extent大小为20K,第17到第32个extent大小为40k,第33到第48个extent大小为80K等等。
Lack of Contiguous Space:没有足够的连续空间
如果数据库在第一个chunk中找不到连续的next extent大小的空间,会继续在下一个chunk中寻找,但是注意extent不能跨chunk。
如果数据库在所有的chunk中都找不到足够的连续空间,那么就分配最大可用的连续空间为next extent(最小分配单位为4KB,默认8KB)。
Merge of Extents for the Same Table:同一张表的extent合并
如果数据库要分配的下一个extent和已分配给同张表的空间连续,那么数据库并不会把这次分配当做一个新的分配,而是扩充已存在的extent。我们看到的extent的个数并不是分配次数,而是extent的物理个数。
查看某张表所占空间大小
select a.dbspace,a.npused,
a.npused* b.pagesize / 1024/1024/1024 as AggUsedGB from sysfragments a, niosdb:systables b where a.tabid = b.tabid and a.fragtype = 'T' and b.tabname = 'tpa_pm_subject_serv_gsm
?
分片查看
select
st.dbsname databasename,st.tabname,sd.name dbs_name, ti_nextns extents,
sin.ti_nrows,sin.ti_pagesize, sin.ti_rowsize,
sin.ti_nptotal nptotal, format_units(sin.ti_nptotal,sd.pagesize) total_size, sin.ti_npused npused, format_units(sin.ti_npused,sd.pagesize) used_size, sin.ti_nptotal-sin.ti_npused
npfree,format_units(sin.ti_nptotal-sin.ti_npused,sd.pagesize) free_size, sin.ti_nextsiz nextsize
from sysmaster:systabnames st, sysmaster:sysdbspaces sd,sysmaster:systabinfo sin,niosdb:systables dt
where sd.dbsnum = trunc(st.partnum/1048576) and dt.tabid>99
and dt.tabname=st.tabname and st.partnum=sin.ti_partnum and st.dbsname='niosdb' and dt.tabname not like 'tmp%' order by 10 desc; ?
合并查看
select
st.dbsname databasename, st.tabname, dt.fextsize ext_size, dt.nextsize nxt_size, sum(ti_nextns) extents,
sum(sin.ti_nrows) nrows,max(sin.ti_pagesize) pagesize, sum(sin.ti_nptotal) total_size, sum(sin.ti_npused) used_size,
sum(sin.ti_nptotal)-sum(sin.ti_npused) npfree,
format_units(sum(sin.ti_nptotal)-sum(sin.ti_npused),max(sd.pagesize)) free_size from sysmaster:systabnames st, sysmaster:sysdbspaces sd,sysmaster:systabinfo sin,niosdb:systables dt
where sd.dbsnum = trunc(st.partnum/1048576)
npused,
format_units(sum(sin.ti_npused),max(sd.pagesize))
nptotal,
format_units(sum(sin.ti_nptotal),max(sd.pagesize))
and dt.tabid>99
and dt.tabname=st.tabname and st.partnum=sin.ti_partnum and st.dbsname='niosdb' and st.tabname not like 'tmp%' group by 1,2,3,4 order by 12 desc; ?
带时间分片查询
select
st.dbsname databasename,st.tabname,sd.name dbs_name, ti_nextns extents,
sin.ti_nrows,sin.ti_pagesize, sin.ti_rowsize,
sin.ti_nptotal nptotal, format_units(sin.ti_nptotal,sd.pagesize) total_size, sin.ti_npused npused, format_units(sin.ti_npused,sd.pagesize) used_size, sin.ti_nptotal-sin.ti_npused
npfree,format_units(sin.ti_nptotal-sin.ti_npused,sd.pagesize) free_size, sin.ti_nextsiz nextsize,frg.begin_time,frg.end_time
from sysmaster:systabnames st, sysmaster:sysdbspaces sd,sysmaster:systabinfo sin,niosdb:systables dt,niosdb:tac_frag_manager frg where sd.dbsnum = trunc(st.partnum/1048576) and dt.tabid>99 and
dt.tabname=st.tabname
and
dt.tabname=frg.table_name
and
sd.name=frg.tablespace_name and frg.del_flag=0 and st.partnum=sin.ti_partnum and st.dbsname='niosdb' and dt.tabname not like 'tmp%' order by 10 desc;
表压缩处理
现场有时会遇到如下情况
1、 数据库空间不够用,有很多表碎片较多,想重用这部分空间 2、 部分表不是很经常使用,可以压缩处理,节省空间
3、 部分表的部分分片方法量很小(比如很久以前的历史数据),可以压缩存放,以节省空
间
针对以上需求可以使用如下方法,注:使用到informix 11.5及以上的特性
相关推荐: