using ProgressMeter, LibPQ, DataFrames, Distributed
addprocs(4)
@everywhere begin
using ProgressMeter, LibPQ, DataFrames
function processSQL(typelike)
conn = LibPQ.Connection("dbname=$(ENV["PGDATABASE"]) user=$(ENV["PGUSER"])")
result = execute(
conn,
"SELECT typname FROM pg_type where typname like '$typelike';";
throw_error=true,
)
df = DataFrame(result)
close(conn)
return df
end
end
sqltypes=["time%","float%","int%"]
nsqltypes=length(sqltypes)
returndf = @showprogress pmap(1:nsqltypes) do i
processSQL(sqltypes[i])
end
Thank you @ImreSamu !
Yes, will include minimum example, my bad…
The solution worked. I realized what I did wrong. I created conn outside of the @distributed like this
using LibPQ, DataFrames, Distributed
addprocs(4)
conn = create_db_connection()
@everywhere function fetch_db(conn, typelike)
result = execute(
conn,
"SELECT typname FROM pg_type where typname like '$typelike';";
throw_error=true,
)
df = DataFrame(result)
return df
end
sqltypes=["time%","float%","int%"]
output = @distributed (vcat) for typelike in sqltypes
df = fetch_db(conn, typelike)
end
and obviously didn’t close connection as well. Many thanks for the answer!