转自:https://www.cnblogs.com/chjbbs/p/6480687.html

Usage:
  pg_dump [OPTION]... [DBNAME] 数据库名放最后,不指定默认是系统变量PGDATABASE指定的数据库。

General options:(一般选项)
  -f, --file=FILENAME          output file or directory name导出后保存的文件名
  -F, --format=c|d|t|p         output file format (custom, directory, tar,导出文件的格式
                               plain text (default))
  -j, --jobs=NUM               use this many parallel jobs to dump并行数
  -v, --verbose                verbose mode
详细模式
  -V, --version                output version information, then exit输出版本信息, 然后退出
  -Z, --compress=0-9           compression level for compressed formats被压缩格式的压缩级别
  --lock-wait-timeout=TIMEOUT  fail after waiting TIMEOUT for a table lock在等待表锁超时后操作失败
  -?, --help                   show this help, then exit显示此帮助信息, 然后退出

Options controlling the output content:(控制输出的选项)
  -a, --data-only              dump only the data, not the schema只导出数据,不包括模式
  -b, --blobs                  include large objects in dump在转储中包括大对象
  -c, --clean                  clean (drop) database objects before recreating在重新创建之前,先清除(删除)数据库对象
  -C, --create                 include commands to create database in dump在转储中包括命令,以便创建数据库(包括建库语句,无需在导入之前先建数据库)
  -E, --encoding=ENCODING      dump the data in encoding ENCODING转储以ENCODING形式编码的数据
  -n, --schema=SCHEMA          dump the named schema(s) only只转储指定名称的模式
  -N, --exclude-schema=SCHEMA  do NOT dump the named schema(s)不转储已命名的模式
  -o, --oids                   include OIDs in dump在转储中包括 OID
  -O, --no-owner               skip restoration of object ownership in在明文格式中, 忽略恢复对象所属者
                               plain-text format

  -s, --schema-only            dump only the schema, no data只转储模式, 不包括数据(不导出数据)
  -S, --superuser=NAME         superuser user name to use in plain-text format在转储中, 指定的超级用户名
  -t, --table=TABLE            dump the named table(s) only只转储指定名称的表
  -T, --exclude-table=TABLE    do NOT dump the named table(s)只转储指定名称的表
  -x, --no-privileges          do not dump privileges (grant/revoke)不要转储权限 (grant/revoke)
  --binary-upgrade             for use by upgrade utilities only只能由升级工具使用
  --column-inserts             dump data as INSERT commands with column names以带有列名的INSERT命令形式转储数据
  --disable-dollar-quoting     disable dollar quoting, use SQL standard quoting取消美元 (符号) 引号, 使用 SQL 标准引号
  --disable-triggers           disable triggers during data-only restore在只恢复数据的过程中禁用触发器
  --exclude-table-data=TABLE   do NOT dump data for the named table(s)以INSERT命令,而不是COPY命令的形式转储数据
  --inserts                    dump data as INSERT commands, rather than COPY
  --no-security-labels         do not dump security label assignments
  --no-synchronized-snapshots  do not use synchronized snapshots in parallel jobs
  --no-tablespaces             do not dump tablespace assignments不转储表空间分配信息
  --no-unlogged-table-data     do not dump unlogged table data
  --quote-all-identifiers      quote all identifiers, even if not key words
  --section=SECTION            dump named section (pre-data, data, or post-data)
  --serializable-deferrable    wait until the dump can run without anomalies
  --use-set-session-authorization
                               use SET SESSION AUTHORIZATION commands instead of
                               ALTER OWNER commands to set ownership

Connection options:(控制连接的选项)
  -d, --dbname=DBNAME      database to dump
数据库名
  -h, --host=HOSTNAME      database server host or socket directory数据库服务器的主机名或套接字目录
  -p, --port=PORT          database server port number数据库服务器的端口号
  -U, --username=NAME      connect as specified database user以指定的数据库用户联接
  -w, --no-password        never prompt for password永远不提示输入口令

  -W, --password           force password prompt (should happen automatically)强制口令提示 (自动)

  --role=ROLENAME          do SET ROLE before dump

