我在psql中搞砸了,并在实现它们之前重命名了template0和template1.现在,当我尝试重新创建template1时,我从psql内部和form命令行中获得"权限被拒绝复制数据库'template1'".
为了节省时间,还需要了解template1与/ data/base中的操作系统读/写权限或者在template1上授予的任何其他内容.
TIA
你必须告诉PostGreSQL这template1是一个模板.如果您不这样做,如果您不是所有者,则不允许复制它:
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
Run Code Online (Sandbox Code Playgroud)
我必须阅读/src/backend/commands/dbcommands.c(由Google发现)的源代码才能理解这一点.它说:
/*
* Permission check: to copy a DB that's not marked datistemplate, you
* must be superuser or the owner thereof.
*/
if (!src_istemplate)
{
if (!pg_database_ownercheck(src_dboid, GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to copy database \"%s\"",
dbtemplate)));
}
Run Code Online (Sandbox Code Playgroud)
我发现如何在博客上做到这一点