Installation
Arch Linux
yay -S postgresql
su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
sudo systemctl enable postgresql
sudo systemctl start postgresql
Ubuntu / Debian
sudo apt install postgresql
Exporting / Importing
Into a sql file
sudo -u postgres pg_dump databas > /tmp/database.sql
Into a csv file
sudo -u postgres psql
\c database
\copy (SELECT * FROM table_name) TO '/tmp/table.csv' DELIMITER ',' CSV HEADER
From a sql file
sudo -u postgres psql -d database -f database.sql
From one table to another
pg_dump -U postgres -t | psql -U postgres -d
Commands
List all databases
\l
Connect to database
\c database
Common Tasks
Renaming a Table
ALTER DATABASE people RENAME TO customers;