【发布时间】:2015-12-20 05:56:33
【问题描述】:
我正在试用 Go Web Programming 一书中的 Chitchat go 应用程序。原始版本有效。当我使用用户密码访问postgresql时,它可以连接到db但无法创建新用户,如下所示:
func db() (database *sql.DB) {
database, err := sql.Open("postgres", "dbname=chitchat user=tom password=tomahawk sslmode=disable")
if err != nil {
log.Fatal(err)
fmt.Println("Db connection failed")
}
return
}
这是Github上的完整代码。
但是,我找到了一个临时解决方案,但它需要授予对 chitchat 数据库中所有序列的访问权限。即使在我申请了
GRANT ALL PRIVILEGES ON DATABASE chitchat to tom;
它仍然需要手动授予每个表序列。以下是采取的步骤:
1) 授予对数据库的访问权限
GRANT all privileges on database chitchat to tom;
2) 列出 chitchat 数据库中的所有序列
SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';
3) 授予他们每个人的访问权限
GRANT all privileges on sequence users_id_seq to tom;
GRANT all privileges on sequence threads_id_seq to tom;
GRANT all privileges on sequence posts_id_seq to tom;
GRANT all privileges on sequence sessions_id_seq to tom;
有没有更好的方法?提前致谢。
【问题讨论】:
标签: postgresql go