Tag postgresql

Useful commands for PostgreSQL

Some useful PostgreSQL commands that I need from time to time. Execute with postgres user.

List all users

psql
\du

Remove a user

dropuser USERNAME

List all databases

psql
\list

Remove a database

dropdb DATABASENAME;

Update password of user

psql
alter user USERNAME with password 'NEWPASSWORD';

Create a database and user, assign user to database

createuser -P USERNAME 
createdb -O USERNAME DATABASENAME

Remove all tables of a schema (if all tables in a single schema)

drop schema public cascade;
create schema public;