您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“PostgreSQL怎么實現(xiàn)不落地并行導出導入”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“PostgreSQL怎么實現(xiàn)不落地并行導出導入”吧!
(導出使用源版本pg_dump,導入使用目標版本pg_restore。如果是ppas請使用enterprisedb對應(yīng)版本。)
1、(源庫)全局元數(shù)據(jù)(用戶、表空間)導出
需要superuser權(quán)限(如果你沒有這個權(quán)限,跳過此步,但是務(wù)必在執(zhí)行下一步時,人為在目標實例中創(chuàng)建所有與對象權(quán)限相關(guān)的用戶)。
pg_dumpall -g -h IP地址 -p 端口 -U 用戶 -W -l 數(shù)據(jù)庫名
2、(目標庫)全局元數(shù)據(jù)導入
導入以上元數(shù)據(jù),在目標庫執(zhí)行即可(通常包括創(chuàng)建用戶,修改用戶密碼,創(chuàng)建表空間等。)
執(zhí)行第2步的目的是保證導入時,執(zhí)行g(shù)rant, 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、(目標實例)關(guān)閉autovacuum,加速導入(可選)
使用超級用戶執(zhí)行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(如果執(zhí)行了6)
使用超級用戶執(zhí)行SQL alter system set autovacuum=on; select pg_reload_conf();
9、(目標實例)收集統(tǒng)計信息(如果執(zhí)行了6)
使用超級用戶執(zhí)行SQL,收集統(tǒng)計信息 \c newdb 超級用戶 analyze;
使用以上方法,60GB的數(shù)據(jù)庫遷移,耗時約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怎么實現(xiàn)不落地并行導出導入”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。