Postgres - databases
Commands / Informational
https://quickref.me/postgres#postgresql-commands
Miscellaneous / Dump / Restore
https://quickref.me/postgres#miscellaneous
Creation
| Usage | Example |
| CREATE DATABASE database_name WITH OWNER username; | Create Database |
| CREATE TABLE table_name( column_name column_type, column_name column_type ); | Create Table |
| CREATE TABLE table_name ( column_name SERIAL PRIMARY KEY ); | Create Table w/ auto-incrementing primary key |
| CREATE USER user_name WITH PASSWORD password; | Create user |
Information
| Description | Usage |
| Get size of database | SELECT pg_size_pretty( pg_database_size('') ); |
Peer authentication failed
# command
psql -U draftsharks -W
# psql: FATAL: Peer authentication failed for user "draftsharks"
# fix
psql -U draftsharks -W -h 127.0.0.1 # wt actual f
Change postgres password
sudo -u postgres psql
# when in psql client
\password