Centos7安装EDB/PPAS/EPAS

企业级PG:EnterpriseDB/EDB/PPAS/EPAS

企业级PG(EnterpriseDB)
EDB官网:www.enterprisedb.com
数据库官网下载链接:www.enterprisedb.com/software-downloads-postgres
官网下载有两个版本:EDB Postgres Advanced Server 和 PostgreSQL。
阿里的云数据库PPAS版:基于PostgreSQL,高度兼容Oracle语法,由阿里云与EnterpriseDB公司合作提供。

EnterpriseDB是全球唯一一家提供基于PostgreSQL企业级产品与服务的厂商。
EnterpriseDB是PostgreSQL的一个分支,在PostgreSQL基础上,针对企业级应用进行了专门的优化,同时,增加了一系列如动态 性能调优(DynaTune)、EDB Loader、高效批量SQL处理等高级特性
EnterpriseDB的兼容性尤为突出,能兼容Oracle的数据库。

安装

安装前的准备
1.关闭firewalld防火墙和Selinux

#查看firwalld的状态
systemctl status firewalld   #也可以执行 firewall-cmd --state

#停止firewalld
systemctl stop firewalld

#禁用firewalld
systemctl disable firewalld

#查看Selinux状态
getenforce

#关闭Selinux
vim /etc/selinux/config
SELINUX=disabled

#重启服务器、立即生效配置
reboot

2.系统参数调整优化

#系统级别的最大文件句柄数量调整
cat /proc/sys/fs/file-max
383676
一般不同的系统版本,默认值会有差别,有的是383676,有的是592409,一般系统的默认值够用,不用修改,我这里永久性的调整为100万:
vim /etc/sysctl.conf
fs.file-max = 1000000

#立即生效
sysctl -p

#查看用户的所有进程级别的限制
ulimit  -a
core file size  (blocks, -c) 0  //内核文件的大小限制
data seg size   (kbytes, -d) unlimited  //最大数据大小限制,建议用户设置为unlimited
scheduling priority     (-e) 0  //调度优先级,一般根据nice设置
file size   (blocks, -f) unlimited  //最大文件大小限制,建议用户设置为unlimited
pending signals     (-i) 15086  //信号可以被挂起的最大数,这个值针对所有用户,表示可以被挂起/阻塞的最大信号数量
max locked memory   (kbytes, -l) 64  //内存锁定值的限制
max memory size     (kbytes, -m) unlimited  //最大可以使用内存限制
open files      (-n) 65535  //进程打开文件数的限制。默认值是1024,默认值太小、通常需要调整该值为65535或unlimited
pipe size    (512 bytes, -p) 8  //管道文件大小限制
POSIX message queues (bytes, -q) 819200  //可以创建使用POSIX消息队列的最大值,单位为bytes
real-time priority      (-r) 0  //限制程序实时优先级的范围,只针对普通用户
stack size      (kbytes, -s) 8192  //限制进程使用堆栈段的大小
cpu time   (seconds, -t) unlimited  //程序占用CPU的时间,单位是秒
max user processes      (-u) 15086  //限制程序可以fork的进程数,只对普通用户有效
virtual memory  (kbytes, -v) unlimited  //限制进程使用虚拟内存的大小,建议用户设置为unlimited
file locks      (-x) unlimited  //锁定文件大小限制

#用户进程级别的限制修改:可以通过修改/etc/security/limits.conf文件实现永久生效的修改
#修改表达式解释:
<domain>    <type>  <item>  <value>

<domain>:
   ftpuser //用户
   @student //组
   * //通配符,所有用户
   % //通配符,用在组的语法
   
<type>:
  soft //软限制。警告的设定,可以超过这个设定值,但是若超过则有警告信息
  hard //硬限制。严格的设定,必定不能超过这个设定的数值
   
<item>:
  core //限制内核文件的大小
  data //最大数据大小限制
  fsize //最大文件大小限制
  memlock //最大锁内存地址空间
  nofile //进程打开文件数的限制
  rss //最大持久驻留内存
  stack //最大堆栈大小
  cpu //最大CPU运行时间
  nproc //最大进程数
  as //地址空间限制
  maxlogins //最大登录次数,用户
  maxsyslogins //最大登录次数,登录此系统的最大次数
  priority //用户运行的优先级
  locks //用户锁定文件数限制
  sigpending //信号可以被挂起的最大数
  msgqueue //可以创建使用POSIX消息队列的最大值
  nice //可以设置的优先级,nice [-20, 19]
  rtprio //实时优先级,数字大的优先级高

