PostgreSQL - User Management

Connect to database with specific user:

psql -d db -U user
psql -h host -d db -U user -W

Create user and do not prompt for password:

CREATE USER user WITH PASSWORD 'password';

Create user and prompt for its password:

createuser user -P

Delete user:

dropuser user

Grant privileges:

GRANT ALL PRIVILEGES ON TABLE table TO user;
GRANT ALL PRIVILEGES ON TABLE table_id_seq TO user;
GRANT ALL PRIVILEGES ON DATABASE db to user;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO user;

If cannot be dropped because some objects depend on it:

REASSIGN OWNED BY user TO postgres;
ALTER TABLE transaction_information OWNER TO postgres;
ALTER SEQUENCE transaction_information_id_seq OWNER TO postgres;
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM user;
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM user;
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM user;
REVOKE USAGE ON SCHEMA public FROM user;
DROP USER user;

Change user password:

alter user user with password 'password';