Logical Backup and restore a database in PostgreSQL
Backup the database with pg_dump utility:
pg_dump -d [source-database] -f [database_backup.sql]
Example: Go to the bin directory of postgreSQL and execute the following command:
pg_dump -d testdb -U postgres -f C:\testwork\test_backup.sql
Restore the database with psql command:
psql -d [destination_database] -f [database_backup.sql]
Example:
C:\Program Files\PostgreSQL\15\bin>psql -d hello -U postgres -f C:\testwork\test_backup.sq