-
Backup and restore with CLI
sudo apt-get install postgresql-client # backup PGPASSWORD=$PASSWORD pg_dump -U $USERNAME -h $URL -p $PORT -n $SCHEMA $DATABASE > dump-file.sql # restore PGPASSWORD=$PASSWORD psql -U $USERNAME -h $URL -p $PORT $DATABASE < dump-file.sql
-
Access the database via CLI
PGPASSWORD=$PASSWORD psql -U $USERNAME -h $URL -p $PORT $DATABASE
-
foreign keys are not indexed per se -- they are only indexed on the external table as primary keys. So don't forget to index them manually
-
Best timestamp format:
timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
-
Postgres has enums:
CREATE TYPE partyws.some_enum AS ENUM ('FOO', 'BAR');
-
Debug query performance with
EXPLAIN ANALYZE ...
-
Mock DB for tests:
npm i -D @shelfio/jest-postgres