Efficient way to move large number of rows from one table to another new table using postgres

Viewed 3481

I am using PostgreSQL database for live project. In which, I have one table with 8 columns. This table contains millions of rows, so to make search faster from table, I want to delete and store old entries from this table to new another table.

To do so, I know one approach:

  • first select some rows
  • create new table
  • store this rows in that table
  • than delete from main table.

But it takes too much time and it is not efficient.

So I want to know what is the best possible approach to perform this in postgresql database?

Postgresql version: 9.4.2.
Approx number of rows: 8000000
I want to move rows: 2000000

2 Answers
Related