I'm simply trying to import some data using a PHP script. From the postgres account I can run the script. From psql logged in as postgres I can run the script.
This is PostgreSQL 9.6 running on Ubuntu 14.04.
-- works
\COPY mcl_import.mcl_user_mapping_tmp (mcl_id, user_id) FROM program '/usr/bin/php -f /var/yadda/yadda/user-import.php' WITH (FORMAT CSV, DELIMITER ',', NULL '[NULL]', header FALSE )
-- fails
COPY mcl_import.mcl_user_mapping_tmp (mcl_id, user_id) FROM program '/usr/bin/php -f /var/yadda/yadda/user-import.php' WITH (FORMAT CSV, DELIMITER ',', NULL '[NULL]', header FALSE );
-- ERROR: program "/usr/bin/php -f /var/yadda/yadda/user-import.php" failed
-- DETAIL: child process exited with exit code 255
Tested access restrictions with this and it works fine.
COPY testing FROM program 'more /var/yadda/yadda/user-import.php' WITH (DELIMITER E'\f');
Tested PHP by outputting version info with this and it works fine.
COPY testing FROM program 'php -v' WITH (DELIMITER E'\f');
Made sure it was was running as postgres with.
COPY testing FROM program 'whoami' WITH (DELIMITER E'\f');
In summary:
- \COPY works
- COPY does not
- It is running as the user postgres
- The user postgres has access to the file
- The user postgres has access to and can run the php command
I would run this script standalone but it's part of a larger migration process.