从文件恢复postgresql [英] Restore postgresql from files

查看:317
本文介绍了从文件恢复postgresql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题 - 我设法从我的硬​​盘驱动器意外卸载了整个PostgreSQL DBMS。我也丢失了我的数据库,并没有进行任何转储的数据。但是,我需要备份来自服务器的所有文件。是否可以以某种方式从这些文件恢复数据库?



我使用的操作系统是Debian 6,DBMS版本是PostgreSQL 8.4。



如果确实有可能,那我该如何去实现呢?



ps。对不起我的英语。

解决方案

确保您的备份是安全的。只要我们有了,我们可以重新开始。



还原PostgreSQL服务器软件(检查包标题)

  apt-get install postgresql-8.4 postgresql-client-8.4 postgresql-contrib-8.4 

停止服务器

  /etc/init.d/postgresql stop 

恢复所有的数据文件。确保所有权是正确的:

  cd /var/lib/postgresql/8.4/ 
mv main main.OLD
cp -a / path / to / backup / main。
/etc/init.d/postgresql start

检查日志(/ var / log / postgresql / ...) - 如果您的备份发生在数据库空闲时,您可能会运气。



请注意,您需要在... / main / - 数据库文件位于主/基,但也有事务日志和其他必要的位和块。



如果您遇到问题,请检查您的权限,检查postgresql.conf文件(从备份还原,如果你有它,pg_hba.conf等)。如果您正在使用pl / perl或某些较早的



,则可能还需要安装其他一些软件包。如果您收到有关丢失日志文件或错误块的问题,那意味着数据库写入磁盘时发生备份,可能会出现损坏。但是,让我们乐观,希望最好。



如果它有效,请检查一切看起来都可以,并且立即使用任何数据库的pg_dump。


I have a big problem - I managed to accidentally uninstall the whole PostgreSQL DBMS from my hard drive. I also lost my database and haven't made any dumps of the containing data. I do, however, have a backup of all files from the server. Is it possible to somehow restore the database from these files?

The OS I am using is Debian 6, and the DBMS version is PostgreSQL 8.4.

If it is indeed possible, then how should I go about achieving this?

ps. Sorry for my English.

解决方案

Make sure your backup is safe. So long as we have that we can start again.

Restore the PostgreSQL server software (check package titles)

apt-get install postgresql-8.4 postgresql-client-8.4 postgresql-contrib-8.4

Stop the server

/etc/init.d/postgresql stop

Restore all your data files. Make sure the ownership is correct:

cd /var/lib/postgresql/8.4/
mv main main.OLD
cp -a /path/to/backup/main .
/etc/init.d/postgresql start

Check the logs (/var/log/postgresql/...) - if your backup occurred while the database was idle you are probably in luck.

Note that you need everything in .../main/ - the database files are in main/base but there are the transaction logs and other assorted bits and pieces needed too.

If you get problems, check your permissions, check your postgresql.conf file (restore that from backup too if you have it, pg_hba.conf etc too). There might be some other packages you need to install too if you were using pl/perl or some such earlier

Now. if you get problems complaining about missing log-files or bad blocks then that means the backup happened while the database was writing to the disk and there may be corruption. However, let's be optimistic and hope for the best.

If it works, check everything looks OK and take a pg_dump of any databases you want straight away.

这篇关于从文件恢复postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