#进程级打开文件句柄数量
#在文件末尾添加配置内容:

echo "
* soft nofile 65535
* hard nofile 70000
" >> /etc/security/limits.conf

注意:
1)修改后用户需要重新登录才能生效
2)如果调整用户进程级限制达到系统级的最大数时,还需要调整系统级的最大值

拷贝安装包解压
mkdir -p /opt/edb
cp edb-as10-server-10.12.20-1-linux-x64.run /opt/edb
cd /opt/edb

安装时,可以选择先编辑好配置文件后进行无人值守安装,也可以step by step命令行交互式安装。我采用命令行交互式安装。

创建安装目录:
mkdir -p /opt/edb/as10
注意:这里只需要创建安装目录就行了。
刚开始我以root身份还创建了2个子目录 /opt/edb/as10/data 和 /opt/edb/as10/data/pg_wal 用于后面的指定的数据目录和REDO(WAL)目录。结果导致安装失败。

初步分析了一下,怀疑可能是root创建的这两个目录后续安装是自动创建的postgres无法写这两个目录导致问题。
所以提前不要创建目录,安装的时候自动创建postgres用户后,会以该用户来创建对应的目录和文件。否则/opt/edb/as10/data/下面的目录和文件的用户和组有问题。
[root@localhost edb]# ls -l /opt/edb/as10/data/
total 64
drwx------ 5 postgres postgres    38 Apr 18 20:17 base
-rw------- 1 postgres postgres    46 Apr 18 20:17 current_logfiles
drwx------ 2 postgres postgres     6 Apr 18 20:17 dbms_pipe
drwx------ 2 postgres postgres  4096 Apr 18 20:17 global
drwxr-xr-x 2 postgres postgres    67 Apr 18 20:17 log
drwx------ 2 postgres postgres     6 Apr 18 20:17 pg_commit_ts
................

数据目录(Data Directory)、REDO(WAL)目录(Write-Ahead Log (WAL) Directory)

执行安装脚本
cd /opt/edb
chmod u+x edb-as10-server-10.12.20-1-linux-x64.run
./edb-as10-server-10.12.20-1-linux-x64.run

Press [Enter] to continue:    #前面License阅读,直接回车继续

Do you accept this license? [y/n]: y   #同意它的License

Installation Directory [/opt/edb/as10]:   #我这里不指定,直接回车使用默认的安装路径/opt/edb/as10

安装组件的选择配置
EDB Postgres Advanced Server [Y/n] :Y
pgAdmin 4 [Y/n] :n    #是否安装客户端连接工具。pgAdmin是一个很好的PG图形化管理工具
StackBuilder Plus [Y/n] :n     
Command Line Tools [Y/n] :Y     
Is the selection above correct? [Y/n]: Y

数据目录和REDO(WAL)目录,建议两者使用不同的块设备分区,并确保使用足够大的空间。WAL的目录建议IOPS极好。我只是测试环境,无特殊要求,不独立块设备。
Additional Directories     
Please select a directory under which to store your data.     
Data Directory [/opt/edb/as10/data]:     #一般不建议使用默认配置,我只是测试环境,直接使用默认值
Please select a directory under which to store your Write-Ahead Logs.     
Write-Ahead Log (WAL) Directory [/opt/edb/as10/data/pg_wal]:   #一般不建议使用默认配置,我只是测试环境,直接使用默认值

选择你需要兼容Oracle还是PostgreSQL,选择Oracle的话,会安装Oracle的一些兼容类型、包、视图、函数等,同时数据类型的显示会兼容Oracle的风格。
如果不需要Oracle的兼容性,建议选择兼容PostgreSQL。更方便的逃离Oracle。

Advanced Server Dialect     
[1] Compatible with Oracle     
[2] Compatible with Postgres     
Please choose an option [1] : 2     # 根据实际需要选择,选择你需要兼容Oracle还是PostgreSQL。
                                    # 选择Oracle的话,会安装Oracle的一些兼容类型、包、视图、函数等,同时数据类型的显示会兼容Oracle的风格。
                                    # 如果不需要Oracle的兼容性,建议选择兼容PostgreSQL。

