在 PostgreSQL 中執(zhí)行備份和恢復(fù)操作可以通過使用 pg_dump 和 pg_restore 工具來實(shí)現(xiàn)。
pg_dump -U username -d database_name > backup_file.sql
其中,-U 指定用戶名,-d 指定要備份的數(shù)據(jù)庫名稱,> 指定備份文件的輸出目錄。
如果只需要備份特定表,可以使用以下命令:
pg_dump -U username -d database_name -t table_name > backup_file.sql
其中,-t 指定要備份的表名。
pg_restore -U username -d database_name < backup_file.sql
其中,-U 指定用戶名,-d 指定要恢復(fù)的數(shù)據(jù)庫名稱,< 指定要恢復(fù)的備份文件。
需要注意的是,在恢復(fù)數(shù)據(jù)庫之前需要先創(chuàng)建一個(gè)空的數(shù)據(jù)庫,然后再執(zhí)行恢復(fù)操作。