Quote:
Originally Posted by waltari2001
I've got a table that contains 20+ millions records and I'm trying to dump its data to a file. I've tried to use the cursor approach because of the memory issues.
|
Quote:
Originally Posted by waltari2001
But I will need to extract my data between the two lines matching "COPY mytable ..." & "\."
|
It's difficult to figure out exactly what you're trying to do.
If you're attempting to dump the database, pg_dump is the tool to use.
The documentation provides guidance on how to deal with large databases. Dumping the database to a compressed or custom archive give you lots of options for restoring the database using
pg_restore.
If you're attempting to "export" a specific table's data to a csv file, then you can write a copy script:
Code:
copy table mytable to stdout with csv header;
You can then pipe the output to a file with psql using the strategies outlined above.
Anything with a cursor or custom function, I'm guessing, would be orders of magnitude slower.