pg_dump/pg_restore备份和恢复

pg_restore恢复备份(记录一下) pg_restore 名称 pg_restore – 从一个由pg_dump创建的归档文件恢复一个PostgreSQL数据库 大纲 pg_restore [connection-option…] [option…] [filename] 描述 pg_restore是一个用来从pg_dump创建的非文本格式归档恢复PostgreSQL数据库的工具。它将发出必要的命令把该数据库重建成它被保存时的状态... 阅读详情

postgresql-10.4数据库备份与恢复

postgresql数据库的备份与恢复需要用到pg_dump、pg_restore、以及psql,这些命令位于pg数据库安装目录的bin目录下。(若设置了PGHOME,则可以直接使用)
pg_dump介绍
[peter@localhost bin]$ ./pg_dump --help
pg_dump dumps a database as a text file or to other formats.

Usage:(用法)
  pg_dump [OPTION]... [DBNAME]

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  在等待表锁超时后操作失败
  --no-sync                    do not wait for changes to be written safely to disk 不用等待更改,安全的写入磁盘 
  -?, --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 在转储中包含大对象
  -B, --no-blobs               exclude 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) 不转储权限
  --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在只恢复数据的过程中禁用触发器
  --enable-row-security        enable row security (dump only content user has
                               access to) 启用行安全性(仅转储用户能访问的内容)
  --exclude-table-data=TABLE   do NOT dump data for the named table(s) 不转储指定的表的数据
  --if-exists                  use IF EXISTS when dropping objects 删除对象时使用
  --inserts                    dump data as INSERT commands, rather than COPY  以INSERT命令,而不是COPY命令的形式转储数据
  --no-publications            do not dump publications 不要转储出版物
  --no-security-labels         do not dump security label assignments 不转储安全标签分配
  --no-subscriptions           do not dump subscriptions 不要转储订阅
  --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 等待转储可以正常运行
  --snapshot=SNAPSHOT          use given snapshot for the dump 使用给定的转储快照
  --strict-names               require table and/or schema include patterns to
                               match at least one entity each 要求表和/或模式包含到的模式每个至少匹配一个实体
  --use-set-session-authorization
                               use SET SESSION AUTHORIZATION commands instead of
                               ALTER OWNER commands to set ownership 使用SET会话授权命令而不是ALTER OWNER命令设置所有权

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
variable value is used.
pg_restore介绍
[peter@localhost bin]$ ./pg_restore --help
pg_restore restores a PostgreSQL database from an archive created by pg_dump.

(pg_restore从pg_dump创建的存档中还原PostgreSQL数据库)

Usage:
  pg_restore [OPTION]... [FILE]

提示:pg_restore 选项参考pg_dump选项。

psql介绍
[peter@localhost bin]$ psql --help
psql is the PostgreSQL interactive terminal.(psql是PostgreSQL交互终端。)

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

General options:(一般选项)
  -c, --command=COMMAND    run only single command (SQL or internal) and exit
  -d, --dbname=DBNAME      database name to connect to (default: "peter")
  -f, --file=FILENAME      execute commands from file, then exit
  -l, --list               list available databases, then exit
  -v, --set=, --variable=NAME=VALUE
                           set psql variable NAME to VALUE
                           (e.g., -v ON_ERROR_STOP=1)
  -V, --version            output version information, then exit
  -X, --no-psqlrc          do not read startup file (~/.psqlrc)
  -1 ("one"), --single-transaction
                           execute as a single transaction (if non-interactive)
  -?, --help[=options]     show this help, then exit
      --help=commands      list backslash commands, then exit
      --help=variables     list special variables, then exit

Input and output options:(输入输出选项)
  -a, --echo-all           echo all input from script
  -b, --echo-errors        echo failed commands
  -e, --echo-queries       echo commands sent to server
  -E, --echo-hidden        display queries that internal commands generate
  -L, --log-file=FILENAME  send session log to file
  -n, --no-readline        disable enhanced command line editing (readline)
  -o, --output=FILENAME    send query results to file (or |pipe)
  -q, --quiet              run quietly (no messages, only query output)
  -s, --single-step        single-step mode (confirm each query)
  -S, --single-line        single-line mode (end of line terminates SQL command)

