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


i using postgresql database live project. in which, have 1 table 8 columns. table contains millions of rows, make search faster table, want delete , store old entries table new table.

to so, know 1 approach:

  • first select rows
  • create new table
  • store rows in table
  • than delete main table.

but takes time , not efficient.

so want know best possible approach perform in postgresql database?

postgresql version: 9.4.2.
approx number of rows: 8000000
want move rows: 2000000

this sample code copying data between 2 table of same. here used different db, 1 production db , other testing db

insert "table2" select * dblink('dbname=db1 dbname=db2 user=postgres password=root',  'select "col1","col2" "table1"')  t1(a character varying,b character varying); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -