Skip to main content


brew info postgresql

Learn Postgres at the Playground - -

Postgres WASM -

Reserved words

Error codes


With Brew:

brew services start postgresql
brew services stop postgresql
brew services restart postgresql
brew services list

With pg_ctl:

pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop


postgres --help

Version: postgres --version or postgres -V

Check if Postgres is running: pgrep -l postgres. If there's no output it's not running.

Check the logs:

Create database: createdb dbname

Delete database: dropdb dbname

Recreate/reset database: dropdb dbname && createdb dbname


Command reference:

Start and connect to a db: psql dbname

Connect with a specific user instead of the default: psql -d dbname -U username

Print current user: \conninfo - see

List users: \du

Quit: \q

Connect to a db: \c dbname or \connect dbname. We can specify username, host, port etc.

Load .sql file: \i src/database-setup.sql

List databases: \l

List the relations (tables) of your currently connected database: \d

List tables (relations): \dt

List tables and indexes: \dti

Show table schema: \d tablename



pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop

Upgrade to new version

Eg from 13 to 14.

As explained in brew info postgresql you can do brew postgresql-upgrade-database.



At the home, click 'Add New Server', then fill the dialog with this data:

  • General tab
    • Name: Servidor Local
  • Connection tab
    • Host name/address: localhost
    • Port: 5432
    • Username: albertvilacalvo