Output format options:(输出格式选项)
  -A, --no-align           unaligned table output mode
  -F, --field-separator=STRING
                           field separator for unaligned output (default: "|")
  -H, --html               HTML table output mode
  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \pset command)
  -R, --record-separator=STRING
                           record separator for unaligned output (default: newline)
  -t, --tuples-only        print rows only
  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)
  -x, --expanded           turn on expanded table output
  -z, --field-separator-zero
                           set field separator for unaligned output to zero byte
  -0, --record-separator-zero
                           set record separator for unaligned output to zero byte

Connection options:(连接选项)
  -h, --host=HOSTNAME      database server host or socket directory (default: "local socket")
  -p, --port=PORT          database server port (default: "5432")
  -U, --username=USERNAME  database user name (default: "peter")
  -w, --no-password        never prompt for password
  -W, --password           force password prompt (should happen automatically)

For more information, type "\?" (for internal commands) or "\help" (for SQL commands) from within psql, or consult the psql section in the PostgreSQL documentation.

例子

纯文本格式的脚本
  • 只导出postgres数据库的数据,不包括模式 -s

    pg_dump -U postgres -f /home/peter/Desktop/pg1.sql -s postgres

  • 导出postgres数据库(包括数据)

    pg_dump -U postgres -f /home/peter/Desktop/pg2.sql postgres

  • 导出postgres数据库中表test1的数据

    pg_dump -U postgres -f /home/peter/Desktop/t1.sql -t test1 postgres

  • 导出postgres数据库中表test1的数据,以insert语句的形式

    pg_dump -U postgres -f /home/peter/Desktop/t2.sql -t test1 --column-inserts postgres

    相关代码如下

[peter@localhost Desktop]$ cd /opt/pg10.4/bin
[peter@localhost bin]$ ./pg_dump -U postgres -f /home/peter/Desktop/pg1.sql -s postgres
[peter@localhost bin]$ ./pg_dump -U postgres -f /home/peter/Desktop/pg2.sql  postgres
[peter@localhost bin]$ ./pg_dump -U postgres -f /home/peter/Desktop/t1.sql  -t test1 postgres
[peter@localhost bin]$ ./pg_dump -U postgres -f /home/peter/Desktop/t2.sql  -t test1 --column-inserts postgres
  • 恢复数据到postgres10数据库

psql -U postgres -f /home/peter/Desktop/pg2.sql postgres10

使用归档文件格式的脚本
使用pg_restore纯文本恢复纯文本格式的脚本,无法恢复
[peter@localhost bin]$ pg_restore -U postgres -d postgres10 /home/peter/Desktop/t2.sql
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.
创建测试表格
create table tbl_test (id int, info text, c_time timestamp);
insert into tbl_test select generate_series(1,100000),md5(random()::text),clock_timestamp();
  • 备份归档文件格式:-F t(备份下来有6.3MB)
    pg_dump -U postgres -F t -f /home/peter/Desktop/vendemo.tar -t tbl_test postgres

  • 恢复到postgres10数据库:
    pg_restore -U postgres -d postgres10 /home/peter/Desktop/vendemo.tar

  • 备份归档文件格式:-F c(备份下来有2.5MB)
    pg_dump -U postgres -F c -f /home/peter/Desktop/vendemo1.tar -t tbl_test postgres

  • 恢复到postgres10数据库:
    pg_restore -U postgres -d postgres10 /home/peter/Desktop/vendemo1.tar

压缩备份与恢复

处理大数据库

使用压缩的转储. 使用你熟悉的压缩程序,比如说 gzip。
  • 备份:
    pg_dump -U postgres postgres | gzip > /home/peter/Desktop/pg.gz
  • 恢复:
    gunzip -c /home/peter/Desktop/pg.gz | psql -U postgres postgres10
    或者
    cat /home/peter/Desktop/pg.gz | gunzip | psql -U postgres postgres10
使用split,split 命令允许你 你用下面的方法把输出分解成操作系统可以接受的大小。 比如,让每个块大小为 2 兆字节:
  • 备份:
    pg_dump -U postgres -d postgres | split -b 2000k - /home/peter/Desktop/vend
