English 中文(简体)
Postgres: 将用户升级为超级用户吗?
原标题:Postgres: upgrade a user to be a superuser?

在邮箱中, 我如何改变现有用户为超级用户? 我不想删除现有用户, 原因不尽相同 。

# alter user myuser ...?
最佳回答
ALTER USER myuser WITH SUPERUSER;

您可以在"http://www.postagresql.org/docs/scurrent/static/sql-alteruser.html" rel=“noreferr”>ALTER USER的文档 上阅读更多信息。

问题回答

为了扩大上述内容,并快速参考:

  • To make a user a SuperUser: ALTER USER username WITH SUPERUSER;
  • To make a user no longer a SuperUser: ALTER USER username WITH NOSUPERUSER;
  • To just allow the user to create a database: ALTER USER username CREATEDB;

您也可以使用 CREATEROLE CREATEUSER 来允许用户使用权限,而不使其成为超级用户。

"http://www.postagresql.org/docs/text/static/sql-alteruser.html" rel="noreferrer" > Documentation

$ su - postgres
$ psql
$ du; for see the user on db
select the user that do you want be superuser and:
$ ALTER USER "user" with superuser;

May be sometimes upgrading to a superuser might not be a good option. So apart from super user there are lot of other options which you can use. Open your terminal and type the following:

$ sudo su - postgres
[sudo] password for user: (type your password here)
$ psql
postgres@user:~$ psql
psql (10.5 (Ubuntu 10.5-1.pgdg18.04+1))
Type "help" for help.

postgres=# ALTER USER my_user WITH option

并列出备选办法清单

SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB  | CREATEROLE | NOCREATEROLE |
CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | REPLICATION|
NOREPLICATION | BYPASSRLS | NOBYPASSRLS | CONNECTION LIMIT connlimit | 
[ ENCRYPTED | UNENCRYPTED ] PASSWORD  password  | VALID UNTIL  timestamp 

所以在命令行中 它会看起来像

postgres=# ALTER USER my_user WITH  LOGIN

或使用加密密码。

postgres=# ALTER USER my_user  WITH ENCRYPTED PASSWORD  5d41402abc4b2a76b9719d911017c592 ;

或在特定时间后撤销许可。

postgres=# ALTER USER my_user  WITH VALID UNTIL  2019-12-29 19:09:00 ;

运行此命令

alter user myuser with superuser;

如果要查看用户按照命令运行的权限,请查看

du

您可以创建 SUPERUSER 或促进 >USER , 因此您可以创建一个 SUPERUSER , 或促进 < USER , 用于您的情况

$ sudo -u postgres psql -c "ALTER USER myuser WITH SUPERUSER;"

或回滚

$ sudo -u postgres psql -c "ALTER USER myuser WITH NOSUPERUSER;"

以防止在设置密码时出现命令记录, 在密码前面插入空白, 但检查系统是否支持此选项 。

$  sudo -u postgres psql -c "CREATE USER my_user WITH PASSWORD  my_pass ;"
$  sudo -u postgres psql -c "CREATE USER my_user WITH SUPERUSER PASSWORD  my_pass ;"
alter user username superuser;

如果您因为使用亚马逊红流而达到此目标, 您无法指定 SUPERUSER

ALTER USER <username> SUPERUSER;

代之以指定 CREATEUSER :

ALTER USER <username> CREATEUSER;

显然, SUPERUSER 并不是亚马逊红流集群的可用用户任务。 我对此感到非常困惑。

https://docs.aws.amazon.com/redtrevention/latest/dg/r_superuses.html>https://docs.aws.amazon.com/redtreft/latest/dg/r_superusers.html

显示这一点的截图:

登录到后gres 用户的后gres 数据库 。

c postgres postgres

发布 du 命令以检查当前给用户的角色 。

Issue the command to grant superuser: alter user username with superuser;

It is quite easy to switch between making user a superuser or a regular user. First do check the permissions of all the users by using following command.

du

然后通过执行命令使用户用户超级用户

ALTER USER user_name WITH SUPERUSER;

使用跟随命令后反转

ALTER USER user_name WITH NOSUPERUSER;

for further understanding, explore the following tutorial: How to Change a User to Superuser in PostgreSQL

找到更好的命令来改变用户的状态 。

ALTER USER myuser WITH SUPERUSER PASSWORD  pgpassword  VALID UNTIL  2034-12-2 ;

Ig 到 之前有效 。 您可以使用此选项进行密码旋转和临时访问 。

例如,您可以按照 rel=“Nofollow noreferr>>>ALTER ROLE 和ALTER USER ,将用户(例如,postergres )登入,而您可以省略可选择的WITH :

ALTER ROLE john WITH SUPERUSER;

或者:

ALTER USER john WITH SUPERUSER;

此外,您还可以使用户john 成为非用户,具体如下:

ALTER ROLE john WITH NOSUPERUSER;

或者:

ALTER USER john WITH NOSUPERUSER;




相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...