Amazon RDS - PostgreSQL 資料匯入



Amazon RDS PostgreSQL 提供了將資料匯入資料庫和從資料庫匯出資料的簡便方法。成功連線到 PostgreSQL 資料庫後,我們可以使用 CLI 工具執行匯入和匯出命令,將其他來源的資料匯入和匯出 RDS 資料庫。

以下是使用匯出和匯入機制進行 PostgreSQL 資料遷移的步驟。

從 Amazon EC2 例項匯入

如果 Amazon EC2 例項上有一個 PostgreSQL 伺服器,並且需要將其遷移到 RDS - PostgreSQL 資料庫例項,請按照以下步驟操作。

匯出資料

使用 pg_dump 建立一個包含要載入資料的檔案。使用 pg_dump 實用程式建立一個包含資料庫資料和所有元資料的資料轉儲檔案。psql 實用程式中的以下命令從名為 mydbname 的資料庫建立轉儲檔案。

pg_dump dbname=mydbname -f mydbnamedump.sql 

建立目標資料庫例項

接下來,我們建立目標資料庫例項並使用 pg_restore 命令將資料恢復到其中。

createdb [new database name]
pg_restore -v -h [endpoint of instance] -U [master username] -d [new database name] [database].dump 

建立目標資料庫

使用 psql 在資料庫例項上建立資料庫並載入資料。

psql \
   -f mydbnamedump.sql \
   --host awsdbpginstance.d34f4mnfggv0.us-west-2.rds.amazonaws.com \
   --port 8199 \
   --username awsdbuser \
   --password awsdbpassword \
   --dbname mynewdb 
廣告
© . All rights reserved.