pg_dump 迁移表到其他模式

作者:瀚高PG实验室 (Highgo PG Lab)- 天蝎座 

使用pg_dump方式将highgo数据库下的public.test表迁移到highgo数据库下的schema hg下


highgo=# select * from pg_tables where tablename='test';
 schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity 
------------+-----------+------------+------------+------------+----------+-------------+-------------
 public     | test      | highgo     |            | f          | f        | f           | f
(1 row)

highgo=# select * from test;
 a 
---
 1
(1 row)

highgo=# create user hg with password 'hg';
CREATE ROLE
highgo=# create schema authorization hg;
CREATE SCHEMA

pg_dump -h localhost -p 5866 -U highgo -F p -t test  -f '/home/highgo/beifen.dmp'

修改导出的文件/home/highgo/beifen.dmp。将模式和属主修改为hg。

[highgo@hgdb ~]$ psql -d highgo -U highgo -f '/home/highgo/beifen.dmp'
SET
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
ALTER TABLE
COPY 1

highgo=# select tablename,tableowner,schemaname from pg_tables where tablename = 'test';
 tablename | tableowner | schemaname 
-----------+------------+------------
 test      | highgo     | public
 test      | hg         | hg
(2 rows)

highgo=# select * from hg.test;
 a 
---
 1
(1 row)

成功!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值