天天看点

EnterpriseDB(阿里云PPAS)自建与使用

概述

EnterpriseDB是全球唯一一家提供基于PostgreSQL企业级产品与服务的厂商

EnterpriseDB是PostgreSQL的一个分支,在PostgreSQL基础上,针对企业级应用进行了专门的优化,同时,增加了一系列如动态 性能调优(DynaTune)、EDB Loader、高效批量SQL处理等高级特性;在众多功能亮点中,EnterpriseDB的兼容性技术尤为惹眼,可以兼容oracle的数据库,目前,IBM 的DB2的数据库直接用EnterpriseDB的兼容包。

云数据库PPAS版,基于PostgreSQL,高度兼容Oracle语法,由阿里云与EnterpriseDB公司合作提供

也就是常说的EDB,EDB其实就是商业版PostgreSQL,主要因为他是和Oracle最接近的数据库,这里主要是指语句的语法,或者说开发层面,对于原来使用Oracle的产品和服务,改造起来成本可能略小

目前PPAS支持的版本是9.3 与10

下载

EDB官网 www.enterprisedb.com

下载需要申请账号密码

这里我们选择的是10.5,可以安装在Linux 64位系统上。

安装

将安装包上传

将安装包上传到已经准备好的系统上,并赋予执行权限

[root@stephen opt]# chmod +x edb-as10-server-10.5.12-1-linux-x64.run           

执行run安装文件

[root@stephen opt]# ./edb-as10-server-10.5.12-1-linux-x64.run 
----------------------------------------------------------------------------
Welcome to the EDB Postgres Advanced Server Setup Wizard.

----------------------------------------------------------------------------
Please read the following License Agreement. You must accept the terms of this 
agreement before continuing with the installation.

Press [Enter] to continue:
Limited Use Software License Agreement
Version 2.9

............................................(忽略这些声明)

Press [Enter] to continue:

Do you accept this license? [y/n]: y

----------------------------------------------------------------------------
Please specify the directory where EDB Postgres Advanced Server will be 
installed.

Installation Directory [/opt/edb/as10]: /opt/edb/as10   
# 选择要安装到的路径,全路径,如例

----------------------------------------------------------------------------
Select the components you want to install; clear the components you do not want
to install. Click Next when you are ready to continue.
# 手动选择一些需要安装的东西,这里我随便选了几样,可以根据需要选择安装

EDB Postgres Advanced Server [Y/n] :y

pgAdmin 4 [Y/n] :y

StackBuilder Plus [Y/n] :n

Command Line Tools [Y/n] :y

Is the selection above correct? [Y/n]: y

----------------------------------------------------------------------------
Additional Directories

Please select a directory under which to store your data.

Data Directory [/opt/edb/as10/data]: /sas_pgdata

Please select a directory under which to store your Write-Ahead Logs.

Write-Ahead Log (WAL) Directory [/opt/edb/as10/data/pg_wal]: /opt/edb/as10/data/pg_wal
# 这里是选择wal放的地方,理论上来说最好是将这个放在pgdata的位置,也就是数据目录里,我安装的时候没太注意,不过影响也不大,各位在安装的时候推荐放在数据目录下
----------------------------------------------------------------------------
Advanced Server Dialect

EDB Postgres Advanced Server can be configured in one of two "Dialects" - 1) Compatible with Oracle or 2) Compatible with Postgres.

If you select Compatible with Oracle, Advanced Server will be configured with appropriate data type conversions, time and date formats, Oracle-styled operators, dictionary views and more. This makes it easier to migrate or write new applications that are more compatible with the Oracle database.

If you select Compatible with Postgres, Advanced Server will be configured with standard PostgeSQL data types, time/date formats and operators.

Advanced Server Dialect

[1] Compatible with Oracle
[2] Compatible with Postgres
Please choose an option [1] : 2

#这里是选择高级服务器可以配置两种方言(Dialects),我更熟悉PG一点,所以选择2

----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix 
user account (postgres) will be created if not present.

#给postgres超级用户一个密码

Password :
Retype Password :
----------------------------------------------------------------------------
 Additional Configuration

Please select the port number the server should listen on.

Port [5432]: 5444

# 因为安装的系统还有一个postgres数据库,选择换一个端口进行安装

Select the locale to be used by the new database cluster.

Locale


Please choose an option [1] : 

Would you like to install sample tables and procedures?

Install sample tables and procedures. [Y/n]: y


----------------------------------------------------------------------------
Dynatune Dynamic Tuning:
Server Utilization

Please select the type of server to determine the amount of system resources 
that may be utilized:

#请选择服务器类型以确定系统资源的数量
#[1]开发(例如开发人员的笔记本电脑)
#[2]通用(例如web或应用服务器)
#[3]专用的(只运行高级服务器的服务器)
#这里我们只是安装测试,所以就选择1


