[完整版]Postgresql 数据库 备份以及恢复的过程

news/2024/7/2 16:55:06 标签: 数据库, 操作系统

0. 准备工作

linux机器上面 必须安装上pg数据库
然后 需要将 pg的主程序目录 放到环境变量里面去  便于执行命令.

1. 先备份

1. 备份目标数据库:
pg_dump -h 10.24.193.25 -U postgres -p 5432  -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 小写指代目标.

 

转载于:https://www.cnblogs.com/jinanxiaolaohu/p/11447639.html


http://www.niftyadmin.cn/n/1536536.html

相关文章

Java多线程-线程的同步与锁

一、同步问题提出 线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏。例如:两个线程ThreadA、ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据。 package cn.thread;public class Foo {private int x 100;public in…

C++随机数的用法

学过别的高级语言的都知道,产生随机数用的都是类似于random这样的字符,c也不例外,在C中使用的是rand()函数,但是不同的是,如果在C中只使用了例如 "int i;irand();"这样,使用程序会发现每次得到的随机数都是一…

​2023年湖北黄冈安管三类人员个人可以报名吗 ?报名时间是什么时候?

2023年湖北黄冈安管三类人员个人可以报名吗 ?报名时间是什么时候? 个人不可以报名。安管三类人员包括建筑施工企业主要负责人、建筑施工企业项目负责人以及建筑施工企业专职安全生产管理人员,他们是对本企业安全生产工作负责的三类人员&#…

PostgreSQL 修改设置数据库的默认用户以及权限.

1. 登录PG数据库. psql -U postgres 界面效果为: [rootcentos76 ~]# psql -U postgres psql (10.7) Type "help" for help.postgres# 其实这里面有一个主意事项. psql 的 命令执行 其实是在环境变量里面的 我这边使用的是rpm 方式安装的pg 数据库. 2. 简单说一下pg…

(转载)C/C++排序算法

排序算法是一种基本并且常用的算法。由于实际工作中处理的数量巨大,所以排序算法对算法本身的速度要求很高。而一般我们所谓的算法的性能主要是指算法的复杂度,一般用O方法来表示。在后面我将给出详细的说明。 对于排序的算法我想先做一点简单的介绍&…

ESXi 虚拟机 提示 无法打开本地虚拟机的 xxx.vmx 的本地管道的 问题解决.

1. 今天同事与我联系, 说一个虚拟机出现连不上, vcenter控制台关闭虚拟机之后 再次打开报错: 2. 自己最开始的解决方法 移除虚拟机, 进入服务器的datastore 重新注册, 结果发现问题更加严重, 虚拟机直接无法使用了. 3. 问题解决的方法与思路来源. 3.0 重新注册之后 有这么个提示…

统计学习方法概论

统计学习的 特点是:关于计算机基于数据构建概率统计模型并运用模型对数据进行预测和分析的一门学科 对象是:数据 目的是:进行预测与分析 目标是:从假设空间中选取最优模型 方法是:监督学习(重点&#xff09…

11-5 一点记录

转载于:https://www.cnblogs.com/ganmk--jy/p/6032787.html