Tagged with “Database” (1)


PostgreSQL is a database

Initial install

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

Backup and restore

# backup a database
sudo -u postgres pg_dump database > database.sql

# restore a database
sudo -u postgres psql -d database -f database.sql

Export a table to CSV

\c database
\copy (SELECT * FROM table_name) TO '/tmp/table.csv' DELIMITER ',' CSV HEADER