PostgreSql

Connect to PostgreSql

psql -h <hostname> -p <port> -U <username> -d <database>
psql -h myhost -p 5432 -U myapplicationuser -d applicationdb
  • With host
postgresql://<username>:<password>@<hostname>:<port>/<database>
psql postgresql://myapplicationuser:mypass@myhost:1234/applicationdb

Basic usage

List all database

\l

Connect to specific database

\c <db_name>
\c users

List all tables in database

\d

List all details with the tables

\d+ <table_name>

Delete stuff

Delete database

DROP DATABASE <database_name>;

Delete tables

DROP TABLE <table_name>;

Create user

CREATE USER <user_name> WITH PASSWORD '<user_password>' SUPERUSER;
ALTER ROLE <user_name> WITH LOGIN;

Exit

quit