如何将 redshift 数据库连接到 ec2 实例上的 bash 脚本 运行
how to connect redshift database to a bash script running on ec2 instance
我有几个 sql 查询,我想 运行 它们针对 amazon redhshift ,基本脚本将在我的 ec2 实例上并将从那里触发。我如何提供与数据库的连接和 运行 一堆 sql 脚本?请指导
最简单的方法是在 ec2 实例上安装 postgres,然后使用 psql 命令行工具连接到 Redshift。
安装 postgres(yum 和 apt-get,选择适合您 Linux 类型的一个):
sudo apt-get install postgresql postgresql-contrib
sudo yum install postgresql postgresql-contrib
这是我的 bash 脚本中的一行代码。查看 psql 手册页以了解所有选项和连接方式。
PGPASSWORD="$RS_password" psql -a -v ON_ERROR_STOP=1 -h "$RS_DNS" -v schema=public -p "$RS_port_no" -U "$RS_user" -d "$RS_db" -f /tmp/math_$$.SQL || { echo psql command 1 failed ; exit 1; }
还有一个 -c 选项可以在命令行上传递 SQL。
我有几个 sql 查询,我想 运行 它们针对 amazon redhshift ,基本脚本将在我的 ec2 实例上并将从那里触发。我如何提供与数据库的连接和 运行 一堆 sql 脚本?请指导
最简单的方法是在 ec2 实例上安装 postgres,然后使用 psql 命令行工具连接到 Redshift。
安装 postgres(yum 和 apt-get,选择适合您 Linux 类型的一个):
sudo apt-get install postgresql postgresql-contrib
sudo yum install postgresql postgresql-contrib
这是我的 bash 脚本中的一行代码。查看 psql 手册页以了解所有选项和连接方式。
PGPASSWORD="$RS_password" psql -a -v ON_ERROR_STOP=1 -h "$RS_DNS" -v schema=public -p "$RS_port_no" -U "$RS_user" -d "$RS_db" -f /tmp/math_$$.SQL || { echo psql command 1 failed ; exit 1; }
还有一个 -c 选项可以在命令行上传递 SQL。