每次使用 psql 手动输入密码的问题
Issue with manually giving password every time with psql
我们正在尝试通过 COPY 命令使用 postgresql 的 psql
将数据从一个 Amazon RDS 数据库迁移到 Amazon Aurora Serverless 数据库。当我从 EC2 实例 运行 脚本时,脚本工作正常,但我需要为 rdswizard 和 postgres 每次迭代手动输入密码.我只想提供密码以及我的 psql
命令。如何不每次都手动输入密码和 psql
命令?
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
我的两个数据库主机都在远程服务器上而不是在本地机器上
您可以将详细信息添加到 ~/.pgpass
文件,以避免经常输入密码。确保为该文件提供 -rw-------(0600)
权限。
This file should contain lines of the following format:
hostname:port:database:username:password
将使用第一行中与当前连接参数匹配的密码字段。参考 official documentation
我们正在尝试通过 COPY 命令使用 postgresql 的 psql
将数据从一个 Amazon RDS 数据库迁移到 Amazon Aurora Serverless 数据库。当我从 EC2 实例 运行 脚本时,脚本工作正常,但我需要为 rdswizard 和 postgres 每次迭代手动输入密码.我只想提供密码以及我的 psql
命令。如何不每次都手动输入密码和 psql
命令?
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
我的两个数据库主机都在远程服务器上而不是在本地机器上
您可以将详细信息添加到 ~/.pgpass
文件,以避免经常输入密码。确保为该文件提供 -rw-------(0600)
权限。
This file should contain lines of the following format:
hostname:port:database:username:password
将使用第一行中与当前连接参数匹配的密码字段。参考 official documentation