You need to either grant permission to the db2 fenced user and/or the group that the db2 fenced user is a member of. For example:
-- 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;
The following stack.sh script was run as root (or another user than can set acls dynamically)
#!/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
Yields the following results:
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.