在 Postgres 中复制/克隆表的最快方法是什么? [英] What is the quickest way to duplicate/clone a table in Postgres?

查看:44
本文介绍了在 Postgres 中复制/克隆表的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以做 CREATE TABLE tbl_2 AS (select * from tbl_1)

但是有没有更好/更快/更强的方法来做到这一点?我说的性能比其他任何东西都重要.这些表都是非规范化的,我不需要担心任何外键约束.

But is there a better/faster/stronger way to do this? I am talking about performance more than anything else. The tables are all denormalised and I do not have any foreign key constraints to worry about.

编辑

可能没有更好的方法了吗?参考:https://dba.stackexchange.com/questions/55661/how-to-duplicate-huge-postgres-table

May be there isn't any better way? Ref: https://dba.stackexchange.com/questions/55661/how-to-duplicate-huge-postgres-table

推荐答案

更好的方法实际上取决于您究竟希望完成什么.

A better way really depends on what exactly you're hoping to accomplish.

如果您想保留原始表中的所有约束和索引,您可以在 CREATE TABLE 语句中使用 LIKE 子句,如下所示:

If you want to keep all the constraints and indexes from the original table you can use the LIKE clause in your CREATE TABLE statement like so:

CREATE TABLE tbl_2 (LIKE tbl_1 INCLUDING INDEXES INCLUDING CONSTRAINTS);

但这只会创建一个空表.您仍然需要复制数据.

But that just creates an empty table. You would still have to copy in the data.

这篇关于在 Postgres 中复制/克隆表的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