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的资料,但是一直没有时间抽出时间 ...
随机推荐
- Failed to close the ServletOutputStream connection cleanly, Broken pipe
Problem1: 服务端报错:Broken pipejava.io.IOException: Connection timed out at sun.nio.ch.FileDispatcherImp ...
- jenkins+ant+jmeter接口自动化的持续集成
一.jmeter.jenkins安装 这里不再说明,请看上一个随笔!!! 链接:https://www.cnblogs.com/magicYJ/p/11839646.html 二.ant安装 下载地址 ...
- 1211 BBS后台管理文章添加
目录 昨日内容回顾 侧边栏inclusion_tag inclusion_tag的响应 使用 自定义inclusion_tag,标签,过滤器 文章的点赞点踩 前端 后端 校验规则 文章的评论功能 1. ...
- 结构型模式(四) 组合模式(Composite)
一.动机(Motivate) 在我们的操作系统中有文件夹的概念,文件夹可以包含文件夹,可以嵌套多层,最里面包含的是文件,这个概念和"俄罗斯套娃"很像.当然还有很多的例子,例如我们使 ...
- python - django (创建到运行流程)
a = 0 """ 1. 创建 Django 操作文件 a. cmd 中选择路径: cd C:\Users\ad\PycharmProjects\index\1\文件名 ...
- [NgRx] NgRx Entity Adapter Configuration - Understanding sortComparer and selectId
import { Course, compareCourses } from "../model/course"; import { EntityState, createEnti ...
- 导入外部proto获取商品信息
Models.proto syntax = "proto3"; package services; //商品模型 message ProdModel { int32 prod_id ...
- RookeyFrame 迁移 线下Model 新增属性 迁移 到数据库
在类库 Rookey.BusSys.Operate(类库) -> InitOperate.cs(类) -> App_Start(方法) 添加代码(举例): ToolOperate.Rep ...
- Angular动态组件
一.主页面: app.component.html: <button (click)="load();">动态</button> 2<div #dom ...
- [golang]text/template模板
这个可以用来处理text文本,不过我更偏爱做成代码生成器. [golang]text/template模板 package main import ( "os" "tex ...