简体   繁体   English

如何使用PG_restore备份/移动数据库?

[英]How do I use PG_restore to backup/move my DB?

I am fairly new with PQSQL and am slowly picking things up - I have added a new disk and would like to do two things: 我是PQSQL的新手,现在正在慢慢学习-我添加了一个新磁盘,想做两件事:

  1. Restore a backup to this new disk - /hda2/pgdata/ 将备份还原到此新磁盘-/ hda2 / pgdata /
  2. Move a database from /hda1/pgdata to /hda2/pgdata/ 将数据库从/ hda1 / pgdata移动到/ hda2 / pgdata /

Q1. Q1。 Use pg_restore to restore a database. 使用pg_restore还原数据库。 Check out the documentation which is very clear. 查看非常清晰的文档。

One important thing to remember, if you want to move to a later version of PostgreSQL use the later version of pg_dump to create a backup dump file. 要记住的一件事很重要,如果要迁移到更高版本的PostgreSQL,请使用更高版本的pg_dump创建备份转储文件。 For example if you want to move from PostgreSQL version 8.3 to version 8.4, then create a backup dump file using pg_dump from version 8.4 and then use pg_restore 8.4 to recreate database in the 8.4 server. 例如,如果要从PostgreSQL版本8.3迁移到版本8.4,请使用版本8.4的pg_dump创建备份转储文件,然后使用pg_restore 8.4在8.4服务器中重新创建数据库。

http://www.postgresql.org/docs/8.4/static/app-pgrestore.html http://www.postgresql.org/docs/8.4/static/app-pgrestore.html

Q2. Q2。 Backup and restore is a safe way of doing it. 备份和还原是一种安全的方法。 Before restoring one can create a tablespace on the new disk and place the database in that space. 在还原之前,可以在新磁盘上创建一个表空间并将数据库放置在该空间中。

CREATE DATABASE mydb TABLESPACE myspace;

http://www.postgresql.org/docs/8.4/interactive/manage-ag-tablespaces.html http://www.postgresql.org/docs/8.4/interactive/manage-ag-tablespaces.html

Simple command to restore database 还原数据库的简单命令

  1. Open PSQL Command console 打开PSQL命令控制台
  2. Provide credentials 提供凭证
  3. go to specific database that you need to restore (If the dataabse is not there Create empty database 转到需要还原的特定数据库(如果没有数据库)创建空数据库

/i < sql Dump file Path > eg \\i /usr/local/pgsql/db20121109.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM