# 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** [**here**](http://www.postgresql.org/docs/9.0/static/sql-droptable.html)

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** [**here**](http://www.postgresql.org/docs/9.0/static/sql-createtable.html)

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