HomeDatabaseMysql TutorialInformix系统维护技巧谈

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
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools