随笔 - 746  文章 - 0  评论 - 39  阅读 - 79万

Postgresql:备份与还原

逻辑备份与还原

pg_dump.exe逻辑备份

  • 是客户端工具
  • 生成的是标准的sql文件。
  • 可以选择 打包、压缩、自定义格式的不同的输出形式
  • 数据一致的,因为postgresql数据库是mvc特性的

 

与pg_dump.exe输出备份之对应的还原

  • 何种输出就需要何种逆向操作,最终就是要获得标准的sql输入

 

 

pg_dump.exe的选项    pg_dump [选项]... [数据库名字]

  • pg_dump.exe --no-owner  --no-privileges  --create
  • pg_dump.exe --no-owner  --no-privileges  --create  --inserts

一般选项:
  -f, --file=文件名        输出文件名
  -F, --format=c|t|p       输出文件格式 (定制, tar, 明文)
  -i, --ignore-version     当服务器的版本号与 pg_dump 的版本号不匹配时仍继续运行
  -v, --verbose            详细模式
  -Z, --compress=0-9       被压缩格式的压缩级别
  --help                   显示此帮助信息, 然后退出
  --version                输出版本信息, 然后退出

控制输出内容选项:
  -a, --data-only             dump only the data, not the schema  --仅备份数据。用于还原的数据库和备份的数据库结构完全一致时!

  -s, --schema-only           dump only the schema, no data  --仅备份结构。用于生成结构脚本

 

  -c, --clean                 clean (drop) schema prior to create  --重新生成目标表。和--create是不兼容选项。被还原的库应该存在!!
  -C, --create                include commands to create database in dump  --创建数据库,用于创建完全的备份。和--clean是不兼容选项。一般情况下,该选项不起作用!!

 

  -O, --no-owner              skip restoration of object ownershipin plain text format
  -x, --no-privileges         do not dump privileges (grant/revoke)

 

  -t, --table=TABLE           dump the named table(s) only
  -T, --exclude-table=TABLE   do NOT dump the named table(s)

  -n, --schema=SCHEMA         dump the named schema(s) only  --指定要导出的构架
  -N, --exclude-schema=SCHEMA do NOT dump the named schema(s) --指定要排除的构架

 

  -b, --blobs                 include large objects in dump
  -d, --inserts               dump data as INSERT commands, rather than COPY
  -D, --column-inserts        dump data as INSERT commands with column names
  -E, --encoding=ENCODING     dump the data in encoding ENCODING

 


  -o, --oids                  include OIDs in dump

  -S, --superuser=NAME        specify the superuser user name to use in plain text format


  --disable-dollar-quoting    disable dollar quoting, use SQL standard quoting
  --disable-triggers          disable triggers during data-only restore
  --use-set-session-authorization  use SESSION AUTHORIZATION commands instead of    ALTER OWNER commands to set ownership

联接选项:
  -h, --host=主机名        数据库服务器的主机名或套接字目录
  -p, --port=端口号        数据库服务器的端口号
  -U, --username=名字      以指定的数据库用户联接
  -W, --password           强制口令提示 (自动)

如果没有提供数据库名字, 那么使用 PGDATABASE 环境变量
的数值.

 

posted on   jinzhenshui  阅读(702)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

点击右上角即可分享
微信分享提示