最近有客户反应liquibase通过pgoneproxy来管理数据库版本时,发现不能建立数据库表。这让我有点难理解,于是我直接下载了一个liquibase来测试,发现是pgoneproxy的权限管理的问题。现在说说测试的过程。
先从http://www.liquibase.org/网站下载对应的liquibase,加压后,在目录下有如下文件:
liquibase.jar
README.txt
liquibase.spec
liquibase.bat
liquibase
LICENSE.txt
sdk
lib
为了创建数据库表,先增加创建表的配置文件,配置文件的内容如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="3" author="db_user">
<createTable tableName="bigaaa">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="firstname" type="varchar(50)"/>
<column name="lastname" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="state" type="char(2)"/>
</createTable>
</changeSet>
</databaseChangeLog>
上面配置文件中,要求创建bigaaa表。在使用下面的命令来运行:
./liquibase --driver=org.postgresql.Driver --changeLogFile=db.changelog.xml --url=jdbc:postgresql://172.30.12.10:2000/pgbench --username=db_user --password=1234 --logLevel=debug --logFile=log.txt update
测试发现报错了:
Unexpected error running Liquibase: ERROR: Access denied due to security policy, DDL disabled or DML restricted! [Failed SQL: CREATE TABLE public.databasechangeloglock (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP WITHOUT TIME ZONE, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
看见错误后,知道是pgoneproxy的安全策略,导致创建表失败的。
在pgoneproxy中有--proxy-group-security=<servergroup:level>,--proxy-security-level=<level> --proxy-table-security=<table:level> 。其中后面两个安全策略都是默认情况下是没有设置的。而proxy_group_security默认情况下是设置为1的。不支持DDL。故需要在配置文件中增加--proxy-group-security=data0:0的配置。其中data0为组名称。