导出来的样子是
   vendaa 2000k
   vendab 2000k
   vendac 2000k
   vendad 434.5k
  • 恢复:
    cat /home/peter/Desktop/vend* | psql -U postgres postgres10
PG备份恢复(一) 文章目录一、逻辑备份1.1 逻辑备份工具1、pg_dump基本语法2、备份命令示例1.2 逻辑备份恢复1、pg_dump基本语法2、psql恢复指定SQL脚本3、pg_restore使用示例 一、逻辑备份 1.1 逻辑备份工具 PG提供了pg_dump、pg_dumpall两种方式进行逻辑备份,其区别就是pg_dumpall只能将数据库全部数据集dump到一个脚本文件中,而pg_dump可以选择指定数据库进行逻辑备份。两者均可以保证dump数据的一致性,且不阻塞其他会话的正常读写操作。 1、pg_dump基 阅读详情

相关推荐

PostgreSQL备份恢复命令:pg_restore恢复压缩格式(-Fc)和psql恢复文本格式(-Fp)的使用

用于恢复由pg_dump创建的 PostgreSQL 数据库备份的命令行工具。它可以恢复整个数据库或特定的表、数据、函数等。pg_restore仅可恢复由pg_dump导出的二进制格式(-Fc)的备份文件。pg_restore可以选择性地恢复数据库的不同部分,如表、索引、函数等。它支持通过选项来指定恢复的目标数据库和恢复的选项,例如并行恢复、恢复特定的表或数据。2、psql可恢复纯文本格式(-Fp),通常用于恢复小型数据库或需要手动控制恢复过程的场景pg_restore。

Tiano__的博客 1937

pg_dump和pg_restore对PostgreSql进行备份和还原

PG BACKUP

weixin_48277414的博客 1万+

PostgreSQL备份与恢复实战:从基础到高级策略

本文深入讲解PostgreSQL数据库备份与恢复的完整实战策略。从基础的逻辑备份工具pg_dump和pg_dumpall的使用详解,到高级的连续归档与时间点恢复(PITR)配置,提供了从原理到实操的全面指南,帮助构建可靠的数据安全防线,确保在数据丢失或误操作时能快速恢复。

weixin_29269441的博客 217

使用psql、pg_dump、pg_restore备份还原数据库

使用pg_restore将数据库还原。使用pg_dump将数据库备份。

昊天罔极的博客 4086

Docker中PostgreSQL数据库备份恢复全攻略:从删除到重建的完整流程

本文详细介绍了在Docker环境中PostgreSQL数据库的备份与恢复全流程,包括备份策略设计、自动化备份方案、恢复前的准备工作、完整恢复流程以及恢复后验证与优化。特别针对Docker容器特性,提供了实用的命令和技巧,帮助开发者和运维人员高效管理PostgreSQL数据库,确保数据安全与业务连续性。

weixin_30825581的博客 543

Windows 系统下 MongoDB和PostgreSQL数据库数据的备份和恢复

在 Windows 系统下进行 MongoDB 和PostgresSQL 数据库的备份(mongodump)和恢复()操作相对直接。下面我将分别介绍这两个过程。

洛阳泰山的博客 1696

解决postgreSQL 16rc1备份和恢复的问题

备份时提示错误:pg_dump: detail: server version: 16rc1;这个问题的本质是pgAdmin的安装版本低了,下载pgadmin4-8.10-x64.exe安装使用就可以解决上面的问题。PostgreSQL 16 RC1 是 PostgreSQL 16 的候选发布版本之一,在正式版本发布之前提供给社区进行测试和反馈。

精通搬砖,资深技术砖家,在软件开发,人工智能,设备开发等领域都有研究。商业合作&交流学习可私信联系。 725

yolov5深度剖析+源码debug级讲解系列(一) yolov5的架构和源码debug准备

前言 前段时间分析了yolov3的源码,这次想带着小伙伴一起把yolov5完全掌握。博主还是保持着一贯的风格,依旧采用debug级别的源码剖析。目的就是让大家可以通过一个系列的文章就把yolov5的架构、设计理念和每一行源码都弄懂。只要小伙伴可以花时间把这个系列读完,就会对yolov5的理解有所提升。 去年参加了kaggle的小麦检测比赛,yolov5在比赛的中段开始呈现霸榜趋势,超越了efficientdet。虽然最后yolov5因为权限等某些问题被kaggle官方禁用了,但是仍然体现出了其强大的能力。值