[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] : 1

----------------------------------------------------------------------------
Dynatune Dynamic Tuning:
Workload Profile

Please select the type of workload this server will be used for:

#选择工作概要
#[1]事务处理(OLTP系统)
#[2]通用(OLTP和报告工作负载)
#[3]报告(复杂查询或OLAP工作负载)
#选择安装数据库用来做工作的类型,我这里这里选择2

[1] Transaction Processing (OLTP systems)
[2] General Purpose (OLTP and reporting workloads)
[3] Reporting (Complex queries or OLAP workloads)
Please choose an option [1] : 2

----------------------------------------------------------------------------
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: /sas_pgdata
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
pgAdmin4 Installation Directory: /opt/edb/as10/pgAdmin4

Press [Enter] to continue:

#确认安装信息

----------------------------------------------------------------------------
Setup is now ready to begin installing EDB Postgres Advanced Server on your 
computer.

Do you want to continue? [Y/n]: y

----------------------------------------------------------------------------
Please wait while Setup installs EDB Postgres Advanced Server on your computer.

 Installing EDB Postgres Advanced Server 
 0% ______________ 50% ______________ 100%
 #########################################

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

#安装完毕
           

ppas的安装步骤

有幸得到分享一个阿里云ppas的自建安装包,安装步骤与edb类似,如下

您是否接受此软件授权协议? [y/n]: y

----------------------------------------------------------------------------
安装 需要在 EnterpriseDB.com 上注册。 请在下方输入您的凭据。 如果您没有帐户,请在 
https://www.enterprisedb.com/user-login-registration 上创建帐户

电子邮件 []: [email protected]

密码 :
----------------------------------------------------------------------------
请指定将要安装 Postgres Plus Advanced Server 的目录。

安装目录 [/opt/PostgresPlus]:          
----------------------------------------------------------------------------
Select the components you want to install.

Database Server [Y/n] :y

Connectors [Y/n] :y

Infinite Cache [Y/n] :y

Migration Toolkit [Y/n] :y

Postgres Enterprise Manager Client [Y/n] :y

pgpool-II [Y/n] :n

pgpool-II Extensions [Y/n] :n

EDB*Plus [Y/n] :y

Slony Replication [Y/n] :y

PgBouncer [Y/n] :y

上述选择是否正确? [Y/n]: y

----------------------------------------------------------------------------
其它目录

请选择一个用于存储数据的目录.

目录 [/opt/PostgresPlus/9.5AS/data]: 

请选择用于存储预写日志的目录。

预写日志(WAL)目录 [/opt/PostgresPlus/9.5AS/data/pg_xlog]: 

----------------------------------------------------------------------------
配置模式

Postgres Plus Advanced Server 始终附带安装适用于 Oracle(R) 的数据库兼容性功能并完全遵守 PostgreSQL 合规性。选择安装默认设置和示例的样式首选项。

Oracle 配置将导致使用特定对象(例如,DATE 数据类型、字符串操作等)生成与 Oracle 兼容的结果、创建相同的 Oracle 示例表格,并使该数据库与文档中所用的 Oracle 示例匹配。

配置模式

[1] Compatible with Oracle
[2] Compatible with PostgreSQL
请选择选项 [1] : 2

----------------------------------------------------------------------------
请提供数据库超级用户(postgres)的口令.如果没有提供口令,那么将创建一个已锁定的Unix用户帐户(postgres).

口令 :
重新输入口令 :
----------------------------------------------------------------------------
其它配置

请选择用于服务器监听的端口号.

端口 [5433]: 

请选择新数据库集群时所使用的语言环境.

安装示例表和存储过程. [Y/n]: y


----------------------------------------------------------------------------
Dynatune 动态性能调整:
服务器使用情况

请选择服务器的类型来确定会利用到的系统资源总合:


[1] 开发模式(例如, 一台开发人员的笔记本)
[2] 通用用途(例如. WEB或应用服务器)
[3] 专有模式(服务器只运行Postgres Plus)
请选择选项 [2] : 2

----------------------------------------------------------------------------
Dynatune Dynamic Tuning:
工作负载概要

请选择这台服务器将要使用到的工作负载类型:

[1] 在线事务处理(OLTP系统)
[2] 通用用途(数据库将用于事务处理和报表类型应用)
[3] 报表(运行复杂查询或OLAP类型的工作负载)
请选择选项 [1] : 1

----------------------------------------------------------------------------
高级选项配置
----------------------------------------------------------------------------
PgBouncer 侦听端口 [6432]: 
----------------------------------------------------------------------------
服务配置

自启动PgBouncer服务 [Y/n]: n

