I'm trying to run copy mananger and load CSV file

val pgConnection = conn.unwrap(classOf[PgConnection]) 
val copyManager = new CopyManager(pgConnection)
val fis = new FileInputStream(tempTsvFilePath.toFile)
val copyCommand = s""" COPY $myTable($listOfMyColumns) FROM STDIN DELIMITER E'\t' CSV """
val linesCopied = copyManager.copyIn(copyCommand, fis)

It works file locally with TestContainers

val timesacaleDb = DockerImageName

which starts with command

postgres", "-c", "fsync=off", "-c", "max_connections=500"

max_connections is temp hack until I throttle tests running in parallel.

Data is imported, all good, I verify every single imported record.

But exactly same code with exactly same input fails when I try to load data to real Postgres provided by ops.

org.postgresql.util.PSQLException: Database connection failed when starting copy
    at org.postgresql.core.v3.QueryExecutorImpl.startCopy(QueryExecutorImpl.java:949)
    at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:45)
    at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:220)
    at org.postgresql.copy.CopyManager.copyIn(CopyManager.java:203)

Caused by: java.io.EOFException: null
    at org.postgresql.core.PGStream.receiveChar(PGStream.java:455)
    at org.postgresql.core.v3.QueryExecutorImpl.processCopyResults(QueryExecutorImpl.java:1227)
    at org.postgresql.core.v3.QueryExecutorImpl.startCopy(QueryExecutorImpl.java:946)

I have no clue what it could be, what is the right way to debug it?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.