Postgres HowTos

To login

sudo su - postgres
psql
\l #lists databases
\connect database_name #to connect to that database 
\dt #lists tables

To quit

\q
exit #to get out of the postgres user

To drop tables from Postgres, documentation herearrow-up-right

You generally need to do this when there is some problem with migrations, and you need to drop a table so a migration can build it.

DROP TABLE table_name CASCADE; #to drop a table, cascades and deletes dependencies

To add tables to Postgres, documentation herearrow-up-right

In general, you shouldn't need to do this. This should always be done with migrations. Remember, you can write SQL migrations.

Last updated