【问题标题】:db2 "export to filename.csv" giving IO errordb2 "export to filename.csv" 给出 IO 错误
【发布时间】:2016-03-17 05:07:44
【问题描述】:

我正在尝试使用 JDBC 连接(我正在使用 DB2 数据库)导出数据,但它失败并出现以下错误:

原因:com.ibm.db2.jcc.c.SqlException: DB2 SQL 错误:SQLCODE: -3001, SQLSTATE: , SQLERRMC: sqlofopn -2029060079

我使用的查询:

call admin_cmd('EXPORT TO /home/user/test_1/db_extract.csv OF DEL MODIFIED BY NOCHARDEL SELECT * from mytable 仅获取前 5 行');

我还授予了 755 对 test_1 文件夹的访问权限。 我也尝试删除 admin_cmd 但收到 BEGIN OF STATEMENT 错误

还尝试使用 putty 进行相同的查询,但运气不好,我得到了这个错误:

SQL3001C 发生 I/O 错误(原因 =“sqlofopn -2029060079”) 在打开输出文件时。

【问题讨论】:

  • 1.您意识到这会将文件写入数据库服务器上的目录,对吧?
  • 2.该目录必须可由实例的受保护用户写入。 755 表示只有目录的所有者才有写权限。
  • 我尝试将 777 也给文件夹,仍然是同样的问题。但是当我删除 admin_cmd 时,它会在我直接从实例运行查询但它不能从 JDBC 连接运行时工作。
  • 您能否通过调用 admin_cmd 过程从 DB2 CLP 运行本机 EXPORT 命令和 EXPORT 命令?另外 - 这是一个通过 JDBC 或类似 Data Studio 调用 admin_cmd 的本土应用程序吗?
  • @proksch_ibm 我尝试使用 admin_cmd 运行,它给出了错误但没有 admin_cmd 它可以工作。它只是一个简单的 Java 应用程序。

标签: database csv db2 export


【解决方案1】:

您需要向 db2 防护用户和/或 db2 防护用户所属的组授予权限。例如:

-- file /tmp/stack.sql
connect to pocdb user proksch using in4mix;

call admin_cmd('export to /stack/my.unl of del select * from proksch.foo');

connect reset;

terminate;

以下 stack.sh 脚本以 root 身份运行(或其他不能动态设置 acls 的用户)

#!/bin/bash
# ran as root to set acts
DB2=/home/db2inst1/sqllib/bin/db2

function rmperms {
        rm -f /stack/my.unl > /dev/null 2> /dev/null
        setfacl -x user:db2inst1 /stack
        setfacl -x user:db2fence /stack
        setfacl -x group:db2 /stack
}

function setperms {
        setfacl -m $1 /stack
}


function getperms {
        echo "   "
        echo "Perms on /stack"
        ls -l  / | grep stack
        getfacl /stack --tabular --absolute-names --recursive
        echo "   "
}
rmperms

getperms

su --command="${DB2} -tvf /tmp/stack.sql" db2inst1

rmperms
setperms user:db2inst1:rwx
getperms

su --command="${DB2} -tvf /tmp/stack.sql" db2inst1

rmperms
setperms user:db2fence:rwx
getperms
su --command="${DB2} -tvf /tmp/stack.sql" db2inst1

rmperms
setperms group:db2:rwx
getperms

su --command="${DB2} -tvf /tmp/stack.sql" db2inst1

产生以下结果:

Perms on /stack
drwxr-xr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
mask             r-x
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2inst1  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2fence  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')

  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
group  db2       rwx
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')


  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.

【讨论】:

    【解决方案2】:

    在 Windows 中,问题在于路径访问。 以管理员权限运行 db2 解决了问题(也可以通过更改文件路径来解决问题)。

    【讨论】:

      猜你喜欢
      • 2015-05-23
      • 2013-03-12
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2019-02-02
      相关资源
      最近更新 更多