'Docker Postgres COPY TO csv using knex
On a windows machine with database running on postgres user, node app generated the file and i was able to download and view it without any issues the code is this:
try {
await knex.raw(`copy (${queryStatement}) TO '${csvPath}' csv header`)
.then((generated: any) => {
if (generated.rowCount > 0) {
return res
.setHeader("Content-Disposition", `attachment; ${filename}`)
.download(csvPath, filename)
} else {
res.status(404).json({message: 'file not generated.'})
}
})
} catch (err) {
next(err)
}
however, the same thing doesn't work in docker, the app container and the pg container, first it complained that only superusers or group members of pg_read_server_files and pg_write_server_files had access to open the file, after i granted them to db user, the file was successfully generated with only the headers for the csv and the error returned in the response file not generated.
i've tried various solutions provided here or elsewhere, none of them worked, the last straw was just generating the files under a shared tmp volume under the same user id and it still didn't work from the app and the file was only getting headers and not the data.
is there any way that postgres can cool down the permissions on files generated using COPY TO so that the container can write the files and the app read and send the file?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
