在Postgres中使用GORM,是否可以同时创建索引?

huangapple go评论137阅读模式
英文:

Is it possible to create an index concurrently in Postgres using GORM?

问题

PostgreSQL允许使用concurrently选项创建索引(https://www.postgresql.org/docs/9.1/sql-createindex.html)。

这样可以在构建索引时不锁定表。是否可以让gorm使用这个选项?

另外,AutoMigrate()的默认行为是什么?它会等待索引成功构建后再返回吗?

英文:

Postgress allows creating indexes with the concurrently option
(https://www.postgresql.org/docs/9.1/sql-createindex.html).

This allows building the index without locking the tables.
Is it possible to allow gorm to use this option?

On the other end, what is the default behavior of AutoMigrate() will it wait until the index is successfully built before returning?

答案1

得分: 0

已经实现了该功能,现在可以通过结构元数据添加CONCURRENTLY选项:

// PostgreSQL选项
type User struct {
  Name string `gorm:"index:,option:CONCURRENTLY"`
}
  • 文档:https://gorm.io/docs/indexes.html
  • Github拉取请求:https://github.com/go-gorm/postgres/pull/47
英文:

The feature has been implemented and now is possible to add the CONCURRENTLY option via the struct metadata:

// PostgreSQL option
type User struct {
  Name string `gorm:"index:,option:CONCURRENTLY"`
}

huangapple
  • 本文由 发表于 2021年5月28日 18:05:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/67736864.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定