简体   繁体   English

Postgres索引

[英]Postgres Indexing

I am a newbie in Postgres. 我是Postgres的新手。

We have implemented SCD type-2 in our project using Postgres. 我们使用Postgres在我们的项目中实现了SCD type-2。 The input file is a full refresh file with approximately 30 million records daily. 输入文件是一个完整的刷新文件,每天有大约3000万条记录。

Account number is the key column. 帐号是关键列。

The approximate number of new records will be 20K/day. 新记录的大概数量为20K /天。 If a record is missing from the source, then that record is closed with an End date in the target. 如果源中缺少记录,则该记录将以目标中的结束日期关闭。 The approximate number of records being closed- 10k/day 关闭的大致记录数量--10k /天

The run time for the query is increasing steadily. 查询的运行时间正在稳步增加。 Will indexing help speed up the process? 索引是否有助于加快这一过程?

Any suggestion on the index to be used? 有关索引的任何建议吗?

Are those 30 million records stored as each row in the database? 这些3000万条记录是作为数据库中的每一行存储的吗? Well if it is so, then indexing (creating and maintaining) that many records will also be a burden to the database to some extent. 如果是这样,那么索引(创建和维护)许多记录在某种程度上也将成为数据库的负担。 However, there's this new index that PostgreSQL has introduced called BRIN Index which might help you a bit. 但是,PostgreSQL引入的这个新索引名为BRIN Index ,可能对你有所帮助。 I had written a blog about this some months ago. 几个月前我写了一篇关于这个的博客。 You can have a look over it and obviously research over it more. 你可以看看它,显然可以对它进行更多的研究。

http://blog.bajratechnologies.com/2016/09/16/Postgres-BRIN-Index/ http://blog.bajratechnologies.com/2016/09/16/Postgres-BRIN-Index/

You'll have too look at the execution plans of the slow queries to be able to determine if indexes will help and what indexes you should create. 您还将查看慢查询的执行计划,以确定索引是否有用以及您应创​​建哪些索引。

The correct index often helps a lot with a query, and with a read-only database you can create as many as you need. 正确的索引通常对查询有很大帮助,而对于只读数据库,您可以根据需要创建任意数量的索引。

You should make sure that any indexes are created after you load the table, since indexes slow down insert a lot. 您应确保加载表创建任何索引,因为索引会减慢插入量。 Either drop and recreate the table before the daily load or truncate and drop all the indexes. 在每日加载之前删除并重新创建表,或者截断并删除所有索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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