If no database name is supplied, then the PGDATABASE environment如果没有提供数据库名字, 那么使用 PGDATABASE 环境变量的数值. 
variable value is used.

Report bugs to <pgsql-bugs@postgresql.org>.

一: 纯文件格式的脚本: 
示例:
1. 只导出postgres数据库的数据,不包括模式 -s
   pg_dump -U postgres -f /postgres.sql -s postgres(数据库名)
2. 导出postgres数据库(包括数据)
   pg_dump -U postgres -f /postgres.sql  postgres(数据库名)
3. 导出postgres数据库中表test01的数据
   create database "test01" with owner="postgres" encoding='utf-8';(单引号,双引号不能错)
   pg_dump -U postgres -f /postgres.sql -t test01 postgres(数据库名)
4. 导出postgres数据库中表test01的数据,以insert语句的形式
   pg_dump -U postgres -f /postgres.sql -t test01 --column-inserts postgres(数据库名)
5. 恢复数据到bk01数据库
  psql -U postgres -f /postgres.sql bk01

二、 使用归档文件格式:
pg_restore
使用pg_restore纯文本恢复纯文本格式的脚本,无法恢复
[root@localhost postgres-9.3.5]# pg_restore -U postgres -d bk01  /mnt/hgfs/window\&ubuntu\ shared\ folder/vendemo.sql 
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

pg_restore和归档文件格式一起使用重建数据库。

1. 先备份: 
   pg_dump -U postgres -F t -f /vendemo.tar vendemo  备份下来有800多k
 . 恢复:
   pg_restore -U postgres -d bk01 /vendemo.tar 
2. 先备份: 
   pg_dump -U postgres -F c -f /vendemo.tar vendemo  备份下来有300多k
 . 恢复:
   pg_restore -U postgres -d bk01 /vendemo.tar

三、 压缩备份与恢复:
处理大数据库:
1. 使用压缩的转储. 使用你熟悉的压缩程序,比如说 gzip。
 . 先备份:
   pg_dump -U postgres vendemo | gzip > /vendemo.gz 备份下来只有30多k
 . 恢复:
   gunzip -c /vendemo.gz | psql -U postgres bk02
 或者
   cat /vendemo.gz | gunzip | psql -U postgres bk02
2. 使用 split。. split 命令允许你 你用下面的方法把输出分解成操作系统可以接受的大小。 比如,让每个块大小为 1 兆字节: 
 . 先备份:
   pg_dump -U postgres -d vendemo | split -b 100k - /vend/vend
   导出来的样子是   vendaa 100k
   vendab 100k
   vendac 100k
   vendad 16k
 . 恢复:
  cat /vend/vend* | psql -U postgres bk02

