Working with PostgreSQL via the Ubuntu terminal is great but sometimes I need a reminder for some of the commands. Here is a list of the things I do most often in PSQL.
- Open Postgres console:
PSQL - Quit:
\q
- List all:
\l - Connect to a database:
\c database_name - Delete database:
drop database database_name;
- List all tables:
\dt - Delete all rows in table:
delete from tablename - Drop table:
drop table table_name;
- Kitchen sink
select * from table_name; - Specific columns
select firstName, lastName from users;
- List roles
\du - Add password to role
ALTER USER davide WITH PASSWORD 'hu8jmn3';