Thursday, March 3, 2016

postgresql: get all users and alter user


Get all users:
SELECT * FROM pg_user;

SELECT usename FROM pg_user;


Rename a user:
ALTER USER bsmith RENAME TO bjohns;

Make a user superuser
ALTER USER bsmith WITH SUPERUSER;

Change a user's password:
ALTER USER bjohns PASSWORD '12345bjxy';

Set the validity of a user's password:
ALTER USER bjohns VALID UNTIL 'Dec 31 2020';

ALTER USER bjohns VALID UNTIL 'infinity';

Give a user ability to do something:
ALTER USER bjohns CREATEUSER;

ALTER USER bjohns CREATEUSER NOCREATEDB;


pg_user is a view in posgresql, having the following information about all database users.
NameTypeDescription
usenamenameUser name
usesysidoidID of this user
usecreatedbboolUser can create databases
usesuperboolUser is a superuser
usecatupdboolUser can update system catalogs. (Even a superuser cannot do this unless this column is true.)
usereplboolUser can initiate streaming replication and put the system in and out of backup mode.
passwdtextNot the password (always reads as ********)
valuntilabstimePassword expiry time (only used for password authentication)
useconfigtext[]Session defaults for run-time configuration variables


Reference:

1. PostgreSQL 9.2.25 Documentation: pg_user


                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one?Read the book free here.

No comments:

Post a Comment