zoukankan      html  css  js  c++  java
  • AWS Redshift 采坑记

    1.不要使用快速启动集群的方式建立,否则vpc是一个巨坑

    2.要配置对应的Role 并配置化 role arn

    3..net 连接类

    using Amazon.Redshift;
    using Amazon.Redshift.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Odbc;
    using System.Text;
    
    namespace eXconsole
    {
         public  class redshiftdb
        {
            public void TestConnectivityOnMasterNode(string clusterName)
            {
                using (IAmazonRedshift redshiftClient = new AmazonRedshiftClient())
                {
                    try
                    {
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();
                        DescribeClustersRequest describeClustersRequest = new DescribeClustersRequest() { ClusterIdentifier = clusterName };
                        DescribeClustersResponse describeClustersResponse = redshiftClient.DescribeClustersAsync().GetAwaiter().GetResult();
                        Cluster firstMatch = describeClustersResponse.Clusters[0];
    
                        String mainDbName = firstMatch.DBName;
                        String endpointAddress = firstMatch.Endpoint.Address;
                        int endpointPort = firstMatch.Endpoint.Port;
                        string masterUsername = firstMatch.MasterUsername;
                        string password = "your master password";
    
    
                        string odbcConnectionString = string.Concat("Driver={PostgreSQL Unicode}; Server=", endpointAddress
                            , "; Database=", mainDbName, "; UID=", masterUsername, "; PWD=", password
                            , "; Port=", endpointPort);
                        string odbcConnectionDsn = "DSN=UrlsRedShiftDb";
                        string query = "SELECT datname FROM pg_database WHERE datistemplate = false;";
    
                        using (OdbcConnection conn = new OdbcConnection(odbcConnectionString))
                        {
                            try
                            {
                                conn.Open();
                                OdbcDataAdapter da = new OdbcDataAdapter(query, conn);
                                da.Fill(ds);
                                dt = ds.Tables[0];
                                foreach (DataRow row in dt.Rows)
                                {
                                    Console.WriteLine(row["datname"]);
                                }
    
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Exception caught while communicating with RedShift master node: ");
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                    catch (AmazonRedshiftException e)
                    {
                        Console.WriteLine("Postgresql command execution on master node has failed.");
                        Console.WriteLine("Amazon error code: {0}",
                            string.IsNullOrEmpty(e.ErrorCode) ? "None" : e.ErrorCode);
                        Console.WriteLine("Exception message: {0}", e.Message);
                    }
                }
            }
        }
    }
  • 相关阅读:
    vue打包以及在Apache环境下的配置
    Vue.js学以致用之遇到的那些坑
    【转】frameset 框架集使用语法,常用语后台。
    基于jquery的简洁树形折叠菜单
    基于jquery的垂直滚动触发器,多参数可设置。
    基于jquery的水平滚轴组件,多参数可设置。
    计算机网络自顶向下方法【九】——安全
    计算机网络自顶向下方法【八】——链路层_2
    计算机网络自顶向下方法【七】——链路层
    计算机网络自顶向下方法【六】——网络层
  • 原文地址:https://www.cnblogs.com/Johnson-zhao/p/10758126.html
Copyright © 2011-2022 走看看