Remember: Terminal app is your friend, not enemy.
- install the app
- click on plus icon in the bottom left corner
- create a new server: name, version, other form fields left with default values
- click to
Initialize
- now you have default databases
- configure your $PATH for CLI commands
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
orsudo vim ~/.bash_profile
and add this line:export PATH="/Applications/Postgres.app/Contents/Versions/15/bin:$PATH"
& save, restart terminal - π
- open your terminal app (for example iTerm)
- configure your $PATH to use the included command line tools (read the point 3)
- write
psql
and submit - now you should see something like:
psql (14.6 (Homebrew), server 15.1)
which is basically welcome message - write:
create database hello;
1 - write
\l
to list all databases, is it here? 2 - π
- open your terminal
- run
pg_dump --dbname=hello --file=hello_backup_2023.sql --schema=public --inserts --username=postgres --host=localhost
- check your current folder for this new file
- π
You did backup of db via pg_dump
and now it's time to restore this dump to your local db.
- open your terminal
- locate your dump file
- write
pg_restore -U postgres -Fc -d hello < /Users/landsman/Downloads/aurora_dump.sql
- if you see any error with input, try to check the
-F
parameter 3 - π
be careful there is no confirm dialog!
- open your terminal
- write
psql
and submit - write
drop database hello;
and submit 1 - write
\l
to list all databases, is it gone? - π
To easily manage your database check out DataGrip. It have the best UX on the market. Nice to have features: CSV export & import, tree visualisation.
To configure paths for CLI commands like pg_dump use CLI tool which
, so for example: which pg_dump
should give you something like: /Applications/Postgres.app/Contents/Versions/15/bin/pg_dump
.
Footnotes
-
Note: be sure to always end your SQL statements with
;
. β© β©2 -
"The input is a PostgreSQL custom-format dump." or "input file does not appear to be a valid archive" ... mostly this error mean that your restore action used invalid format. Check format
-F
(--format=) argument. Values are: c|d|t|p ... (custom, directory, tar, plain text (default)) β©