postgresql資料庫匯入匯出,postgresql匯入匯出

來源:互聯網
上載者:User

postgresql資料庫匯入匯出,postgresql匯入匯出
匯出遠端資料庫

1.從遠端資料庫IP上的資料庫monitor匯出threshold表結構和資料到檔案threshold.sql:
pg_dump -t threshold -h 135.32.94.142 monitor -U monitor -p 5432  -f threshold.sql

-t 指定要匯出的表名;

-h 指定資料庫地址;

-U 指定資料庫使用者;

-p 指定訪問連接埠;

-f  指定匯出到檔案;

2.從遠端資料庫IP上的資料庫monitor匯出所有表結構和資料到檔案monitor.sql:
pg_dump -h 135.32.94.142 monitor -U monitor -p 5432  -f monitor.sql

3.從遠端資料庫IP上的資料庫monitor僅僅匯出所有的表結構到檔案monitor.sql:
pg_dump -s -h 135.32.94.142 monitor -U monitor -p 5432  -f monitor.sql 

-s 只匯出表結構

注:一般資料庫資料量比較大,如果遠程匯出所有的表結構和資料的話會非常慢,所有只匯出表結構是個明智的選擇。隨後你就可以匯出單個重要資料表的結構和資料進來。匯入資料庫1.從本地檔案threshold.sql匯入表結構和資料到遠程IP上的資料庫monitor:
psql -h 135.32.9.99 -d monitor -U monitor -f threshold.sql

-h 指定資料庫地址;

-d 指定資料庫;

-U 指定使用者;

-f 指定要匯入的檔案(這裡是步驟1匯出的檔案);

注:這裡的檔案就是上面從遠端資料庫匯出的檔案。

2.匯入到本機資料庫:
psql -h 0.0.0.0  -p 5432 -d monitor -U monitor -f monitor.sql 
 -p 指定資料庫服務連接埠,根據本機情況而變,預設是5432連接埠


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.