在postgres中,如何将现有用户更改为超级用户?出于各种原因,我不想删除现有用户 .
# alter user myuser ...?
要扩展上述内容并快速参考:
使用户成为超级用户: ALTER USER username WITH SUPERUSER;
ALTER USER username WITH SUPERUSER;
使用户不再是超级用户: ALTER USER username WITH NOSUPERUSER;
ALTER USER username WITH NOSUPERUSER;
只允许用户创建数据库: ALTER USER username CREATEDB;
ALTER USER username CREATEDB;
您还可以使用 CREATEROLE 和 CREATEUSER 来允许用户权限,而不必使其成为超级用户 .
CREATEROLE
CREATEUSER
Documentation
运行此命令
alter user myuser with superuser;
如果要查看用户的权限,请运行以下命令
\du
alter user username superuser;
$ su - postgres$ psql$ \du; 用于查看db上的用户选择您想要成为超级用户的用户:$ ALTER USER "user" with superuser;
su - postgres
psql
\du;
ALTER USER "user" with superuser;
可能有时升级到超级用户可能不是一个好选择 . 因此除了超级用户之外,您还可以使用许多其他选项 . 打开终端并键入以下内容:
$ 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;
Docs.
6 回答
要扩展上述内容并快速参考:
使用户成为超级用户:
ALTER USER username WITH SUPERUSER;
使用户不再是超级用户:
ALTER USER username WITH NOSUPERUSER;
只允许用户创建数据库:
ALTER USER username CREATEDB;
您还可以使用
CREATEROLE
和CREATEUSER
来允许用户权限,而不必使其成为超级用户 .Documentation
运行此命令
如果要查看用户的权限,请运行以下命令
alter user username superuser;
$
su - postgres
$
psql
$
\du;
用于查看db上的用户选择您想要成为超级用户的用户:
$
ALTER USER "user" with superuser;
可能有时升级到超级用户可能不是一个好选择 . 因此除了超级用户之外,您还可以使用许多其他选项 . 打开终端并键入以下内容:
还列出了选项列表
所以在命令行中它看起来像
或使用加密密码 .
或者在特定时间后撤消权限 .
Docs.