I'm using travis-ci.org to test a Node.js module. It uses the latest pg package to access a PostgreSQL database.
The integration tests need to use the Postgres copy
command (from within a transaction... not psql's \copy
) to populate a temporary table with some CSV data.
Everything passes locally... but running on Travis-CI I'm hitting:
"COPY some_table(column_a,column_b) FROM
'/home/travis/build/my_org/my_repo/test/fixtures/some_file.csv' CSV HEADER;"
{ error: could not open file
"/home/travis/build/my_org/my_repo/test/fixtures/some_file.csv" for reading:
Permission denied
at Connection.parseE
(/home/travis/build/my_org/my_repo/node_modules/pg/lib/connection.js:567:11)
at Connection.parseMessage name: 'error',
...
So a file Permission denied
is the thing. My noob Linux skills tell me the file at that location exists. I've tried chmod
ing it to 777, but that didn't have any effect.
I'm connecting to Postgres on Travis with the string:
postgres://postgres:postgres@localhost:5432
And all's well with that.
One thing, I do need PostgreSQL V9.6, so my .travis.yml
file looks like:
language: node_js
node_js:
- "6"
services:
- postgresql
addons:
postgresql: "9.6"
sudo: false
dist: trusty
...which has worked great in the past, but this is the first time I've ever had to use copy
.
I guess it's something to do with whatever user Postgres is running as somehow?
Any help very gratefully received!
Tim
I actually ran into this issue when I was working on an inherited code base which was using the old Travis infrastructure (based on Ubuntu Precise) and wanted to update it to Trusty.
The Precise-based image had no problem reading a file from the travis home directory - maybe the PostgreSQL server was running as the travis
user, not as postgres
, but on Trusty this was not the case and I got this error.
Using chmod
on the file itself is not enough, the server still can't read from the travis
home directory. So you could create a file using mktemp
, copy your file to it, change those permissions to 666
using chmod
. Now you're able to read it in using PostgreSQLs COPY FROM
.