简体   繁体   中英

Connect IntelliJ to Amazon Redshift

I'm using the latest version of IntelliJ and I've just created a cluster in Amazon Redshift. How do I connect IntelliJ to Redshift so that I can query it from my favorite IDE?

  1. Download a jdbc driver: http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html#download-jdbc-driver
  2. On IntelliJ: View |Tool Windows | Database View |Tool Windows | Database
  3. Click on "Data Source Properties" ( 在此处输入图片说明 )
  4. Click Add ( + ) and select "Database Driver":

在此处输入图片说明

  1. Uncheck "JDBC drivers", and add a jdbc driver, select a class from the dropdown and select a PostgreSQL dialect: 在此处输入图片说明

    6.Add a new connection, and use this datasource for your connection: ( + | Data Source | RedShift ).

    7.Set URL templates:

    • jdbc:redshift://[{host::localhost}[:{port::5439}]][/{database::postgres}?][\\?<&,user={user:param},password={password:param},{:identifier}={:param}>]

    • jdbc:redshift://\\[{host:ipv6:\\:\\:1}\\][:{port::5439}][/{database::postgres}?][\\?<&,user={user:param},password={password:param},{:identifier}={:param}>]

    • jdbc:redshift:{database::postgres}[\\?<&,user={user:param},password={password:param},{:identifier}={:param}>]

You can connect IntelliJ to Redshift by the using the JDBC Driver supplied by Amazon. In the Redshift Console, go to "Connect Client" to get the driver.

Then, in the IntelliJ Data Source window, add the JAR as a Driver file, and use the following settings:

  • Class: com.amazon.redshift.jdbc41.Driver
  • URL template: jdbc:redshift://{host}:{port}/{database}

Common Pitfalls:

  • If the driver file is not readable or marked as in quarantine by OS X, you won't be able to select the driver class.

For a more detailed guide, see this blog post: Connecting IntelliJ to Redshift

Note: There is no native Redshift support in IntelliJ yet. IntelliJ Issue DBE-1459

Update for 2019: I've just created a PostgreSQL connection and then filled the usual Redshift settings (don't forget port: 5439), no need to download Amazon's JDBC driver.

在此处输入图片说明

Only little issue is that the syntax check doesn't know Redshift specificities such as AS and some functions, but queries execute correctly.

Update for 2020 : PyCharm (and possibly all other JetBrains IDEs) now supports connecting to Redshift through IAM AWS credentials without manual driver installation .

Here are the detailed setup instructions:

  1. Grant a redshift:GetClusterCredentials permission to your AWS user. Either create and attach a new policy ( docs ) or use an existing one such as AmazonRedshiftFullAccess (not recommended: too permissive).

  2. Create an AWS access key (access key id + secret access key pair) for your user ( docs ).

  3. Create a text configuration file ~/.aws/credentials (no extension) with the following content ( docs ):

[default]  # arbitrary profile name, will be used later
region = <your region>
aws_access_key_id = <your access key id>  # created on the previous step
aws_secret_access_key = <your secret access key>
  1. Create a new PyCharm database connection of type Amazon Redshift and set it up ( docs ):
    1. Choose connection type = IAM cluster/region (right under the «General» tab of the connection settings window).
    2. Authentication = AWS Profile
    3. User = {your AWS login}
    4. Profile = default or the one you have used in credentials file.
      • The credentials can possibly be provided through AccessKeyID / SecretAccessKey connection settings on the «Advanced» tab but it did not work for me (due to NullPointerException if Profile field is empty).
    5. Database = {your database} , choose an existing one to not face non descriptive errors from the driver.
    6. Region = {your region}
    7. Cluster = {cluster name} , get it from Redshift AWS console .
  2. Setup the connection:
    1. Check necessary databases in the «Schemas» tab.
    2. «Advanced» tab: AutoCreate = true (literal lowercase true as the setting value). This will automatically create a new database user with your AWS login.
  3. Test connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM