我的本地计算机上有一个本地Postgres数据库.现在,我想将本地Postgres数据库文件合并到AWS现有RDS数据库.有谁知道如何做到这一点?预先谢谢你.
I have a local Postgres database in my local machine. Now I would like to merge a local Postgres database file to AWS existing RDS database. Does anyone know how to do this? Thank you in advance.
推荐答案如果RDS实例位于专用子网中,则需要通过EC2实例进行隧道传输才能到达RDS实例.假设已设置安全组,以便可以通过SSH进入EC2实例,并且EC2实例可以访问端口5432上的RDS,则可以执行以下操作:
If the RDS instance is in a private subnet, then you need to tunnel through an EC2 instance to get to your RDS instance. Assuming your security groups are set so that you can ssh into the EC2 instance, and the EC2 instance has access to RDS on port 5432, you can do the following:
其中< username> 是本地计算机上的Postgres用户名("postgres"是默认用户).例如:
where <username> is the Postgres username on the local computer ('postgres' is the default user). For example:
$ pg_dump -Fc --no-acl --no-owner -h localhost -Upostgres my_development_db -f data.dump例如:
$ ssh -i ~/.ssh/ida_rsa -fNL 5433:my_prod_db.cbaxyzxyz.us-west-1.rds.amazonaws:5432 ec2-user@ec2-11-222-333-4.us-west-1pute.amazonaws例如:
$ pg_restore --no-owner -n public -c -1 -p 5433 -Umy_prod_username -h 127.0.0.1 -d prod_db_name data.dump在出现提示时输入RDS数据库密码.
Enter the RDS database password when prompted.
请注意, -c (干净")选项将删除数据库对象,然后再从本地数据库转储中重新创建它们.
Note that the -c ("clean") option, will drop the database objects before recreating them from your local database dump.
更多推荐
将本地PostgreSQL数据库文件合并到AWS RDS数据库
发布评论