Issue
You want to copy a .csv
file from your local machine to a Heroku Postgres table.
Resolution
Run heroku pg:psql -a <application_name>
.
Once the Postgres shell opens, run
DATABASE=> \copy table_name FROM csv_file.csv WITH (FORMAT CSV);
If an upload data is large, we'd recommend the following:
- Attempt to run the
\copy
the data in smaller batches - If it's a private tier plan, attempt to run the
\copy
from a (one-off) dyno to avoid the extra overhead/latency to connect to the database server