-
Notifications
You must be signed in to change notification settings - Fork 0
Database copy to save cost
Leo Leung edited this page Oct 18, 2024
·
2 revisions
Instance type of aws rds database can be changed, but the storage can only be increased not decreased. Therefore, we need to copy data from old database to new database.
- Create snapshot from old database.
- Use replace in terraform to create new database with smaller storage.
- Create an instance server from old database snapshot for data migration.
- Make sure you are in the network that can connect both old database snapshot server and new database.
- Install
psql
andpg_dump
commands. Make sure the database tool same version as the remote database. Refer to this installation guide https://www.atlantic.net/dedicated-server-hosting/how-to-install-and-configure-postgres-14-on-ubuntu/ . - Run postgresql commands. (both databases share same password)
export PGPASSWORD= pg_dump -C -h old_hostname -U old_user old_db_name | psql -h new_hostname -U new_user new_db_name