Home Database Mysql Tutorial Informix系统维护技巧谈

Informix系统维护技巧谈

Jun 07, 2016 pm 05:53 PM
system maintenance

Informix是一种大型的数据库管理系统,具有先进的技术、性能与可靠性,在全球范围的各种应用中使用十分广泛,包括政府、金融保险、邮政电信、制造及零售等重要行业或领域。本文根据笔者在SCO Unix/Xenix上使用 Informix-4GL与Informix-SQL的经验,简要介

Informix是一种大型的管理系统,具有先进的技术、性能与可靠性,在全球范围的各种应用中使用十分广泛,包括政府、金融保险、邮政电信、制造及零售等重要行业或领域。本文根据笔者在SCO Unix/Xenix上使用 Informix-4GL与Informix-SQL的经验,简要介绍Informix系统维护中的几个较为特殊的问题及其处理方法。

表文件的修复

Informix的数据库是指由若干张表所构成的集合,其中每一张表对应着两个文件,即数据文件(后缀为.dat)与索引文件(后缀为.idx)。当系统出现异常、死机、掉电或非正常关闭时,有时会使一些使用中的表文件未能正常关闭而出现毁损,当系统再次对这些表进行相关操作时,就会报告“不能检索下一条记录”、“不能删除记录”等错误信息。

通常,数据文件是很少发生问题的。要判别数据文件是否正常,只需执行select * from 〈table-name〉语句或类似的语句即可, 但不能使用where、order by等子句,以免利用到索引文件,目的就是纯粹从数据文件中依次读取数据。如果数据读取顺利且记录个数正确,表明该文件完好无损;反之,则有问题,通常只能用其数据备份来恢复。

如果数据文件正确无误,那么就该检查相应的索引文件。Informix提供有一个实用程序bcheck,专门用来检查与修复索引文件,即依次比较数据文件与索引文件,倘若不一致,就询问是否删除和重建有问题的索引。bcheck有许多选项可供选用,其中-n和-y用于对所有的提问都回答“no”或“yes”,让系统自动进行一系列的操作。其语法如下:

bcheck [选项] 〈表文件名〉

要检查表的索引文件,应先运行bcheck -n命令。如果一切正常, 说明索引没有问题。一旦发现有错误报告(如有多少个错误数据记录指针、丢失了多少个数据记录指针或索引结点指针等),则再执行bcheck -y 命令即可将其修复。

Informix-SQL中的语句check table 〈表名〉与repair table 〈表名〉在运行时分别以选项-n与-y调用bcheck命令,功能一样,不同的只是使用表名而不是表文件名。

如果索引文件没有相应的读写权限, 或者没有正确指明其路径, 在bcheck时会出现“无法打开索引文件”的信息。如果索引文件被删除或格式被破坏了,也有同样的信息。此时可从数据备份中将对应的索引文件拷贝回来,也可暂时创建一个字段与索引均与原表完全一致的新表并将其索引文件拷贝给原表,再运行bcheck -y命令修复。

表空间的回收

Informix对数据表的管理方式较为特殊,当数据量增加时,表所占用的磁盘空间随之增加;但数据记录被删除时,原先所占用的空间暂不释放,依然由该表所控制,作为日后增加记录时使用。为提高系统的性能及有关各表的查询速度,应及时回收这种“空闲”的磁盘空间。

使用bcheck -s命令可回收索引文件的空间,其中-s 选项的作用是重新估算索引文件的大小。要同时回收数据文件与索引文件的空间,可让DBMS(数据库管理系统)去做表结构的修改工作,但修改前后的表结构及有关权限要保证一样。可利用Informix-SQL达此目的,最为保险的做法是先给相应的表增加一个字段,再将该字段删除。也可利用alter table 命令“欺骗”DBMS去修改表的结构,如alter table aa modify(bb smallint),其中aa表的字段bb的类型本来就是smallint。

表的迁移

任何一个Informix数据库都有九个系统表,用于记录数据库的有关信息,其中系统表systables(用于描述数据库中的各表)中的字段dirpath指明各表文件的绝对路径或相对路径。

Informix数据库的搜索路径一般由环境变量DBPATH来设定,系统根据DBPATH的正确设定即可找到相应的数据库及其各表。迁移Informix数据库表时(比如从Unix/Xenix的根文件系统迁移到分离的文件系统/u),只要重新设定DBPATH,通常系统即可正常运行。如果报告某些表找不到了(实际上这些表文件还在,且有关权限也对),问题就在于systables 表中的dirpath字段值采用了绝对路径, 此时要用update命令修正其值,最好改用相对路径,即直接改为表文件名。

系统查询的优化

Informix在执行查询(特别是多表查询)指令前,会利用其所提供的优化器(cost-based optimizer,基于成本的优化器),依据当时系统所记载的有关各表的相关信息,按照一定的判断法则进行分析并选择出一条最有效率的途径来执行。系统必须掌握各表的正确数据,才不至于做出错误的选择。但出于系统效率上的考虑,不可能随时修改记录各表最新状况的相关文件,否则会增加许多额外的输入/输出负担。因此, 应定期执行这种信息的更新操作。

在Informix数据库的系统表systables中有一字段nrows,专门用来记录各表的记录个数。优化器在运行法则判断时,各表的nrows 值具有很高的参考价值。nrows的更新可通过如下命令来完成,即:

update statistics [for table 〈table-name〉]

其中,方括号[]中的子句是可选的,用于指定表名,以对该表进行更新;否则,将对数据库中的各表进行全部更新。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

See all articles