To export: pg_dump -U username database_name > dump_01.pgsql
To import: psql -U username database_name < dump_01.pgsql
To provide a password, create a file ~/.pgpass
(chmod to 600) and add one line in the following format:
hostname:port:database_name:username:password
For example:
localhost:5432:some_database:myuser:378dshk2389dshkj
From time to time, I was getting an error like this on local (Mac):
ActiveRecord::ConnectionNotEstablished
connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
The remedy:
cd /opt/homebrew/var/postgresql@14
rm postmaster.pid
brew services restart postgresql
Restart on Ubunut:
sudo systemctl restart postgresql