使用PostgreSQL内建格式(custom格式)
/Library/PostgreSQL/9.6/bin/pg_dump --host localhost --port 5432 --username "postgres" --password --format custom --blobs --encoding UTF8 --no-privileges --verbose --file "/home/my/dbname.backup" --schema "app" --schema "sys" "dbname"
使用sql格式(plain格式)
/Library/PostgreSQL/9.6/bin/pg_dump --host localhost --port 5432 --username "postgres" --no-password --format plain --no-owner --encoding UTF8 --inserts --column-inserts --no-privileges --verbose --file "/home/my/dbname.sql" --schema "app" --schema "sys" "dbname"
恢复数据库(custom格式)
#覆盖已有的数据,pg_restore --host localhost --port 5432 --username "db_user" --dbname "db_name" --password --no-owner --no-privileges --clean --verbose "/home/my/dbname.backup"#新建数据库pg_restore --host localhost --port 5432 --username "db_user" --dbname "db_name" --password --no-owner --no-privileges --verbose "/home/my/dbname.backup"#差别在于是否有 --clean