(转)PostgreSQL pg_dump&psql 数据的备份与恢复的更多相关文章

  1. [转帖]PostgreSQL pg_dump&psql 数据的备份与恢复

    PostgreSQL pg_dump&psql 数据的备份与恢复   https://www.cnblogs.com/chjbbs/p/6480687.html 文章写的挺好 今天试了下 挺不 ...

  2. PostgreSQL pg_dump&psql 数据的备份与恢复

    Usage:   pg_dump [OPTION]... [DBNAME] 数据库名放最后,不指定默认是系统变量PGDATABASE指定的数据库. General options:(一般选项)   - ...

  3. 【PostgreSQL】PostgreSQL操作-psql基本命令

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.建立数据库连接 ---------------- 接入PostgreSQL数 ...

  4. [转] PostgreSQL学习手册(数据表)

    from: http://www.cnblogs.com/stephen-liu74/archive/2012/04/23/2290803.html 一.表的定义: 对于任何一种关系型数据库而言,表都 ...

  5. PostgreSQL学习手册(数据表)<转>

    一.表的定义: 对于任何一种关系型数据库而言,表都是数据存储的最核心.最基础的对象单元.现在就让我们从这里起步吧.    1. 创建表:    CREATE TABLE products (      ...

  6. Oracle数据库用户数据完整备份与恢复

    使用PLSQL-Developer工具可以快速便捷地完成Oracle数据库用户.表的备份恢复. Oracle数据库用户数据完整备份与恢复 1. 备份 1.1   PL/SQL->工具->导 ...

  7. PostgreSQL操作-psql基本命令

    一.建立数据库连接----------------接入PostgreSQL数据库: psql -h IP地址 -p 端口 -U 数据库名 之后会要求输入数据库密码 二.访问数据库 1.列举数据库:\l ...

  8. 使用PostgreSQL存储时序数据

    操作系统 :CentOS7.3.1611_x64 PostgreSQL版本 :9.6 问题描述 在InfluxDB中存储时序数据时,当tag值和时间戳都相同时会执行覆盖操作.在PostgreSQL中能 ...

  9. golang自己定义数据类型查询与插入postgresql中point数据

    golang自己定义数据类型查询与插入postgresql中point数据 详细代码例如以下: package main import ( "bytes" "databa ...

随机推荐

  1. “一切都是消息”--iMSF(即时消息服务框架)入门简介

    “一切都是消息”--这是iMSF(即时消息服务框架)的设计哲学. MSF的名字是 Message Service Framework 的简称,由于目前框架主要功能在于处理即时(immediately) ...

  2. 使用 Java 8 语言功能

    Android Studio 3.0 及以上版本支持所有 Java 7 语言功能,以及部分 Java 8 语言功能(具体因平台版本而异). 本页介绍您可以使用的 Java 8 语言功能.如何正确配置项 ...

  3. 2018最新大厂Android面试真题

    前言 又到了金三银四的面试季,自己也不得不参与到这场战役中来,其实是从去年底就开始看,android的好机会确实不太多,但也还好,3年+的android开发经历还是有一些面试机会的,不过确实不像几年前 ...

  4. Microsoft .NET Core 1.0.0 VS 2015 Tooling Preview 2 Uninstall Failed

    卸载过程中总是卸载失败报0x80070001:函数不明确错误.转遍了各大论坛和QQ,最终还是在stackoverflow上找到了答案... 原因是我卸载时选择的DotNetCore.1.0.0-VS2 ...

  5. [20171218]varchar2(4000)如何保存.txt

    [20171218]varchar2(4000)如何保存.txt --//以前写的,不知道为什么被删除了,现在补上. 如果一行能被存储于一个数据块(data block)中,那么其行头(row hea ...

  6. python pip 使用时错误: Patal error in launcher:Unable to create process using '"'

    当前我的电脑配置是64位, 装有python2.7 和python 3.6 两个版本 在使用pip install mysqlclient 的时候,出现了  Patal error in launch ...

  7. 17秋 软件工程 团队第五次作业 Alpha Scrum6

    17秋 软件工程 团队第五次作业 Alpha Scrum6 今日完成的任务 世强:APP内通知消息发送; 港晨:APP前端登陆界面编写: 树民:Web后端数据库访问模块代码实现: 伟航:Web后端Re ...

  8. JDK动态代理源码解析

    动态代理.静态代理优缺点     关于JDK的动态代理,最为人熟知的可能要数Spring AOP的实现,默认情况下,Spring AOP的实现对于接口来说就是使用的JDK的动态代理来实现的,而对于类的 ...

  9. Arcgis10.3在添加XY数据时出现问题

    准备通过excel表格(xls格式)中的经纬度生成点数据,但是选择数据的时候报错:连接到数据库失败,常规功能故障,外部表不是预期的格式.如下图所示: 解决方法: 将xls格式的表格另存为csv格式,重 ...

  10. Django templates 模板的语法

    MVC 以及 MTV MVC: M : model -->> 存取数据(模型) V: view -->> 信息的展示(视图) C: controller -->> ...