postgres: upgrade a user to be a superuser?

后端 未结 7 1120
别那么骄傲
别那么骄傲 2021-01-29 17:03

In postgres, how do I change an existing user to be a superuser? I don\'t want to delete the existing user, for various reasons.

# alter user myuser ...?
         


        
7条回答
  •  悲&欢浪女
    2021-01-29 17:50

    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
    

    Also listing the list of options

    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'
    

    So in command line it will look like

    postgres=# ALTER USER my_user WITH  LOGIN
    

    OR use an encrypted password.

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

    OR revoke permissions after a specific time.

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

提交回复
热议问题