久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

PostgreSQL怎么實現不落地并行導出導入

213次閱讀
沒有評論

共計 2346 個字符,預計需要花費 6 分鐘才能閱讀完成。

本篇內容主要講解“PostgreSQL 怎么實現不落地并行導出導入”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“PostgreSQL 怎么實現不落地并行導出導入”吧!

9.4 以下版本,使用 pg_dump 并行導出,pg_restore 并行導入,遷移

(導出使用源版本 pg_dump,導入使用目標版本 pg_restore。如果是 ppas 請使用 enterprisedb 對應版本。)

1、(源庫)全局元數據 (用戶、表空間) 導出

需要 superuser 權限(如果你沒有這個權限,跳過此步,但是務必在執行下一步時,人為在目標實例中創建所有與對象權限相關的用戶)。

pg_dumpall -g -h IP 地址  -p  端口  -U  用戶  -W -l  數據庫名

2、(目標庫)全局元數據導入

導入以上元數據,在目標庫執行即可(通常包括創建用戶,修改用戶密碼,創建表空間等。)

執行第 2 步的目的是保證導入時,執行 grant, alter set owner 等操作時,目標用戶已存在,否則缺失用戶會導致 pg_restore 報錯。

3、(目標庫)建庫

postgres=# create database newdb; 
CREATE DATABASE

4、(目標庫)插件

安裝 postgresql 軟件時,打包源庫已使用的的插件。 
 
略

5、(源庫)導出

mkdir /data01/pg/backup 
pg_dump -j 32 -f /data01/pg/backup -F d -h IP 地址  -p  端口  -U  用戶  -W newdb

6、(目標實例)關閉 autovacuum,加速導入(可選)

使用超級用戶執行 SQL 
 
alter system set autovacuum=off; 
select pg_reload_conf();

7、(目標庫)導入

pg_restore -d newdb -F d -j 32 -h IP 地址  -p  端口  -U  用戶  /data01/pg/backup

8、(目標實例)開啟 autovacuum(如果執行了 6)

使用超級用戶執行 SQL 
 
alter system set autovacuum=on; 
select pg_reload_conf();

9、(目標實例)收集統計信息(如果執行了 6)

使用超級用戶執行 SQL,收集統計信息  
\c newdb  超級用戶  
analyze;

使用以上方法,60GB 的數據庫遷移,耗時約 10 分鐘。

多機玩法

Where this gets interesting is with multiple hosts. You can:
$ # dump a remote database to your local machine
$ pg_dump -h remotedb.mydomain.com -f /home/postgres/dump.sql test
 
$ # dump a local database and write to a remote machine
$ pg_dump -h remotedb.mydomain.com test | ssh postgres@remotedb.mydomain.com  cat   dump.sql 
 
$ # dump a remote database and write to the same remote machine
$ pg_dump -h remotedb.mydomain.com test | ssh postgres@remotedb.mydomain.com  cat   dump.sql 
 
$ # or a different remote machine
$ pg_dump -h remotedb1.mydomain.com test | ssh postgres@remotedb2.mydomain.com  cat   dump.sql 
 
You also have similar restore options. I will use psql below but pg_restore works the same:
$ # dump a remote database and restore to your local machine
$ pg_dump -h remotedb.mydomain.com test1 | psql test2
 
$ # dump a local database and restore to a remote machine
$ pg_dump -h remotedb.mydomain.com test | ssh postgres@remotedb.mydomain.com  psql test 
 
$ # dump a remote database and restore to the same remote machine
$ pg_dump -h remotedb.mydomain.com test1 | ssh postgres@remotedb.mydomain.com  psql test2 
 
$ # or a different remote machine
$ pg_dump -h remotedb1.mydomain.com test | ssh postgres@remotedb2.mydomain.com  psql test

到此,相信大家對“PostgreSQL 怎么實現不落地并行導出導入”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-20發表,共計2346字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 晋宁县| 资源县| 赤城县| 常德市| 宝山区| 阳谷县| 平昌县| 双流县| 敖汉旗| 信丰县| 桦甸市| 东至县| 岢岚县| 玛纳斯县| 崇州市| 北流市| 麻城市| 招远市| 灵寿县| 普兰县| 台州市| 泽州县| 三原县| 嘉荫县| 达尔| 南丰县| 都匀市| 苏尼特左旗| 余庆县| 务川| 抚松县| 临海市| 梅河口市| 崇义县| 中江县| 西林县| 广丰县| 灌云县| 朝阳县| 肥城市| 集安市|