0. 准备工作

linux机器上面 必须安装上pg数据库
然后 需要将 pg的主程序目录 放到环境变量里面去 便于执行命令.

1. 先备份

. 备份目标数据库:
pg_dump -h 10.24.193.25 -U postgres -p -F c -f /TestPG/TestDS0816.dmp TestDS0816
# -h 小写 指向目标服务器
# -U 大写 使用的用户
# -p 小写 pg 数据库使用的端口.
# -F 指代导出格式. c 只的就是 自定义的pg_dump格式.
# -f 指代目录
# 目标数据库在最后面. man的内容为:
-F format
--format=format
Selects the format of the output. format can be one of the following: p
plain
Output a plain-text SQL script file (the default). c
custom
Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is
also compressed by default. d
directory
Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable
format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default and also supports
parallel dumps. t
tar
Output a tar-format archive suitable for input into pg_restore. The tar format is compatible with the directory format: extracting a tar-format archive produces a valid directory-format archive. However, the tar format does not support compression.
Also, when using tar format the relative order of table data items cannot be changed during restore.

2. 创建用户以及创建数据库

登录数据库

 psql -U postgres

创建用户以及创建数据库 注意 这里面有很大的一个坑  创建的时候 不区分大小写 ,但是因为恢复的区分大小写,所以必须添加 "" 双引号括住 数据库和用户的名字才可以.
(感谢平台部 刘威 协助..这一块坑了我半个多小时.) 创建用户
create role "TestDS0816" superuser login;
创建数据库
create database "TestDS0816" ;
设置密码
alter role "TestDS0816" with password 'Test6530';
退出数据库的命令为:
\q

3.执行恢复

pg_restore -U postgres -d TestDS0816 /TestPG/TestDS0816.dmp
# -U 大写 用户
# -d 小写指代目标.

[完整版]Postgresql 数据库 备份以及恢复的过程的更多相关文章

  1. postgresql数据库备份和恢复

    PostgreSQL自带一个客户端pgAdmin,里面有个备份,恢复选项,也能对数据库进行备份 恢复(还原),但最近发现数据库慢慢庞大的时候,经常出错,备份的文件过程中出错的几率那是相当大,手动调节灰 ...

  2. postgresql数据库备份和恢复(超快)

    PostgreSQL自带一个客户端pgAdmin,里面有个备份,恢复选项,也能对数据库进行备份 恢复(还原),但最近发现数据库慢慢庞大的时候,经常出错,备份的文件过程中出错的几率那是相当大,手动调节灰 ...

  3. 12 postgresql数据库备份和恢复

    数据表结构备份与恢复 备份 1.找到postgres 安装目录,在找到bin文件夹,会看到一堆exe后缀的文件,用win+r 打开cmd,将pg_dump.exe 拖进cmd黑窗口中 2.基本语法:- ...

  4. 小型网站MYSQL问题二:Percona Xtrabackup实现数据库备份和恢复

    1.安装软件仓库(不要问我为什么不用源码安装,好吧,其实我懒.) 1 2 3 4 5 6 7 8 wget https://www.percona.com/downloads/percona-rele ...

  5. PostgreSQL 数据库备份与还原

    PostgreSQL 数据库备份与还原 目录 备份 还原 栗子 备份 PostgreSQL提供的一个工具pg_dump,逻辑导出数据,生成sql文件或其他格式文件,pg_dump是一个客户端工具,可以 ...

  6. Sql Server数据库备份和恢复:原理篇

    本文与您探讨为什么Sql Server有完整备份.差异备份和事务日志备份三种备份方式,以及为什么数据库又有简单模式.完整模式和大容量日志模式这三种恢复模式.本文内容适用于2005以上所有版本的Sql ...

  7. PostgreSQL的备份和恢复

    关于PostgreSQL的备份和恢复详细信息请参阅<PostgreSQL中文文档>. 备份: #pg_dump --username=postgres v70_demo > v70_ ...

  8. 使用exp&imp工具进行数据库备份及恢复

    使用exp&imp工具进行数据库备份及恢复1.exp/imp使用方法介绍exp/imp为一种数据库备份恢复工具,也可以作为不同数据库之间传递数据的工具,两个数据库所在的操作系统可以不同.exp ...

  9. MongoDB学习总结(六) —— 数据库备份和恢复

    我们都知道数据库数据经常备份是多么的重要,MongoDB作为一个数据库系统,自然提供了完善,丰富而且好用的备份与恢复机制. 以下介绍三种数据库备份和恢复的方式 > 数据目录直接拷贝 数据库目录直 ...

随机推荐

  1. docker 安装与基本命令

    安装 Install Docker for Linux Download Docker for Mac Install Docker for Windows 镜像是docker三大核心概念中最重要的. ...

  2. 记录vue用 html5+做移动APP 用barcode做扫一扫功能时安卓 的bug(黑屏、错位等等)和解决方法

    最近做项目时,要用到扫一扫二维码的功能,在html5+里面有提供barcode功能,于是照过来用了, 写的代码如下 : 扫码页面: <style lang="less" sc ...

  3. spring boot的异常处理

    原文:https://blog.csdn.net/tianyaleixiaowu/article/details/70145251 全局异常处理是个比较重要的功能,一般在项目里都会用到. 我大概把一次 ...

  4. jQuery基础的动画里面的回调函数

    <style> *{margin:0; padding:0;} #target{ border-radius:10px; background:#eee; } .fade{/*动画起始状态 ...

  5. 通过jQuery给<li>绑定点击事件

    背景:有个需求需要js中实现li标签的事件绑定,li通过在ajax请求中动态添加,按照常理,使用jQuery,可以使用以下方法绑定点击事件: $(function(){  commonAjaxCall ...

  6. Django ajax 简单介绍

    AJAX Asynchronous Javascript And XML是 "异步Javascript和XML".即使用 Javascript 语言与服务器进行异步交互,传输的数据 ...

  7. Flask配置Cors跨域

    1 跨域的理解 跨域是指:浏览器A从服务器B获取的静态资源,包括Html.Css.Js,然后在Js中通过Ajax访问C服务器的静态资源或请求.即:浏览器A从B服务器拿的资源,资源中想访问服务器C的资源 ...

  8. SQL Server 使用union all查询多个条件数据合并分组显示,同比统计

    ),a.created_yearmonth,) created_yearmonth, a.countaccount countaccount, a.yxsl yxsl, a.sccdsl sccdsl ...

  9. Rust中的测试用例的写法

    有点类似 #[derive(Debug)] pub struct Rectangle { length: u32, width: u32, } impl Rectangle { pub fn can_ ...

  10. 201871010126 王亚涛 《面向对象程序设计(java)》 第6-7周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/nwnu-daizh/p ...