返回首页

gbase数据、南大通用产品文档:GBase8sDIRECT_IO 配置参数(UNIX)

更新日期:2024年09月11日

使用 DIRECT_IO 配置参数来控制用于 dbspace chunk 的熟文件直接 I/O。
该参数在 UNIX™ 平台上启用直接 I/O (绕过文件系统缓冲)或在 AIX® 操作系统上启
用并发 IO(绕过文件系统缓冲和不必要的写串行化。)
onconfig.std 值
DIRECT_IO 0

0 = 不使用直接 I/O 或并发 I/O
1 = 如果可以使用,则直接 I/O,绕过文件系统缓冲
2 = 在 AIX 操作系统上启用并发 I/O(并发 I/O 选项包括直接 I/O 和并发 I/O。)
生效
编辑 onconfig 文件并重启数据库服务器之后。
用法
直接 I/O 仅可用于 dbspace chunk,其文件系统支持页大小的直接 I/O。
通过使用直接 I/O,您能减少 AIO 虚拟处理器的数目。
如果启用直接 I/O,则使用文件系统支持的 KAIO(内核异步 I/O)。然而,如果设置环境
变量 KAIOOFF,则不使用 KAIO。当直接 IO 和 KAIO 都使用时,可减少 AIO 虚拟处
理器的数目。如果使用直接 IO,但不使用 KAIO,则不应减少 AIO 虚拟处理器的数目。
对于用作临时 dbspace chunk 的熟文件,GBase 8s 不使用直接或并发 I/O。

GBase 8s 管理员参考
南大通用数据技术股份有限公司 - 61 -

在 AIX 上,如果 GBase 8s 使用 chunk 的并发 I/O,则另一个程序(比如一个联机外部
备份程序)必须也使用并发 I/O。否则,文件打开操作将失败。
如果 GBase 8s 使用 chunk 的直接 I/O,且另一个程序试图不使用直接 I/O 来打开该
chunk,则打开操作正常成功,但可发生性能损失。之所以发生损失,是因为文件系统可能
试图确保每个打开操作查看相同的文件数据,或者通过在冲突打开操作期间根本不使用直
接 I/O,或者通过在每次直接 I/O 前清空文件系统高速缓存并在每次直接写之后使文件系
统高速缓存无效。
在 Windows™ 平台上使用 dbspace chunk 的直接 I/O,
与 DIRECT_IO 配置参数的值无关。

当您将带有 SQL 数据类型的值转换为字符数据类型时,rtypwidth() 函数返回字符数
据类型需要避免截断的最小字符数。


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 923 -

语法
mint rtypwidth(sqltype, sqllen)
mint sqltype;
mint sqllen;

sqltype
SQL 数据类型的整数代码。
sqllen
对于指定的 SQL 数据类型,在数据文件中的字节数。

用法

随同 DESCRIBE 语句初始化的 sqlda,提供 rtypwidth() 函数来使用。sqltype 和
sqllen 组件对应于每一 sqlda.sqlvar 结构中同名的组件。

返回代码
0
sqltype 不是有效的 SQL 数据类型。
>0
返回值是 sqltype 数据类型要求的最小字符数。

示例

此样例程序在 demo 目录中的 rtypwidth.ec 文件中。
/*
* rtypwidth.ec *

This program displays the name of each column in the 'orders' table and the number of
characters required to store the column when the data type is converted to characters.
*/

#include


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 924 -

#define WARNNOTIFY 1
#define NOWARNNOTIFY 0

main(argc, argv)
int argc;
char *argv[];
{
mint i, numchars;

int4 exp_chk();
char db_stmnt[50];
struct sqlda *sql_desc;
struct sqlvar_struct *col;

EXEC SQL BEGIN DECLARE SECTION;
char db_name[20];
EXEC SQL END DECLARE SECTION;

printf("RTYPWIDTH Sample ESQL Program running.\n\n");

if (argc > 2) /* correct no. of args? */
{
printf("\nUsage: %s [database]\nIncorrect no. of argument(s)\n",argv[0]);
exit(1);
}
strcpy(db_name, "stores7");
if (argc == 2)
strcpy(db_name, argv[1]);

EXEC SQL connect to :db_name;
sprintf(db_stmnt, "CONNECT TO %s", argv[1]);
exp_chk(db_stmnt, NOWARNNOTIFY);


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 925 -

printf("Connected to %s\n", db_name);
EXEC SQL prepare query_1 from 'select * from orders';
/* prepare select */
if(exp_chk("Prepare", WARNNOTIFY) == 1)
exit(1);
EXEC SQL describe query_1 into sql_desc;
/* setup sqlda */
if(exp_chk("Describe", WARNNOTIFY) == 1)
exit(1);
printf("\n\tColumn Name \t# chars\n");

/*
* For each column in orders print the column name and the minimum number of
characters required to convert the SQL type to a character data type
*/
for (i = 0, col = sql_desc->sqlvar; i < sql_desc->sqld; i++, col++)
{
numchars = rtypwidth(col->sqltype, col->sqllen);
printf("\t%-15s\t%d\n", col->sqlname, numchars);
}

printf("\nRTYPWIDTH Sample Program over.\n\n");
}

/*
The exp_chk() file contains the exception handling functions to
heck the SQLSTATE status variable to see if an error has occurred following an SQL
statement. If a warning or an error has occurred, exp_chk() executes the GET DIAGNOSTICS
statement and prints the detail for each exception that is returned.
*/
EXEC SQL include exp_chk.ec
输出

RTYPWIDTH Sample ESQL Program running.

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 926 -


Connected to stores7

Column Name # chars
order_num 11
order_date 10
customer_num 11
ship_instruct 40
backlog 1
po_num 10
ship_date 10
ship_weight 10
ship_charge 9
paid_date 10

RTYPWIDTH Sample Program over.

GBase 8c 数据库提供的gsql 工具,支持若干高级功能,以便用户更方便地使用数据库。
gsql 程序有一些不属于SQL 命令的内部命令,以反斜线(“\”)开头。

使用gsql 工具登录GBase 8c 数据库,语法格式如下:
gsql -d dbname -p port <-U user_name> <-h hostip>
其中参数说明:

-d 参数:
指定要连接到的数据库名称。
首次连接可以指定生成的默认数据库postgres。

-p 参数:指定通过节点哪个端口号连接。可查看安装使用的yml 文件。CN 节点默
认端口为5432。

-U 参数:指定以哪个数据库用户身份连接,权限可能不同。缺省默认为gbase。

-h 参数:指定数据库节点所在的服务器IP。缺省默认为当前服务器IP。

-r 参数:如指定此选项,用户可以使用↑↓方向按键查看历史命令;
具体操作命令为:
[gbase@gbase8c ~]$ gsql -d postgres -p 5432

GBase 8c V5 安装部署手册(分布式)
南大通用数据技术股份有限公司
36
返回正确信息(省略部分信息)

gsql ((multiple_nodes GBase8cV5 3.0.0…… )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#
随后可以自由使用GBase 8c 数据库。

退出GBase 8c 数据库登录状态。直接输入\q 命令,即可退出数据库。
postgres=# \q

GBase 8c V5 安装部署手册(分布式)
南大通用数据技术股份有限公司
37
7
附录