自启动pgAgent服务 [Y/n]: y

更新通知服务 [Y/n]: y

更新通知服务用于通知,下载和安装您所使用的Postgres Plus Advanced Server的安全补丁以及其它更新程序。
----------------------------------------------------------------------------
安装前概述

下面的设置将被用于安装:

安装目录: /opt/PostgresPlus
数据目录: /opt/PostgresPlus/9.5AS/data
WAL目录: /opt/PostgresPlus/9.5AS/data/pg_xlog
数据库端口: 5433
数据库的超级用户: postgres
操作系统帐户: postgres
数据库服务: ppas-9.5
PgBouncer所使用的监听端口: 6432

按 [Enter] 继续:
----------------------------------------------------------------------------
安装程序已经准备好将 Postgres Plus Advanced Server 安装到您的电脑。

您确定要继续吗? [Y/n]: y

----------------------------------------------------------------------------
正在安装 Postgres Plus Advanced Server 至您的电脑中,请稍候。

 正在安装Postgres Plus Advanced Server
 0% ______________ 50% ______________ 100%
 ########################################
 正在安装Database Server ...
 正在安装pgAgent ...
 正在安装Connectors ...
 正在安装Migration Toolkit ...
 正在安装EDB*Plus ...
 正在安装Infinite Cache ...
 正在安装Postgres Enterprise Manager Client ...
 正在安装Slony Replication ...
 正在安装PgBouncer ...
 正在安装StackBuilder Plus ...
 #

----------------------------------------------------------------------------
安装程序已经将 Postgres Plus Advanced Server 安装于您的电脑中。
           

启动edb数据库

启动数据库

[edb@stephen ~]$ pg_ctl start
waiting for server to start....2018-12-03 11:01:01 CST LOG: listening on IPv4 address "0.0.0.0", port 5444
2018-12-03 11:01:01 CST LOG: listening on IPv6 address "::", port 5444
2018-12-03 11:01:01 CST LOG: listening on Unix socket "/tmp/.s.PGSQL.5444"
2018-12-03 11:01:01 CST LOG: redirecting log output to logging collector process
2018-12-03 11:01:01 CST HINT: Future log output will appear in directory "log".
 done
server started           

其余步骤与edb相同

配置环境

新建用户edb

为了方便使用和管理,我们新建edb用户来使用edb。

useradd -U edb           

然后将安装好的安装目录和数据目录赋予用户权限

chown -R edb:edb /opt/edb/
chown -R edb:edb /sas_pgdata           

配置环境变量

将新建的环境变量加到.bash_profile中

export PATH=/opt/edb/as10/bin:$PATH
export LD_LIBRARY_PATH=/opt/edb/as10/lib:$LD_LIBRARY_PATH
export PGDATA=/sas_pgdata
export PGHOST=/tmp           

查看数据库是否正常

[edb@stephen ~]$ psql -Upostgres
Password for user postgres: 
psql.bin (10.5.12)
Type "help" for help.

postgres=# 
postgres=# \d
             List of relations
 Schema | Name | Type | Owner   
--------+------------+----------+----------
 public | dept | table | postgres
 public | emp | table | postgres
 public | jobhist | table | postgres
 public | next_empno | sequence | postgres
 public | salesemp | view | postgres
(5 rows)

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

postgres=# \q
           

查看数据库后台进程是否正常

[edb@stephen ~]$ ps -ef|grep edb
postgres 3668 1 0 10:45 ? 00:00:00 /opt/edb/as10/bin/edb-postgres -D /sas_pgdata
root 4007 2079 0 10:57 pts/1 00:00:00 su - edb
edb 4008 4007 0 10:57 pts/1 00:00:00 -bash
edb 4112 1 0 11:01 pts/1 00:00:00 /opt/edb/as10/bin/edb-postgres
edb 4113 4112 0 11:01 ? 00:00:00 postgres: logger process   
edb 4129 4112 0 11:01 ? 00:00:00 postgres: checkpointer process  
edb 4130 4112 0 11:01 ? 00:00:00 postgres: writer process   
edb 4131 4112 0 11:01 ? 00:00:00 postgres: wal writer process  
edb 4132 4112 0 11:01 ? 00:00:00 postgres: autovacuum launcher process  
edb 4133 4112 0 11:01 ? 00:00:00 postgres: stats collector process  
edb 4134 4112 0 11:01 ? 00:00:00 postgres: bgworker: dbms_aq launcher  
edb 4135 4112 0 11:01 ? 00:00:00 postgres: bgworker: logical replication launcher  
edb 4165 4008 0 11:02 pts/1 00:00:00 ps -ef
edb 4166 4008 0 11:02 pts/1 00:00:00 grep --color=auto edb