人唯优的博客 4万+

postgresql数据库备份策略

postgresql数据库备份策略

demonson的专栏 5248

【无标题】IP804A参考资料和管脚作用图

3.3V内置led控制内置EEPROM接口,用于哑应用ip804a,可集成为4X N端口PSE稳压器内置支持外部设备。多个系统和IC总线用于从每个IP804A收集PD电源状态,以支持全局电源管理。多个ip804a可以构建一个具有成本效益的PHY级PSE系统以支持PD分类和电源管理,而无需主机。基于LLDP(IEEE标准8023AT-2009的一部分),可以实时维护PSE和PD之间的动态电源管理,以提高电源效率。IP804A是一款用于POE(以太网供电)系统的4端口PSE(电源设备)控制器IC。

2301_78055735的博客 1060

【Matterport3D模拟器安装详细教程】适用于离散视觉语言导航任务的环境部署与安装

请注意,本文特指在环境下的安装!

六六六六神的博客 6794

PostgreSQL Backup and Restore with pg_dump and pg_restore

A working backup is the difference between a bad afternoon and a bad week. PostgreSQL provides and for logical backups. These client utilities work with local or remote databases and produce portable archives that you can load into a compatible PostgreSQ

allway2的博客 260

IsaacLab从入门到精通(二) 导入自定义机器人

IsaacLab系列第二讲,导入自定义的机器人及设置

DejaWu33的博客 8469

PostgreSQL十大命令行工具实战指南:psql、pg_dump、pg_restore等核心CLI详解

PostgreSQL命令行工具是数据库运维与开发的底层基础设施,其本质是基于客户端-服务端协议的可编程接口,遵循Unix哲学实现组合式操作。理解psql元命令、pg_dump逻辑备份格式选择、pg_restore并行恢复机制、pg_basebackup物理备份一致性保障等原理,能显著提升数据库可靠性、RTO/RPO控制能力及自动化水平。这些工具广泛应用于生产环境故障排查、CI/CD数据初始化、高可用架构搭建、CDC实时同步及K8s健康探针等关键场景,是DBA、后端工程师和数据工程师必须掌握的基础能力。

weixin_34101914的博客 316

【七】Hadoop3.3.4基于ubuntu24的分布式集群安装

本次安装实验基于苹果m2芯片的mac系统,使用vmware fusion搭建三台ubuntu24分布式虚拟机,确保在三台机器上安装了Java jdk8,并配置了免密码登录,网络互通,防火墙关闭,授时服务器已经同步。访问apche官网源,下载3.3.4版本,我们用二进制通用版即可,因为hadoop运行在java环境,跨平台性使得无需编译arm架构版本。至此,Hadoop的安装完成,包括hdfs文件存储系统,mapreduce计算框架,yarn资源管理系统均能正常、稳定使用。

qq_31412425的博客 2162

学Simulink--基于电力电子变换器的建模与仿真实例:LLC谐振变换器在高频AC-DC转换中的建模

本文详细介绍了使用Simulink+Simscape Electrical对LLC谐振变换器进行建模与仿真的完整流程。LLC谐振变换器因其高效率、低噪声的特点,广泛应用于高频AC-DC转换场景。文章从背景原理出发,逐步讲解系统结构设计、建模步骤(包括AC源、整流器、LLC变换器、负载等模块搭建)、控制策略实现(固定频率/变频/PID控制)和仿真设置。通过分析仿真结果的关键指标,提出参数整定和算法优化建议。该建模方法为电力电子设计人员提供了实用的仿真工具,有助于优化LLC变换器性能,缩短开发周期。

xiaoheshang_123的博客 298

PG 逻辑备份

pg_dump 只能备份单个数据库,不会导出角色和表空间相关的信息,而且恢复的时候需要创建空数据库。pg_dumpall 可以备份所有数据库,并且备份角色,表空间。

dnuiking的博客 428

RK3588在线更新系统内核的方法

