0

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.

Knyri
  • 2,968
  • 1
  • 17
  • 24
  • 1
    php probably emitted some kind of message saying why it failed. This message will likely show up in the PostgreSQL server's log file. – jjanes Nov 15 '19 at 22:56
  • Possible duplicate of [php postgresql pdo copy from stdin](https://stackoverflow.com/questions/9261916/php-postgresql-pdo-copy-from-stdin) – cetver Nov 15 '19 at 23:15
  • @jjanes Yep, it sure did. For some reason the starting directory is different when using `COPY`. Added an absolute path to the require in the PHP script and everything worked. – Knyri Nov 16 '19 at 15:36

0 Answers0