Answers:
ALTER USER myuser WITH SUPERUSER;
您可以在文档中阅读更多内容
SELECT rolname, rolsuper FROM pg_roles;
致@masterweily
\du
列出所有用户/角色。
有时升级到超级用户可能不是一个好的选择。因此,除了超级用户以外,您还可以使用许多其他选项。打开您的终端并输入以下内容:
$ 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';
您可以创建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 myuser WITH NOSUPERUSER