0

我们正在尝试通过COPY命令使用psqlpostgresql将数据从一个 Amazon RDS 数据库迁移到 Amazon Aurora Serverless 数据库。当我从 EC2 实例运行该脚本时,该脚本运行良好,但我需要手动为rdswizardpostgres每次迭代提供密码。我只想在我的命令中提供密码。如何不每次都手动提供密码和命令?psqlpsql

allSites=(3 5 9 11 29 30 31 32 33 34 37 38 39 40 41 45 46 47 48)

for i in "${allSites[@]}"
do
   psql \
    -X \
    -U rdswizard \
    -h my_rds_host_url_goes_here \
    -d wizard \
    -c "\\copy (select site_id,name,phone from client_${i} where date(create_date) > '2019-09-11' LIMIT 100) to stdout" \
| \
psql \
    -X \
    -U postgres \
    -h my_aurora_serverless_host_url_goes_here \
    -d wizard \
    -c "\\copy client_${i}(site_id,name,phone) from stdin"
done

我的两个数据库主机都在远程服务器上,而不是在本地机器上

4

1 回答 1

2

您可以将详细信息添加到~/.pgpass文件中,以避免经常输入密码。确保提供-rw-------(0600)对文件的权限。

该文件应包含以下格式的行:

hostname:port:database:username:password

将使用第一行中与当前连接参数匹配的密码字段。参考官方文档

于 2019-09-18T08:20:05.107 回答