【PostgreSQL】- 1.3 PostgreSQL 创建数据库(初始化)

windows环境下 postgresql v12 绿色版+postgis 3.4.1版本配置,空间数据库迁移 使用绿色版pg空间数据库,postgresql-12.17-1-windows-x64-binaries.zip,postgis-bundle-pg12-3.4.1x64.zip,配置和创建空间数据库,并对数据进行备份和还原 阅读详情

接 “【PostgreSQL】- 1.1 在 Debian 12 上安装 PostgreSQL 15”,在本小节我们进行初始化。

创建集群

初始化与创建集群

切换用户为 postgres

  ~# sudo -i -u postgres 
  ~$ mkdir /opt/pgdata/mydatabase
  ~$ pg_createcluster --datadir=/opt/pgdata/mydatabase 15 mydatabase
  Creating new PostgreSQL cluster 15/mydatabase ...
  /usr/lib/postgresql/15/bin/initdb -D /opt/pgdata/mydatabase --auth-local peer --auth-host scram-sha-256 --no-instructions
  The files belonging to this database system will be owned by user "postgres".
  This user must also own the server process.
  
  The database cluster will be initialized with locale "C".
  The default database encoding has accordingly been set to "SQL_ASCII".
  The default text search configuration will be set to "english".
  
  Data page checksums are disabled.
  
  fixing permissions on existing directory /opt/pgdata/mydatabase ... ok
  creating subdirectories ... ok
  selecting dynamic shared memory implementation ... posix
  selecting default max_connections ... 100
  selecting default shared_buffers ... 128MB
  selecting default time zone ... Asia/Shanghai
  creating configuration files ... ok
  running bootstrap script ... ok
  performing post-bootstrap initialization ... ok
  syncing data to disk ... ok
  Warning: systemd does not know about the new cluster yet. Operations like "service postgresql start" will not handle it. To fix, run:
  sudo systemctl daemon-reload
  Ver Cluster Port Status Owner    Data directory     Log file
  15  mydatabase  5432 down   postgres /opt/pgdata/mydatabase /var/log/postgresql/postgresql-15-mydatabase.log

在这里创建的 mydatabase 是一个 PostgreSQL 集群,它包含了运行一个特定版本的 PostgreSQL 所需的所有数据文件、配置文件和事务日志。命令中:

  • --datadir=/opt/pgdata/mydatabase 指定了新集群的数据目录位置。

  • 15 是 PostgreSQL 的版本号。

  • mydatabase 是这个新集群的名称。

    可以在最后看到 postgresql 集群及更多信息

  版本 15
  集群 mydatabase
  端口 5432
  状态 down
  拥有者 postgres
  数据目录 /opt/pgdata/mydatabase
  日志文件 /var/log/postgresql/postgresql-15-mydatabase.log

