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. 在centos7 中docker info报错docker bridge-nf-call-iptables is disabled 的解决方法

    在centos7中安装好docker以后,启动成功,运行命令 docker info ,报错: [root@iz2ze2bn5x2wqxdeq65wlpz ~]# docker info Client ...

  2. jQuery常用API之jQuery选择器

    3.jQuery常用API 3.1 jQuery选择器 3.1.1 jQuery基础选择器 原生JS获取元素的方式很多.很杂,而且兼容性情况不一致,因此jQuery给我做了封装,是获取元素统一了标准 ...

  3. 7 CentOS 7网卡配置

    首先重中之重:修改前一定要进行系统备份,如果是虚拟机进行快照 查看虚拟机的网卡配置 注意桥接模式和NAT模式     桥接模式:网络层面,虚拟机和PC处于同级地位,虚拟机直接和路由器相连     NA ...

  4. windows 如何cmd启动redis

    运行cmd 然后到redis路径 运行命令: redis-server redis.windows.conf

  5. Ubuntu18.04.2安装中文输入法

    转载请注明出处: BooTurbo  https://www.cnblogs.com/booturbo/p/11287557.html 1.英文的Ubuntu系统,首先要安装中文语言,在 Settin ...

  6. 3.1 Spark概述

    一.Spark简介 1.Spark的特点 特点1:运行速度快(内存计算,循环数据流.有向无环图设计机制) 把所有针对数据集的操作转换成一张有向无环图,整个执行引擎调度都是基于这个有向无环图,对这个有向 ...

  7. Spring Boot 调度器

    Spring Boot 可以很简单的添加一个调度任务 首先需要添加maven依赖 <dependency> <groupId>org.springframework</g ...

  8. MyBatis 使用 foreach 批量插入

    MyBatis 使用 foreach 批量插入 参考博文 老司机学习MyBatis之动态SQL使用foreach在MySQL中批量插入 使用MyBatis一次性插入多条数据时候可以使用 <for ...

  9. jenkins+maven+svn实现springboot项目的自动化部署过程

    说明:部署springboot项目的jar 前提(参考:https://www.cnblogs.com/myitnews/p/11493779.html): 全局安全配置(前面配置过) 全局工具配置( ...

  10. django之视图层和部分模板层

    视图层 小白必会三板斧(三个返回的都是HttpResponse对象,通过看源码,可以知道是内部实现) 1.HttpResponse # 返回字符串 2.render # 返回一个html页面 还可以给 ...