Completely copying a postgres table with SQL

前端 未结 7 1240
春和景丽
春和景丽 2021-01-30 06:13

DISCLAIMER: This question is similar to the stack overflow question here, but none of those answers work for my problem, as I will explain later.

I\'m t

7条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 06:48

    Apparently you want to "rebuild" a table. If you only want to rebuild a table, not copy it, then you should use CLUSTER instead.

    SELECT count(*) FROM table; -- make a seq scan to make sure the table is at least
                                -- decently cached
    CLUSTER someindex ON table;
    

    You get to choose the index, try to pick one that suits your queries. You can always use the primary key if no other index is suitable.

    If your table is too large to be cached, CLUSTER can be slow though.

提交回复
热议问题