限制 Amazon Redshift 中架构的大小
Posted
技术标签:
【中文标题】限制 Amazon Redshift 中架构的大小【英文标题】:Restricting the size of a schema in Amazon Redshift 【发布时间】:2015-07-27 08:41:24 【问题描述】:我们在项目中使用 Amazon Redshift。
在我们的项目中,我们为不同的团队分配了不同的架构。例如,营销部门获得一个单独的架构来存储他们的表以供分析,而销售团队获得一个单独的架构。
正在发生的情况是,一组分析员用本质上更临时的表占用了数据库的大部分空间,并且不关心删除它/清除它。因此,维护自己的模式的纪律留给了各个模式所有者。时不时地,我们最终会做一次家务练习。
我想知道我们是否可以配置每个架构/数据库的大小。比方说,我们将 100 GB 分配给销售模式,50 GB 分配给市场营销等等......
【问题讨论】:
【参考方案1】:根据 Redshift 文档,Redshift 似乎没有提供限制每个架构/数据库大小的功能,但有一种解决方法。
由于您可以使用以下查询获取每个表的数据大小,因此您可以编写一个脚本来监控它们的使用情况并在超出时发送警报。然后,只需通过 cron 定期运行脚本。
查询以获取每个表的数据大小和行数select
trim(pgdb.datname) as database, trim(pgn.nspname) as schema,
trim(a.name) as Table, b.mbytes, a.rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
order by 1, 2, 3;
ex) 结果
database | schema | table | mbytes | rows
----------+---------------+-------------+--------+----------+
test_db | dev_schmea_1 | click_log | 23 | 4653
prod_db | prod_schema_1 | click_log | 16217 | 2112354
prod_db | prod_schema_1 | install_log | 5544 | 433538
查询以获取每个架构的数据大小和行数
select
trim(pgdb.datname) as database, trim(pgn.nspname) as schema,
sum(b.mbytes) as mbytes, sum(a.rows) as rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
group by pgdb.datname, pgn.nspname
order by 1, 2;
查询以获取每个数据库的数据大小和行数
select
trim(pgdb.datname) as database, sum(b.mbytes) as mbytes, sum(a.rows) as rows
from
(select db_id, id, name, sum(rows) as rows from stv_tbl_perm a group by db_id, id, name) as a
join pg_class as pgc on pgc.oid = a.id
join pg_namespace as pgn on pgn.oid = pgc.relnamespace
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, count(*) as mbytes from stv_blocklist group by tbl) b on a.id=b.tbl
group by pgdb.datname
order by 1;
【讨论】:
感谢您的回复。这有助于作为一种解决方法。【参考方案2】:此功能现在存在于 Redshift 中: Redshift Create Schema Docs
文档中的相关示例:
create schema us_sales authorization dwuser QUOTA 50 GB;
【讨论】:
以上是关于限制 Amazon Redshift 中架构的大小的主要内容,如果未能解决你的问题,请参考以下文章
Amazon Redshift VACUUM 按架构还是按数据库运行?
将数据从 Amazon S3 复制到 Redshift 并避免重复行