转储 RDS Postgres 查询的内容

Dump Contents of RDS Postgres Query

这个问题的简短版本:

我想从 shell 脚本内的 RDS 中托管的数据库实例转储 Postgres 查询的内容。

完整版本:

现在我正在编写一个 shell 脚本,我想将查询的内容从源数据库转储到 .dump 文件中,然后 运行 将转储文件放在目标数据库实例。两个数据库实例都托管在 RDS 中。

MySQL 允许您使用 mysqldump tool, but the recommended answer to this problem in Postgres seems to be to use the COPY command. However, the COPY command isn't available in RDS instances. The recommended solution in this case seems to be to use the '\copy' command, which does the same thing locally using the psql tool. However, it doesn't seem 执行此操作,就像这是 shell 脚本中的一个支持选项。

完成此任务的最佳方法是什么?

谢谢!

我不熟悉 shell,但我在 Windows 中使用批处理文件将查询输出转储到一个文件并在另一个实例上导入该文件。

这是我用来从 postgres RDS 导出到 Windows 上的文件的内容。

SET PGPASSWORD=your_password
cd "C:\Program Files (x86)\pgAdmin 4\v3\runtime"
psql -h your_host -U your_username -d your_databasename -c "\copy (your_query) TO 
path\file_name.sql"

以上所有命令都在一个批处理文件中。