複製 AWS RDS Postgres 實例

複製 AWS RDS Postgres 實例

面對這樣一種情況,我們需要將幾個小的 postgres 實例合併為一個更大的實例

無法弄清楚在替換發生時如何將“舊”資料庫新資料複製到“新”資料庫

我會嘗試簡化它:

old db instance name is X
new db instance is Y

X has 10 GB of data and its takes 15~ minutes to dump & restore
in the meanwhile X receives more data (1-2 MB)

** HOW do i make X replicate data to Y so this data wont get lost ? ** 

我有這個用於轉儲和恢復的小腳本

## remote db to remote db

PGPASSWORD=$source_pass pg_dump -h $source_host -d $source_db_name -U $source_user -p $source_port > test.sql

psql postgres://$dest_user:$dest_pass@$dest_host:$dest_port/postgres -c "CREATE DATABASE ${source_db_name}" \
-c "CREATE USER ${source_user} WITH PASSWORD '${source_pass}'" \
-c "ALTER USER "${source_user}" WITH CREATEDB" \
|| echo "database already exists"

psql postgres://$dest_user:$dest_pass@$dest_host:$dest_port/$source_db_name < test.sql \
 && echo "loaded Data succesfuly !" || echo "Couldnt load data"

相關內容