postgresql 如何将默认的 postgres 超级用户重命名为“root”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9607447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:42:56  来源:igfitidea点击:

How do I rename the default postgres superuser to "root"?

postgresqlgentoo

提问by hobbes3

I currently log in to PostgreSQL using psql -U postgres. How do I rename postgresuser to root?

我目前使用psql -U postgres. 如何将postgres用户重命名为root

If I am already logged in as postgresthen trying ALTER USER postgres RENAME TO rootwill say ERROR: session user cannot be renamed.

如果我已经登录,postgres那么尝试ALTER USER postgres RENAME TO root会说ERROR: session user cannot be renamed

Is it possible to rename the user without logging as postgresuser? I don't think I have any other superuser since this is a fresh install of PostgreSQL.

是否可以在不以postgres用户身份登录的情况下重命名用户?我认为我没有任何其他超级用户,因为这是 PostgreSQL 的全新安装。

By the way, I am running Gentoo on Amazon EC2.

顺便说一下,我在 Amazon EC2 上运行 Gentoo。

回答by Joachim Isaksson

You should be able to just create a new postgres superuser called root by logging in as the postgres user and (at the shell) typing;

您应该能够通过以 postgres 用户身份登录并(在 shell 中)键入来创建一个名为 root 的新 postgres 超级用户;

createuser --superuser root
psql> create database root owner root

After that, when logged in as root, you should be able to do what you want with the postgres user.

之后,当以 root 身份登录时,您应该能够对 postgres 用户执行您想要的操作。

回答by Frank Heikens

What about:

关于什么:

ALTER ROLE postgres RENAME TO root;

using a different superuser role?

使用不同的超级用户角色?

回答by A.H.

You can try

你可以试试

update pg_authid set rolname ='root' where rolname = 'postgres';

But be aware, that munching the system catalogues by hand is always a little dangerous.

但请注意,手动咀嚼系统目录总是有点危险。