Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a PostgreSQL database with a multi-Gb table (which contains a log of certain events). I need to pass the latest events to an analyst - let's say he only needs events from the last month.

How can I produce a dump of only those rows that have, say, created_at > '2012-05-01'?

share|improve this question

Another way is to use COPY or \copy (the psql command), something like:

COPY (SELECT * FROM big_table WHERE created_at > '2012-05-01') TO '/path/to/a/dump/file';
share|improve this answer
But does it produce actual INSERT statements? More generally speaking, how do you get the dump back into the database? – Leonid Shevtsov May 28 '12 at 13:13
No, it doesn't produce valid SQL statments - its output is CSV, "text" or binary format. But it could be imported in another DB using the same commands. – Milen A. Radev May 28 '12 at 13:34
@LeonidShevtsov from this SO answer you can COPY big_table FROM '/path/to/a/dump/file, though you might have to have the same version on both instances. – Matthieu Sep 3 '15 at 7:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.