Please provide a password for the database superuser (postgres). A locked Unix user account (postgres) will be created if not present.
Password : 1q2w3e        # 数据库初始超级用户postgres的密码、不同的edb版本提供的默认超级用户不同,有些版本默认初始化的超级用户是enterprisedb,有些版本默认初始化的超级用户是edb,可以 cat /etc/passwd 查看初始的默认用户是什么
Retype Password : 1q2w3e

Please select the port number the server should listen on.     
Port [5432]:  # 使用默认的监听端口、不同的edb版本的默认端口也不同、有的版本可能是5444,不修改,使用默认端口

...     
[763] zh_CN.utf8     
...          
Please choose an option [1] : 763  # 指定数据库的字符集编码zh_CN.utf8。注意不同的edb版本字符集对应的编号不同,选择zh_CN.utf8对应的编号。

Install sample tables and procedures. [Y/n]: Y  # 是否安装示范表和存储过程,一般可以不安装,我这里选择安装

Please select the type of server to determine the amount of system resources      
that may be utilized:   
[1] Development (e.g. a developer's laptop)     
[2] General Purpose (e.g. a web or application server)     
[3] Dedicated (a server running only Advanced Server)     
Please choose an option [2] : 2    # EDB动态优化,我测试使用,选General

Please select the type of workload this server will be used for:     
[1] Transaction Processing (OLTP systems)     
[2] General Purpose (OLTP and reporting workloads)     
[3] Reporting (Complex queries or OLAP workloads)     
Please choose an option [1] :   # 数据库用于什么业务场景(oltp事务型/htap混合型/olap分析型)。我默认OLTP事务型。

配置好后会显示确认配置信息是否正确:
Pre Installation Summary
The following settings will be used for the installation::
Installation Directory: /opt/edb/as10
Server Installation Directory: /opt/edb/as10
Data Directory: /opt/edb/as10/data
WAL Directory: /opt/edb/as10/data/pg_wal
Database Port: 5432
Database Superuser: postgres
Operating System Account: postgres
Database Service: edb-as-10
Command Line Tools Installation Directory: /opt/edb/as10

确认配置后OK后回车,然后Y继续安装。安装结束后,会自动创建一个系统用户postgres和数据库超级用户postgres,同时新增一个随操作系统自动启动数据库的服务。

如果安装后报下面错误,请检查是否是数据目录、WAL目录权限的问题,可能是提前用root身份创建的、导致postgres无法写。请不要创建,系统会自动创建。
Please wait while Setup installs EDB Postgres Advanced Server on your computer.

Installing EDB Postgres Advanced Server 
 0% ______________ 50% ______________ 100%
 ########################################Warning: Problem running post-install step. Installation may not complete 
correctly
 The database cluster initialisation failed.
Press [Enter] to continue:
#

----------------------------------------------------------------------------
Setup has finished installing EDB Postgres Advanced Server on your computer.

如果安装失败,就尝试卸载重装。
cd /opt/edb/ens10/
./uninstall-edb-as10-server

Please choose an option [1] : 1  #整体卸载
Info: The data directory (/opt/edb/as10/data) and service user account (postgres) have not been removed.
#
Info: Uninstallation completed

删除用户和目录data:
userdel  postgres
rm /opt/edb/ens10/data
然后重新安装。

安装后进行配置

如果是选择的兼容Oracle,则安装完成以后,需要安装Oracle OCI。我选择的兼容PostgreSQL,所以这里不介绍Oracle OCI的安装。

安装后切换到数据库用户,进行安装后的环境配置。用户root身份来配置postgres用户的环境变量。

数据库安装完成后会自动生成环境变量文件:/opt/edb/as10/pgplus_env.sh。可以直接拷贝内容,写到数据库用户的环境变量文件中/opt/edb/as10/.bash_profile。

cat /opt/edb/pgplus_env.sh

export PATH=/opt/edb/as10/bin:$PATH
export PGHOME=/opt/edb/as10
export PGDATA=/opt/edb/as10/data
export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=5432
export PGLOCALEDIR=/opt/edb/as10/share/locale

也可以手动编辑用下面的内容创建环境变量文件(下面变量更全)

vi /opt/edb/as10/.bash_profile

export LANG=zh_CN.utf8
export PGDATA=/opt/edb/as10/data
export PGHOME=/opt/edb/as10?
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH?
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
#不同edb版本出初始化的默认用户不同postgres/edb/enterprisedb,根据实际情况设置
export PGUSER=postgres
export PGDATABASE=postgres
alias rm='rm -i'?
alias ll='ls -lh'?
unalias vi

su - postgres
pwd
/opt/edb/as10 #发现用户被锁定再该目录下

如果要调整优化数据库的配置参数,则可以通过修改postgresql.conf配置文件
su - postgres
cd $PGDATA
vi postgresql.conf
参数调优这里不介绍了

修改数据库防火墙(ACL),开放安全限制、允许外部连接
cd $PGDATA
vi pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only     
local   all             all                                    trust     
# IPv4 local connections:     
host    all             all             127.0.0.1/32            md5     
# IPv6 local connections:     
host    all             all             ::1/128                 md5     
# Allow replication connections from localhost, by a user with the     
# replication privilege.     
local   replication     all                                     md5     
host    replication     all             127.0.0.1/32            md5     
host    replication     all             ::1/128                 md5     
host    all             all             0.0.0.0/0               md5

主要:
local   all             all                                    trust 
host    all             all             0.0.0.0/0               md5

重启数据库
pg_ctl restart -m fast
相关命令:pg_ctl stop | start | restart

也可以使用service脚本方式
systemctl restart edb-as-10.service
systemctl stop edb-as-10.service
systemctl start edb-as-10.service

添加系统启动时自启动数据库

方法1:systemctl  enable edb-as-10.service

方法2:pg_ctl 命令启动

注意:rc.local 运行在操作系统完全引导成功、但尚未启动login shell之前。所以我们配置在 /etc/profiles 或 bashrc 里的环境变量并未得到执行、还未生效,因此,在 rc.local 执行阶段看不到任何环境变量。

解决办法:在 rc.local 中在执行启动命令之前加上 export 环境变量设置。或者启动命令做到避免依赖环境变量。

方法一(执行前添加export):

echo 'export PGDATA=/opt/edb/as10/data && su edb -c "/opt/edb/as10/bin/pg_ctl start"' >> /etc/rc.d/rc.local
chmod u+x /etc/rc.d/rc.local

方法二(-D 指定PGDATA目录,避免依赖环境变量):

echo 'su postgres -c "/opt/edb/as10/bin/pg_ctl start -D /opt/edb/as10/data"' >> /etc/rc.d/rc.local
chmod u+x /etc/rc.d/rc.local

常用命令
基本操作命令和postgresql相同

启动数据库: pg_ctl start
重启数据库: pg_ctl restart -m fast
停止数据库: pg_ctl stop
查看服务状态: pg_ctl  status  或者  ps aux |grep postgres

查看数据库是否正常: psql -Upostgres
postgres=# 
postgres=# help //可查看帮助信息
postgres=# \d  //List of relations
postgres=# \l  //List of databases
postgres=# \q  //quit

远程登录、连接数据库

psql -h host -p port PGDATABASE PGUSER
psql -h host -p port -U PGUSER PGDATABASE

psql -h 127.0.0.1 -p 5432 postgres postgres
psql -h 127.0.0.1 -p 5432 testdb ppas
psql -h 127.0.0.1 -p 5432 -U ppas testdb

创建用户ppas
create role ppas login encrypted password '1q2w3e';

创建数据库testdb
create database testdb with template template1;
#create database testdb02 with template template1 onwer ppas;
grant all on database testdb to ppas;
grant all on database testdb to postgres;

获取当前db的所有表信息
select * from pg_tables;

查看用户的所有表(用户自定义的表,如果未经特殊处理,默认都是放在名为public的schema下)
select tablename from pg_tables where schemaname='public';

创建表:
create table test01( 
id integer not null, 
name character(255),
price decimal(8,2),
primary key(id)
);

插入数据
insert into test01(id,name,price) values (1,'a',11.5),(2,'b',20.3);

查看表结构
\d test01;

查看表的数据
select * from test01;

删除表
drop table test01;

查看Server版本信息:
psql --version;
SHOW server_version;
SELECT version();

Centos7安装EDB/PPAS/EPAS相关推荐

  1. EDB PPAS(Oracle 兼容版) Oracle与PostgreSQL 兼容模式的参数配置切换

    标签 PostgreSQL , EDB , PPAS , 参数 , Oracle模式 , PostgreSQL模式 背景 EDB PPAS是EDB推出的一款同时兼容Oracle和PostgreSQL协 ...

  2. centos7 nginx配置php7,centos7安装并配置nginx+php,centos7nginx

    centos7安装并配置nginx+php,centos7nginx centos7安装并配置nginx+php 安装nginx yum install nginx 设置nginx开启起动 syste ...

  3. centos7安装配置pgAgent

    centos7安装pgagent: 默认cmake已经安装 编译wxGTK https://excellmedia.dl.sourceforge.net/project/wxwindows/2.8.7 ...

  4. centos7 安装mysql php_Centos7安装mysql与php的方法

    本文主要和大家分享Centos7安装mysql与php的方法,希望能帮助到大家. 相关mysql视频教程推荐:<mysql教程> 官网下载安装mysql-server 依次使用下面三个命令 ...

  5. Centos7安装Apache和PHP,包含配置过程

    本文主要讲的是本人在迁移php网站相关软件的安装和配置过程,以及一下问题的解决步骤.通过阅读本文能够知道如何迁移php网站,如何配置httpd服务使得它能够解析php文件以及如何解决迁移过程中的异常问 ...

  6. LINUX CentOS7安装字体库

    LINUX CentOS7安装字体库 2017年12月26日 17:06:07 q260996583 阅读数:4866更多 个人分类: linux JAVA画图时常用到Font 类对象 这样的对象依赖 ...

  7. centos7安装mysql缺失依赖_CentOS7安装mysql5.7不成功,解决依赖包之后还是无法安装成功...

    [root@xg79 ~]# yum -y installmysql-community-server ............. Error: Package:mysql-community-ser ...

  8. linux tomcat7怎么安装,centos7安装Tomcat7,

    centos7安装Tomcat7, 一.环境 centos7 linux apache-tomcat-7.0.92.tar.gz:链接:https://pan.baidu.com/s/1-clhIjD ...

  9. CentOS7安装CDH 第三章:CDH中的问题和解决方法

    CentOS7安装CDH 第三章:CDH中的问题和解决方法 参考文章: (1)CentOS7安装CDH 第三章:CDH中的问题和解决方法 (2)https://www.cnblogs.com/yang ...

最新文章

  1. Swift: 用Alamofire做http请求,用ObjectMapper解析JSON
  2. 数学:统计:基本概念
  3. LeetCode Algorithm 530. 二叉搜索树的最小绝对差
  4. hibernate脏数据_Hibernate脏检查的剖析
  5. 对c++primer 16.6.1的第4小节的代码说明
  6. Mac OS 如何更改文件的默认打开方式
  7. 典型医学设计实验GEO数据分析 (step-by-step) - 数据获取到标准化
  8. Servlet实现文件下载
  9. es6 Iterator 接口与 Generator 函数
  10. 微信小程序模板消息群发解决思路
  11. 线性筛法 欧拉筛c语言,[洛谷P3383][模板]线性筛素数-欧拉筛法
  12. AI头发笔刷_5G大量PS笔刷AI笔刷打包下载(超过1000款笔刷)
  13. 通过ARP查询目标路由器的MAC地址
  14. 计算机图形学的网络课程
  15. 一文读懂华为、小米、OV成为国产四强背后的秘诀?
  16. 学习java的第十九天,static关键字、隐匿代码块的学习
  17. fluent p1模型_FLUENT中的辐射模型
  18. Win10蓝牙开关消失解决方法
  19. 出现Artifact xxx:war exploded: Error during artifact deployment. See server log for details.的问题(已经解决)
  20. 5 个可以加速开发的 VueUse 函数库

热门文章

  1. 数据校验码(计算机组成原理)
  2. 水利水电之水资源管理第一章测试题
  3. java实现蓝牙通信程序_Android蓝牙通信聊天实现发送和接受功能
  4. PyQt5 控件学习(一个一个学习之QObject)
  5. MySQL的InnoDB引擎是如何解决幻读的?
  6. 契约测试概念以及契约测试框架SCC VS PACT对比
  7. minicom配置1500000波特率
  8. Geany编辑器win7环境下配置Python编程环境
  9. EtherCAT通信DS402协议----PDO映射
  10. 大学入学计算机理论知识试卷及答案,2017年大学计算机基础知识试题及答案