PostgreSQL 数据库备份与恢复 pd_dump pg_restore
备份 PG 数据库生成的文件可以有两种,一种是 SQL 文件,一种是二进制文件,二进制文件只能使用 pg_restore 进行恢复。
PostgreSQL 数据库操作简要说明
PostgreSQL数据库版本
psql --version
psql (PostgreSQL) 9.1.3
下面是在linux下的操作,在windows下面将su -postgres 换为
运行输入cmd→d:→
cd D:\Program Files\PostgreSQL\9.2\bin,下面创建表、删除表时,需要在postgres下操作,因此需要在创建删除数据库前面输入psql -u postgres
一、数据库备份
1、备份数据库结构
su - postgres
pg_dump -Fc -s -f testdbschema.sql testdb
2、备份数据库数据
su - postgres
pg_dump -Fc -a -f testdbdata.sql testdb
3、备份数据库结构和数据
su - postgres
pg_dump -Fc -f testdbschemadata.sql testdb
4、备份数据库中指定表结构
pg_dump -Fc -s -t citycode -f citycode_schema.sql testdb
5、备份数据库中指定表数据
pg_dump -Fc -a -t citycode -f citycode_data.sql testdb
.6、备份数据库中指定表(结构和数据)
pg_dump -Fc -t citycode -f citycode_schemadata.sql testdb
二、删除数据库
su - postgres
dropdb testdb
三、恢复数据库
1、创建新数据库testdb
su - postgres
createdb testdb;
2、 恢复数据结构(only schema)
su - postgres
pg_restore -s -d testdb testdbschema.sql
3、恢复数据库数据(only data)
su - postgres
pg_restore -a -d testdb testdbdata.sql
4、恢复数据库结构和数据(schema and data)
su - postgres
pg_restore -d testdb testdbschemadata.sql
5、指定表数据恢复
1)删除表
psql testdb
DROP TABLE citycode;
2)恢复表结构
pg_restore -s -t citycode -d testdb citycode_schema.sql
3)恢复表数据
pg_restore -a -t citycode -d testdb citycode_data.sql
4)恢复表(结构和数据)
pg_restore -t citycode -d testdb citycode_schemadata.sql
以上备份恢复相关操作可用于静态(无数据增长)数据库。
重要提示:pg_restore 可用来恢复pg_dump命令以 (Fc\Ft)格式备份的数据文件。执行pg_dump备份命令时若无此格式参数声明,pg_restore 恢复时可能出现错误提示“pg_restore: [archiver] input file does not appear to be a valid archive”。
pg_dump 官方文档
https://www.postgresql.org/docs/10/app-pgdump.html
pg_dumpall
https://www.postgresql.org/docs/10/app-pg-dumpall.html
pg_restore
https://www.postgresql.org/docs/10/app-pgrestore.html
PostgreSQL 数据库备份与恢复 pd_dump pg_restore的更多相关文章
- pg_restore - 从一个由 pg_dump 创建的备份文件中恢复 PostgreSQL 数据库。
SYNOPSIS pg_restore [ option...] [ filename] DESCRIPTION 描述 pg_restore 是一种用于恢复由 pg_dump(1) 创建的任何非纯文本 ...
- postgresql数据库的数据导出
一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump ...
- PPAS数据库备份与恢复
PPAS数据库备份不同于普通的Postgresql数据库的备份,因为PPAS数据库是兼容Oracle数据库的,所以会涉及到同义词.包.存储过程等,这个时候用Postgresql社区的备份与恢复工具时, ...
- linux下PostgreSQL数据库的源码安装
实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...
- Linux命令应用大词典-第42章 PostgreSQL数据库
42.1 initdb:初始化PostgreSQL数据库 42.2 pg_ctl:控制PostgreSQL服务 42.3 psql:PostgreSQL交互式客户端工具 42.4 createdb:创 ...
- PostgreSQL数据库常用脚本-初始化、备份、恢复推荐脚本
公司最近开始逐步推广使用PostgreSQL,为方便开发人员和实施人员操作,特整理数据库初始化.备份.恢复的推荐脚本如下: 1. 连接数据库 psql -h 127.0.0.1 -p 1921 -U ...
- pg_dump - 将一个PostgreSQL数据库抽出到一个脚本文件或者其它归档文件中
SYNOPSIS pg_dump [ option...] [ dbname] DESCRIPTION 描述 pg_dump 是一个用于备份 PostgreSQL 数据库的工具.它甚至可以在数据库正在 ...
- PostgreSQL 数据库备份与还原
PostgreSQL 数据库备份与还原 目录 备份 还原 栗子 备份 PostgreSQL提供的一个工具pg_dump,逻辑导出数据,生成sql文件或其他格式文件,pg_dump是一个客户端工具,可以 ...
- ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库
前段时间在园子里看到了小蝶惊鸿 发布的有关绿色版的Linux.NET——“Jws.Mono”.由于我对.Net程序跑在Linux上非常感兴趣,自己也看了一些有关mono的资料,但是一直没有时间抽出时间 ...
随机推荐
- (Linux基础学习)第三章:terminal与shell的简介和修改命令提示符颜色
第1节:terminal终端设备终端:键盘.鼠标.显示器物理终端(/dev/console):控制台console虚拟终端(tty:teletypewriters,/dev/tty# #为[1-6]) ...
- selenium 全天课整理(二)
# encoding=utf-8 ''' selenium 全天 二 ''' #unittest例子 from selenium import webdriver import unittest,ti ...
- 个性化排序算法实践(四)——GBDT+LR
本质上GBDT+LR是一种具有stacking思想的二分类器模型,所以可以用来解决二分类问题.这个方法出自于Facebook 2014年的论文 Practical Lessons from Predi ...
- 使用vue打包,vendor文件过大,或者是app.js文件很大
我的解决办法: 1.把不常改变的库放到index.html中,通过cdn引入,比如下面这样: 然后找到build/webpack.base.conf.js文件,在 module.exports = { ...
- P1072 Hankson 的趣味题[数论]
题目描述 Hanks 博士是 BT(Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲解了 ...
- javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/pay/index] again. Check your ViewResolver setup!
2019-08-08 17:12:03.544 ERROR 13748 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Se ...
- 1211 BBS后台管理文章添加
目录 昨日内容回顾 侧边栏inclusion_tag inclusion_tag的响应 使用 自定义inclusion_tag,标签,过滤器 文章的点赞点踩 前端 后端 校验规则 文章的评论功能 1. ...
- HEXO的使用
本文将总结性的介绍如何建立自己的github.io博客,后续会持续补充,进阶.感谢baixin提供的参考文章. 技术选型为github+hexo+idea,首先最简单的阐述下这个东西都干嘛的 1. 技 ...
- jdango 2.x的url配置的改变
新版本的url.py文件中,不在使用1.x的正则表达式,强制使用在程序启动的时候会提示: WARNINGS: ?: (2_0.W001) Your URL pattern '^*article/' h ...
- C#实现上传/下载Excel文档
要求 环境信息:WIN2008SERVER 开发工具:VS2015 开发语言:C# 要求: 1.点击同步数据后接口获取数据展示页面同时过滤无效数据并写入数据库,数据可导出Excel并支持分类导出 2 ...