zoukankan      html  css  js  c++  java
  • postgresql学习之安装篇

    ---恢复内容开始---

    安装方法:

    1、可以使用操作系统自带的安装源

    2、可以使用官网下载的源码进行安装

    3、可以使用编译好的包入.run格式的安装包安装(本文使用的是这种安装方法,下载地址http://www.postgres.cn/download)

    安装之前首先需要为postgresql数据库新建一个管理员用户:

      groupadd postgres

      mkdir /home/postgres

      useradd postgres -g postgres -s /bin/bash -b /home/postgres

    开始安装:

      安装使用root用户安装,上传了赋予文件执行权限chmod +x postgresql-9.4.5-1-linux-x64.ru。根据提示一路安装至结束。安装完了之后进入安装目录ll查看一下目录信息,会发现.cache和data两个目录是postgres用户组的。

    配置:

    进入data目录下,配置文件说明:

      pg_hba.conf--此文件是配置链接权限的,共分5列,请求连接类型--要连接的数据库--请求连接的用户--请求来的地址--请求认证的方式。默认的第一行local   all             all                                     md5,意思是本地登陆,我们本地登录不验证密码,将md5换成trust

      pg_ident.conf--此文件是配置登陆数据库所需要验证的用户名码,格式username:password

      postgresql.conf--此文件是主要数据库的配置信息,具体的每个参数含义不再列出,listen_addresses和port使用默认的。

    启动、关闭数据库:

      为管理员用户postgres配置环境变量。cd && vim .profile,我能当末尾添加如下信息:

    export PG_HOME=/opt/PostgreSQL/9.4
    export PGDATA=/opt/PostgreSQL/9.4/data
    export PATH=$PATH:$PG_HOME/bin

    当让别忘记source .profile,下面就试试效果如何,直接输入pg_ 然后使用TAB键会带出很多pg_***的文件,这就说明环境变量已生效,那就开始启动数据库吧.

    postgres@ubuntu:~$ pg_ctl start
    pg_ctl: another server might be running; trying to start server anyway
    server starting
    postgres@ubuntu:~$ 2016-06-08 22:35:40 CST FATAL: lock file "postmaster.pid" already exists
    2016-06-08 22:35:40 CST HINT: Is another postmaster (PID 2392) running in data directory "/opt/PostgreSQL/9.4/data"?

    这个错误是说postmaster.pid这个文件已经存在了,说明这个数据库已经被启动了。那就先关掉吧

    postgres@ubuntu:~$ pg_ctl stop
    waiting for server to shut down.... done
    server stopped

    然后再启动一下。

    postgres@ubuntu:~$ pg_ctl start
    server starting
    postgres@ubuntu:~$ 2016-06-08 22:37:16 CST LOG: redirecting log output to logging collector process
    2016-06-08 22:37:16 CST HINT: Future log output will appear in directory "pg_log".

    postgres@ubuntu:~$ ps -ef|grep postgres  --说明postgresql启动成功
    root 2660 1655 0 22:24 pts/2 00:00:00 su - postgres                                        --这个用户切换的进程,不用管
    postgres 2661 2660 0 22:24 pts/2 00:00:00 -su                                                --同上
    postgres 2719 1 0 22:37 pts/2 00:00:00 /opt/PostgreSQL/9.4/bin/postgres         --这个是postgresql的主进程
    postgres 2720 2719 0 22:37 ? 00:00:00 postgres: logger process                       --这个是子进程,在PostgreSQL中称为SysLogger(8.0),用于整个系统的日志输出;
    postgres 2722 2719 0 22:37 ? 00:00:00 postgres: checkpointer process              --这个是子进程,在PostgreSQL中称为Checkpointer(9.2),用于处理checkpoints;
    postgres 2723 2719 0 22:37 ? 00:00:00 postgres: writer process                        --这个是子进程,在PostgreSQL中称为BgWriter,用于将脏页刷出到磁盘;
    postgres 2724 2719 0 22:37 ? 00:00:00 postgres: wal writer process                   --这个是子进程,在PostgreSQL中称为WalWriter(8.3),处理预写日志输出;
    postgres 2725 2719 0 22:37 ? 00:00:00 postgres: autovacuum launcher process  --这个是子进程,在PostgreSQL中称为AutoVacuum(8.1),用于系统的自动清理;
    postgres 2726 2719 0 22:37 ? 00:00:00 postgres: stats collector process            --这个是子进程,在PostgreSQL中称为PgStat,用于统计数据收集。 
    postgres 2728 2661 0 22:37 pts/2 00:00:00 ps -ef
    postgres 2729 2661 0 22:37 pts/2 00:00:00 grep postgres

    此外,如果配置了副本的话,应该还有一个进程  postgres: archiver process:  在PostgreSQL中称为PgArch,用于预写日志归档;同步数据用的。

    图片来自http://wiki.postgresql.org/wiki/Pgsrcstructure

     详细关于进程的可以参考http://wiki.postgresql.org/wiki/Pgsrcstructure

    如果修改过配置需要执行pg_ctl reload重新加载数据库

    postgres@ubuntu:~$ psql -h 127.0.0.1 -p 5432
    Password:
    psql (9.3.10, server 9.4.5)
    WARNING: psql major version 9.3, server major version 9.4.
    Some psql features might not work.
    Type "help" for help.

    postgres=# l
    List of databases
    Name | Owner | Encoding | Collate | Ctype | Access privileges
    -----------+----------+----------+------------+------------+-----------------------
    postgres | postgres | UTF8 | zh_CN.utf8 | zh_CN.utf8 |
    template0 | postgres | UTF8 | zh_CN.utf8 | zh_CN.utf8 | =c/postgres +
    | | | | | postgres=CTc/postgres
    template1 | postgres | UTF8 | zh_CN.utf8 | zh_CN.utf8 | =c/postgres +
    | | | | | postgres=CTc/postgres
    (3 rows)

  • 相关阅读:
    完美世界经典版本881外挂
    ShowModal 动态创建窗体和释放窗体
    HTML 颜色代码大全
    padding margin border 的四值顺序
    三 C# Socket通信 窗体控件与多线程
    Java解压缩Zip 文件
    八 C# Socket通信 通信协议设计
    CSS+DIV实现鼠标经过背景变色
    七 C# Socket通信 阻塞性线程的快速终止
    二 C# Socket通信模式
  • 原文地址:https://www.cnblogs.com/gangdou/p/5571573.html
Copyright © 2011-2022 走看看