我的做法是使用 Postgres 外部数据包装器和 dblink,
这样,红移表可以直接在 Postgres 中使用。
按照此处的说明进行设置https://aws.amazon.com/blogs/big-data/join-amazon-redshift-and-amazon-rds-postgresql-with-dblink/
该链接的重要部分是这段代码:
CREATE EXTENSION postgres_fdw;
CREATE EXTENSION dblink;
CREATE SERVER foreign_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '<amazon_redshift _ip>', port '<port>', dbname '<database_name>', sslmode 'require');
CREATE USER MAPPING FOR <rds_postgresql_username>
SERVER foreign_server
OPTIONS (user '<amazon_redshift_username>', password '<password>');
然后,对于我的用例,我设置了一个基于该索引的 postgres 物化视图。
create materialized view if not exists your_new_view as
SELECT some,
columns,
etc
FROM dblink('foreign_server'::text, '
<the redshift sql>
'::text) t1(some bigint, columns bigint, etc character varying(50));
create unique index if not exists index1
on your_new_view (some);
create index if not exists index2
on your_new_view (columns);
然后我定期运行(在 postgres 上)
REFRESH MATERIALIZED VIEW your_new_view;
或
REFRESH MATERIALIZED VIEW CONCURRENTLY your_new_view;