We are using a java application that does something like “COPY (select xyz from abc ) TO filename.csv.gz” using JDBC to postgres 9.3.11 server.
A COPY command which outputs to a server file must be executed as a regular query, not as a COPY statement. Use a regular JDBC java.sql.Statement, not the PGJDBC driver specific CopyManager classes.
The PGJDBC specific CopyManager classes are for COPY operations that read "... FROM STDIN" or write "... TO STDOUT".
I'm not sure exactly what's causing it to hang but I bet it's waiting for COPY related messages from the server that are never arriving because the executed command is not returning a COPY stream.