检查 postgresql 的新集群状态

  ~# systemctl status postgresql@15-mydatabase.service
  * postgresql@15-mydatabase.service - PostgreSQL Cluster 15-mydatabase
     Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; preset: enabled)
     Active: active (running) since Wed 2024-03-27 15:51:36 CST; 2min 38s ago
    Process: 574 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 15-mydatabase start (code=exited, status=0/SUCCESS)
   Main PID: 584 (postgres)
      Tasks: 6 (limit: 19051)
     Memory: 41.6M
        CPU: 228ms
     CGroup: /system.slice/system-postgresql.slice/postgresql@15-mydatabase.service
             |-584 /usr/lib/postgresql/15/bin/postgres -D /opt/pgdata/mydatabase -c config_file=/etc/postgresql/15/mydatabase/postgr>
             |-601 "postgres: 15/mydatabase: checkpointer "
             |-602 "postgres: 15/mydatabase: background writer "
             |-613 "postgres: 15/mydatabase: walwriter "
             |-614 "postgres: 15/mydatabase: autovacuum launcher "
             `-615 "postgres: 15/mydatabase: logical replication launcher "
  
  Mar 27 15:51:33 zh-ubds-pg01-hw8-deb12-zx-ser systemd[1]: Starting postgresql@15-mydatabase.service - PostgreSQL Cluster 15-ubiz>
  Mar 27 15:51:36 zh-ubds-pg01-hw8-deb12-zx-ser systemd[1]: Started postgresql@15-mydatabase.service - PostgreSQL Cluster 15-ubizd>

运行正常。注意这里区别与 “【PostgreSQL】- 1.1 在 Debian 12 上安装 PostgreSQL 15”初始化之前,现在为 active (running)

检查数据库

  ~# sudo -i -u postgres
  ~$ psql
  psql (15.6 (Debian 15.6-0+deb12u1))
  Type "help" for help.
  
  postgres=# \l
                                             List of databases
    Name    |  Owner   | Encoding  | Collate | Ctype | ICU Locale | Locale Provider |   Access privileges
  ----------+----------+-----------+---------+-------+------------+-----------------+-----------------------
  postgres  | postgres | SQL_ASCII | C       | C     |            | libc            |
  template0 | postgres | SQL_ASCII | C       | C     |            | libc            | =c/postgres          +
            |          |           |         |       |            |                 | postgres=CTc/postgres
  template1 | postgres | SQL_ASCII | C       | C     |            | libc            | =c/postgres          +
            |          |           |         |       |            |                 | postgres=CTc/postgres
  (3 rows)
  
  postgres=#
  

创建新用户

在实际业务环境中,不建议使用默认的 postgres 用户进行所有操作,因为这可能带来安全风险。创建具有特定权限的单独用户(如 dbadmin)是一种更好的做法。

  ~$ psql
  psql (15.6 (Debian 15.6-0+deb12u1))
  Type "help" for help.
  
  postgres=# CREATE USER dbadmin WITH PASSWORD 'my_password!';

配置外部访问权限

编辑pg_hba.conf文件以控制访问权限

编辑文件 pg_hba.conf

  vim /etc/postgresql/15/mydatabase/pg_hba.conf

添加行,例如允许来自 172.16.x.x 网段的所有 IP 地址访问数据库

  # TYPE  DATABASE        USER            ADDRESS                 METHOD  
  host    all             dbadmin         172.16.0.0/16           md5
  host    all             dbadmin         127.0.0.1/32            md5

在 pg_hba.conf 文件中,规则是按照它们出现的顺序进行评估的。这里给一个较完整的配置

  # Database administrative login by Unix domain socket
  local   all             postgres                                peer
  
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  local   all             dbadmin                                 md5
  host    all             dbadmin         127.0.0.1/32            md5
  host    all             dbadmin         172.16.0.0/16           md5
  
  # "local" is for Unix domain socket connections only
  local   all             all                                     peer
  # IPv4 local connections:
  host    all             all             127.0.0.1/32            scram-sha-256
  # IPv6 local connections:
  host    all             all             ::1/128                 scram-sha-256
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  local   replication     all                                     peer
  host    replication     all             127.0.0.1/32            scram-sha-256
  host    replication     all             ::1/128                 scram-sha-256

编辑文件 postgresql.conf 文件中的 listen_addresses 设置,确保 PostgreSQL 服务监听所有接口

  listen_addresses = '*'      # 监听所有接口  

重新加载 PostgreSQL 配置, 注意要切换到 root

  ~# systemctl restart postgresql@15-mydatabase.service

切回 postgres, 继续为 dbadmin 赋权,授予该用户 CREATEDB 和 CREATEROLE 权限,这样它就可以创建数据库和角色,但不能修改系统级别的配置或删除其他用户的数据库。

  ~# sudo -i -u postgres
  ~$ psql
  psql (15.6 (Debian 15.6-0+deb12u1))
  Type "help" for help.
  
  postgres=# ALTER USER dbadmin CREATEDB CREATEROLE;
  ALTER ROLE

创建新数据库

注意这个例子数据库与集群同名为 mydatabase

  ~# sudo -i -u postgres
  ~$ createdb -U dbadmin mydatabase
  Password:

再次查看数据库列表

  ~$ psql
  psql (15.6 (Debian 15.6-0+deb12u1))
  Type "help" for help.
  
  postgres=# \l
                                             List of databases
    Name    |  Owner   | Encoding  | Collate | Ctype | ICU Locale | Locale Provider |   Access privileges
  ----------+----------+-----------+---------+-------+------------+-----------------+-----------------------
  postgres  | postgres | SQL_ASCII | C       | C     |            | libc            |
  template0 | postgres | SQL_ASCII | C       | C     |            | libc            | =c/postgres          +
            |          |           |         |       |            |                 | postgres=CTc/postgres
  template1 | postgres | SQL_ASCII | C       | C     |            | libc            | =c/postgres          +
            |          |           |         |       |            |                 | postgres=CTc/postgres
  mydatabase    | dbadmin  | SQL_ASCII | C       | C     |            | libc            |
  (4 rows)
  

已成功创建数据库。

对 dbadmin 进行验证

  ~$ psql -U dbadmin -d mydatabase
  Password for user dbadmin:
  psql (15.6 (Debian 15.6-0+deb12u1))
  Type "help" for help.
  
  mydatabase=> SELECT version();
                                                      version
  -------------------------------------------------------------------------------------------------------------------
  PostgreSQL 15.6 (Debian 15.6-0+deb12u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
  (1 row)
  
  mydatabase=>\q
  ~$

配置防火墙规则

配置防火墙规则规范对数据库服务器的网络访问,这里包含了 ssh 协议和 ipv6

  ~# apt install ufw
  ~# ufw allow 5432/tcp
  ~# ufw allow ssh
  ~# ufw status verbose
  Status: active
  Logging: on (low)
  Default: deny (incoming), allow (outgoing), disabled (routed)
  New profiles: skip
  
  To                         Action      From
  --                         ------      ----
  5432/tcp                   ALLOW IN    Anywhere
  22/tcp                     ALLOW IN    Anywhere
  5432/tcp (v6)              ALLOW IN    Anywhere (v6)
  22/tcp (v6)                ALLOW IN    Anywhere (v6)
在一台机器上运行多个PostgreSQL实例     最近要做一些有关PostgreSQL多实例运行的例子,一般都普遍需要在不同的机器上安装上PostgreSQL Server,然后在不同的机器上进行配置,比如通过plproxy进行一些demo的设置。当然这样的需求可以通过多个虚拟机的方式实现,比如创建多个vmware的虚拟机,大家一起跑就是了。不过这样有点资源浪费,而且需要维护不同的机器。尝试着在同一台机器上运行多个PostgreSQL S 阅读详情

相关推荐

保姆级教程:手把手教你用 pg_ctl 初始化 PostgreSQL 数据库并找到配置文件

本文提供了一份详细的PostgreSQL数据库初始化指南,重点介绍如何使用pg_ctl命令创建数据库集群并定位关键配置文件postgresql.conf和pg_hba.conf。通过分步教程,帮助用户理解PostgreSQL的初始化机制,掌握数据目录设置、配置文件修改及服务启动等核心操作,解决常见安装配置问题。

weixin_29202213的博客 226

Postgresql安装、初始化及用户, 角色与权限管理

du: 可以查看所有已存在的用户/角色, 以及它们拥有的权限属性\l: 可以查看所有数据库及其属主和所有拥有权限的用户配置选择一个数据库后,\dt可以查看所有表的属主和相应用户权限select * from information_schema.role_table_grants where grantee = '用户名';可以查看指定用户拥有的所有数据库权限。

wang11876的博客 7075

linux(centos6) 下安装 postgresql-9.3.1.tar.gz

复制安装目录下的linux文件到/etc/init.d/中,并将linux名称重命名为postgresql。我的postgresql-9.3.1.tar.gz 安装包放在 /usr/local 下。在文件最后加入:PATH=$PATH:/usr/local/postgresql/bin。如果需要修改端口,可以修改 listen_addresses下一行。listen_addresses 默认是注释掉的,打开即可。在环境变量 /etc/profile 最后加入。编辑复制出来的文件,修改下图中的位置即可。

2301_79294686的博客 1085

【PostgreSQL】从零开始:(七)PostgreSQL-Initdb命令初始化数据库

initdb是PostgreSQL初始化数据库的工具,用来生成PostgreSQL的Data目录结构使用initdb创建数据库集群时,会自动初始化区域设置支持。initdb默认情况下将使用其执行环境的区域设置来初始化数据库集群,因此,如果您的系统已设置为在数据库集群中使用您想要的区域设置,那么您不需要其他任何东西去做。如果您想使用不同的区域设置(或者您不确定系统设置为哪个区域设置),您可以通过指定initdb使用哪个区域设置4>选项。--locale。

圈小圈DBA的博客 3947

PostgreSQL 数据库初始化

按照先后顺序创建 创建全局数据库(GLOBAL) 全局数据库中存储与数据库集群相关的信息,例如集群中的数据库、用户、 角色等。 用户不能连接全局数据库。 全局数据库中的数据操作由DBMS自动完成 创建临时数据库(TEMPDB) 临时数据库用于存储DBMS在运行过程中产生的临时信息,例如排序、创建hash表等。 用户不能连接临时数据库,临时数据库中的数据操作由DBM...

椟夜 6766

TwinCAT 3 实战指南:从系统配置到高级运动控制

本文详细介绍了TwinCAT 3工业自动化控制平台的实战应用,从系统配置、PLC编程到EtherCAT总线配置和高级运动控制。通过倍福(Beckhoff)的TwinCAT 3平台,工程师可以高效实现复杂的工业自动化任务,包括运动控制、PLC编程等。文章还提供了常见问题排查和性能优化技巧,帮助用户提升系统稳定性和实时性。

weixin_30831529的博客 304

postgresql 手动启动_在windows下手动初始化PostgreSQL数据库教程

环境:win7 64 sp1PG:9.3.51、创建用户postgres,密码同样是postgres:net user postgres postgres /add2、在数据库根目录下建立data目录:C:\Program Files\PostgreSQL\9.3>md data3、去掉administrator对data目录的权限:C:\Program Files\PostgreSQL\9...

weixin_39628380的博客 1198

Krylov子空间与Arnoldi过程

一、应用背景 Krylov子空间方法是模型降阶(MOR)的一种,Krylov 子空间方法就是在Krylov子空间中寻找近似解。 二、Krylov子空间 n是原始矩阵的维度,m为降阶后矩阵的维度,通常m<<n。 三、Arnoldi 过程: 计算Km 的一组正交 对应上述MGS过程的python代码: import numpy as np def arnoldi_itera...

保持写作习惯,完成知识沉淀 6001

在Linux上建立PostgreSQL数据库服务器

在上一篇文章中,我们讨论了在Linux上非常流行的MySQL数据库服务器的使用方法。在这篇文章中,我们将关注另一个选择,名为PostgreSQL的开放源码数据库。尽管MySQL是一个快速,强大和相当简单的关系型数据库管理系统,但PostgreSQL更加具有综合性,并为这种复杂性牺牲了一些速度。 如果你已经习惯于使用包含各种图标和快捷方式的界面,那么PostgreSQL非常适合你,尽管MyS

wufengpin@com 1584

MATLAB实战:手把手教你实现Gardner环路位同步(附完整代码)

本文通过MATLAB实战,详细讲解了Gardner环路位同步算法的原理与实现。内容涵盖插值滤波器、定时误差检测、环路滤波器与数控振荡器等核心模块,并提供完整代码和调试技巧,帮助读者掌握数字通信中关键的符号定时同步技术。

weixin_29048775的博客 174

分位数回归和stata

分位数回归与stata 找了半天也没找到我想看的那种完整点的stata教程,只好自己写一个了… 参考教材:《用STATA学微观计量经济学》&《高级计量经济学及STATA应用_第2版》 第一部分 纯理论 更加详细的百度吧,很长很长,这里主要是拿来和ols比较。ols是均值回归,求解的方法是残差的平方最小,而这里就是对残差的绝对值用分位数做惩罚。(思想了解一下即可) 第二部分 Stata...

Joycezzz的博客 1万+

postgresql 9.3.1 编译安装

postgresql 9.3.1 编译安装 1 编译、安装 tar -xvf postgresql-9.3.1.tar cd postgresql-9.3.1 ./configure make make install 2 创建用户及组 groupadd postgres useradd -g postgres postgres passwd postgres 3 环境设置 mkdi

kiwi的专栏 844

自动驾驶IDM与MOBIL模型

IDM模型,自动驾驶

不想学好数学的汽车工程师不是一个好的程序员 1万+

Openeuler22.03 部署 Postgresql10.5+PostGIS3.1

Openeuler22.03 部署 Postgresql10.5+PostGIS3.1

srebro.cn | 运维小弟 2729

手把手教你学Simulink--基于光伏(PV)系统的建模与仿真场景:-不同天气条件下光伏系统的输出性能分析

本文介绍了使用Simulink和Simscape Electrical工具箱进行光伏系统建模与仿真的完整流程。内容涵盖准备工作、模型构建、仿真分析三大步骤,重点演示了如何模拟不同天气条件(光照强度、温度变化)对光伏输出性能的影响。通过添加PVArray模块、配置参数、设置环境变化条件、连接测量仪器等操作,实现了光伏系统在动态天气条件下的输出特性分析。文章还提供了仿真参数设置建议和结果分析方法,帮助用户理解环境因素与光伏性能的关联性,为光伏系统设计和优化提供参考。

MHD0815的博客 189

把 ABAP 接到外部世界的几条路, 从 Web Service 到 RFC、BAPI 与 IDoc 的完整理解

摘要: ABAP 的连接能力是其长期成为企业核心的关键,不仅支持通用协议(HTTP、SOAP、XML),还保留了 SAP 特有的技术(RFC、BAPI、IDoc)。Web Service 是跨系统通信的主轴,依赖 SOAP/WSDL 实现契约化协作,而 Enterprise Service 更强调业务语义的复用与治理。经典技术如 RFC 和 BAPI 因高效稳定仍广泛使用,尤其适合紧耦合场景。ABAP 通过分层工具箱(如代理生成、服务注册)实现灵活集成,平衡新旧技术,满足多样化的企业连接需求。 (字数:15

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 138

pgrust 初始化指南:initdb 创建数据目录的完整流程

pgrust 是一个用 Rust 重写 PostgreSQL 的开源项目,目标是与 Postgres 18.3 完全兼容,目前已在超过 4.6 万条回归查询上输出一致。对新手来说,上手 pgrust 的第一步就是 **pgrust initdb 初始化**——为数据库集群创建数据目录。本文将带你完整走一遍 initdb 创建数据目录的流程,从准备工作、初始化命令到目录内部结构,一次讲清楚。 ##

gitblog_01140的博客 357

嵌入式模拟电路面试题大全及参考答案(持续更新)

高输入阻抗:由于晶体管的基极-发射极(BJT)或栅极-源极(MOSFET)电压很低,跨导放大器具有很高的输入阻抗。低输出阻抗:晶体管的集电极-发射极或漏极-源极电阻较低,提供较低的输出阻抗。电压控制:输入信号控制晶体管的跨导,从而控制输出电流。晶体管:作为放大器的核心,可以是BJT或MOSFET。偏置电路:为晶体管提供稳定的工作点,确保其在放大区域内工作。负载电阻:与晶体管的集电极或漏极连接,将电流转换为电压。晶体管的选择:根据所需的增益、速度和功率消耗选择合适的晶体管。偏置稳定性。

大模型大数据攻城狮的专栏 988

Debian6.04 Postgresql-9.1.3 安装教材

前言:本人机器:AMD64x2 4400++ 1G 内存 第一阶段-编译安装: 1,从postgresql官网下载postgresql-9.1.3.tar.bz2这个我想大家都知道的 2,把源代码复制到/usr/src/postgresql-9.1.3.tar.bz2 且 cd /usr/src 3,解压: t...

weixin_34126557的博客 137

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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...

CentOS 6.3下安装Postgresql_9.2.1数据库

操作系统: CentOS 6.3 x64 数据库版本: Postgresql 9.2.1   操作系统需要安装的lib包: yum install readline-devel yum install zlib-devel     1、  下载postgresql最新版: postgresql-9.2.1.tar.gz 2、解压文件: cd /usr/lo

William Wang的专栏 1155

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

在 Linux 上安装 PostgreSQL

PostgreSQL 的官方下载地址为: ftp://ftp.postgresql.org/pub/v7.1.3/postgresql-7.1.3.tar.gz http://www.postgresql.org/ ...

cuizhu0832的博客 85

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

centos apache php postgresql,CentOS平台下安装PostgreSQL9.3

Linux系统:CentOS 1 用root登入系统,下载postgresql9.3,解压缩,进入解压缩后的postgresql目录 2 编译、安装 #pwd #./configuLinux系统:CentOS1 用root登入系统,,下载postgresql9.3,解压缩,进入解压缩后的postgresql目录2 编译、安装#pwd#./configure --profix=/usr/local/...

weixin_35995377的博客 173

ubuntu14.04源代码安装postgresql 9.1

项目须要使用gisgraphy,怎奈gisgraphy3.0仅仅支持postgis1.5.因此仅仅能安装老版本号的posgresql和postgis了。从postgis的support matrix图能够看到postgis不同版本号支持的postgresql, 我安装的是postgresql9.1.14. 1.下载postgresql9.1版本号的源代码,http://www....

weixin_34186931的博客 138
上一篇: 【PostgreSQL】- 1.2 PostgreSQL 配置单独的数据库存储
下一篇: 【PostgreSQL】- 1.4 PostgreSQL 业务规划(创建 Schema)
星瑙提神
博客等级 码龄20年 274粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值