I'd like to use Go to copy postgres data from database A, view A into Database B, table B. This will be done for several dozen tables and I'd like to take advantage of the concurrency offered by Go.
I can do this using psql commandline that looks something like:
psql -h hostServer -p 5432 -U dbUser -d dbName \
-c "\copy (Select * From myView) TO STDOUT" \
| psql -h destinationHost -p 5432 -U dbUser -d destinationDB \
-c "\copy destinationTable FROM STDIN"
Or in Python by running the above command or by using os.pipe and psycpog2's copy_from/to commands. Unfortunately, neither of these options seem to play too well with concurrency. This is why I'm looking to do the same thing in go.
So my question - how can I run the above command line command in GO? Or pipe data to/from different postgres databases? I'v been experimenting with the following code and haven't had success. Any tips would be appreciated.
import "github.com/go-pg/pg"
//connect to source and destination db's (successful connection confirmed)
r, w := io.Pipe()
println("start")
_, err := destDB.CopyFrom(r, "COPY destinationTable FROM STDIN")
if err != nil {
println(err)
}
_, err = srcDB.CopyTo(w, "COPY (SELECT * FROM sourceView) TO STDOUT")
if err != nil {
println(err)
}
srcDB.Close()
destDB.Close()
CopyFromandCopyTomust be run concurrently i don't know how go makes threads but suspect that your code isn't doing that.