Update multi schema on REDSHIFT by command line

I. Install PostgresSQL via http://www.postgresql.org/download/

  • Remember set enviroment variable on window: PGHOST = localhost

II. Install Cygwin via https://cygwin.com/install.html

III. Using Cygwin connect to PSQL

Create file .sh run on Cygwin follow below content. Remember when you using notepad++ to create file .sh YOU SHOULD change from Windows Format to UNIX Format.

  • PGOPTIONS behaves the same as the options connection parameter. We need this param because on redshift we have many schemas so before run query we need set search_path to schemas we want to update.
  • PGPASSWORD behaves the same as the password connection parameter. Use of this environment variable is not recommended for security reasons, as some operating systems allow non-root users to see process environment variables via ps; instead consider using the ~/.pgpass file
  • -U is username of Redshift cluster
  • -d is database name of Redshift
  • -p is port of Redshift
  • -h is host of Redshift

IV. Run file sh on Cygwin

sh file_name.sh