代码拉取完成,页面将自动刷新
根据官方文档描述,可以使用transaction_read_only参数控制事务的读写状态。但实际测试时发现该参数并不生效。实验结果如下:
[omm@db1 ~]$ gs_guc reload -N all -I all -c "transaction_read_only=on"
Begin to perform gs_guc for all datanodes.
Total instances: 2. Failed instances: 0.
Success to perform gs_guc!
[omm@db1 db1]$ gsql -d postgres -p 26000
gsql ((openGauss 1.0.0 build 0bd0ce80) compiled at 2020-06-30 18:19:27 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=# select name,setting,boot_val,reset_val from pg_settings where name='transaction_read_only';
name | setting | boot_val | reset_val
-----------------------+---------+----------+-----------
transaction_read_only | off | off | off
postgres=# create table t3(id int,name varchar(20));
CREATE TABLE
以上示例发现,虽然使用guc设置transaction_read_only=on,但实际并没有生效,依然可以对数据库做DML/DDL操作。
为什么会不生效?
在实际transaction相关参数查看时发现了default_transaction_read_only参数,该参数默认设置为off状态。
postgres=# select name,setting,boot_val,reset_val from pg_settings where name like '%transaction_read_only';
name | setting | boot_val | reset_val
-------------------------------+---------+----------+-----------
default_transaction_read_only | off | off | off
transaction_read_only | off | off | off
当把default_transaction_read_only参数设置为on时,测试结果如下:
[omm@db1 ~]$ gs_guc reload -N all -I all -c "default_transaction_read_only=on"
Begin to perform gs_guc for all datanodes.
Total instances: 2. Failed instances: 0.
Success to perform gs_guc!
postgres=# select name,setting,boot_val,reset_val from pg_settings where name like '%transaction_read_only';
name | setting | boot_val | reset_val
-------------------------------+---------+----------+-----------
default_transaction_read_only | on | off | on
transaction_read_only | on | off | off
(2 rows)
当对default_transaction_read_only 参数做修改后,transaction_read_only参数也随之修改,事务状态也成功变更为read only模式,DML/DDL拒绝执行,示例如下:
postgres=# insert into t1 values(222);
ERROR: cannot execute INSERT in a read-only transaction
由此可以发现,直接决定事务读写状态的应该是default_transaction_read_only参数,至于default_transaction_read_only 和 transaction_read_only参数的区别和关系,目前官方文档还没有指出,期待进一步完善。
Hey @贾军锋, Welcome to openGauss Community.
All of the projects in openGauss Community are maintained by @opengauss-bot.
That means the developers can comment below every pull request or issue to trigger Bot Commands.
Please follow instructions at https://gitee.com/opengauss/community/blob/master/contributors/command.en.md to find the details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
/kind bug
Hey @贾军锋 please feel free to fix it.
Thanks very much.
目前单机、单机主备模式下,该参数在数据库恢复过程中或者在备机里,固定为true;否则,固定为default_transaction_read_only的值。
登录 后才可以发表评论