《RK3588设备在线升级系统内核方法》 本文介绍了RK3588设备在线升级系统内核的简易方法。通过将新内核文件boot.img拷贝至目标主机后,使用dd命令配合关键参数(fsync确保写入磁盘、notrunc避免截断分区)进行安全更新,更新后需执行sync同步操作并重启生效。文章特别强调操作过程中断电风险,并扩展说明了Uboot的类似更新方法。该方法避免了现场设备拆卸的麻烦,为嵌入式系统维护提供了实用解决方案。

荻夜的博客 1051

psql pg_dump pg_restore等命令

每次恢复数据库,都要查一遍命令,醉了…… dropdb dbname 删除数据库 createdb dbname -O onwer   创建数据库,指定所有者,默认postgres psql -d 数据库名    连接指定的数据库 psql -d dbname -f filename(  -h host -p port)   用文件恢复数据库dbname pg_restore --dbn...

白开水的博客 1849

2024全国村级行政边界数据

五级行政区划:村边界数据产品涵盖五级行政区划:(一级行政区)省级行政区共31个其中:(台湾、香港、澳门除外);(二级行政区)地级行政区共334个其中:7个地区、3个盟、30个自治州、294个地级市;(三级行政区)县级行政区共2851个其中:1355个县、117个自治县、49个旗、3个自治旗、363个县级市、962个市辖区、1个林区、1个特区;(四级行政区)乡级行政区共40497个其中:11626个乡、1034个民族乡、20117个镇、7566个街道、151个苏木、1个民族苏木、2个县辖区公所;

J_Giser的博客 3237

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

dump的文件 查看pg_PostgreSQL数据库导出命令pg_dump详解

http://huangro.javaeye.com/blog/366038pg_dump是一个将PostgreSQL数据库保存到一个脚本或者归档文件中的工具.这个脚本文件的格式是纯文本,它包含许多SQL命令, 这些SQL命令可以用于重建该数据库并将之恢复到保存成脚本的时候的状态.要恢复这些脚本,使用 psql。 它们甚至可以用于在其它机器甚至是其它硬件体系的机器上 重建该数据库,通过对脚本进行一...

weixin_39559119的博客 1191

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

postgresql导入mysql的备份,PostgreSQL之pgdump备份恢复操作

逻辑备份在恢复时,介于逻辑备份与故障时间点之间的数据难以恢复,故一般不采取逻辑备份方式进行数据库备份,但逻辑适用于跨平台跨版本的数据迁移;逻辑备份恢复主要以下三种:pg_dumppg_dumpallcopy本小节主要讲解pg_dumppg_dump备份只能备份单个数据库,不会导出角色和表空间相关的信息-F c 备份为二进制格式,压缩存储.并且可被pg_restore用于精细还原-F p 备份为文本...

weixin_30563489的博客 364

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

postgres数据库的数据备份与恢复

psql -U sde -d geodb -c "\copy fwlzm FROM '/home/postgres/dump/fwlzm.sql'" (数据能进去,但是无法判断里面的索引是否存在,导入的时候会提示索引已存在)使用这套组合,测试了一下,恢复数据的时候,比如要恢复某个schema下面的所有数据,就需要先删除该scheme下面的所有表,然后再恢复数据。只恢复指定的schema 如果是想恢复有sde的空间数据库,好像没法单独恢复schema=sde的数据,比如下面整个语句恢复数据失败。

qq_21526409的博客 732

PostgreSQL 数据库备份还原脚本

PostgreSQL 数据库备份还原脚本

u013008898的博客 433

greenplum—监控运维

greenplum 的备份恢复

蓝魔的博客 428

PostgreSQL 中进行数据导入和导出

在 PostgreSQL 中,数据的导入和导出是数据库管理中不可或缺的操作。通过使用COPYCOPYpg_dump和pg_dumpall等工具,您可以高效地管理您的数据。掌握这些命令和技巧,将有助于提高数据管理的效率和准确性。希望本文对您了解 PostgreSQL 中的数据导入和导出有所帮助。无论是开发、维护还是数据分析,熟练运用这些工具都将使您的工作更加得心应手。如果您有更多的问题或需要深入了解,请参考 PostgreSQL 的官方文档或相关技术资源。

2509_93985794的博客 862
上一篇: pg最新源码安装插件
下一篇: 使用wireshark监控网络字节流
codepeter
博客等级 码龄6年 11粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值