【问题标题】:CodeIgniter with PostgreSQL and PgBouncer in Transaction mode事务模式下的 CodeIgniter 与 PostgreSQL 和 PgBouncer
【发布时间】:2021-02-04 19:41:16
【问题描述】:

之前我们在会话模式下使用带有 PgBouncer 的 PostgreSQL 9,因此能够轻松创建新记录并获取最后一个 ID 为 db->insert_id('table', 'pk_column')

但是使用 PgBouncer 的 Session 模式对我们来说是非常有问题的,每秒有几次操作,Pool 很容易达到连接的容量,所以我们切换到 PostgreSQL 12 和事务模式的 PgBouncer。

这种模式已经开始出现的一个问题是使用需要在同一个会话中的操作不起作用,不允许使用CURRVAL,这是insert_id()使用的,

CodeIgniter 3 创建的 INSERT 示例:

INSERT INTO "table" ("column") VALUES ('ABC');
SELECT pg_get_serial_sequence('table', 'tableid') AS seq;
SELECT CURRVAL('public.table_tableid_seq') AS ins_id;

这段代码会触发错误:

currval has not yet been defined this session

是否必须在 CodeIgniter 中进行任何配置才能在事务模式下使用 PgBouncer?

【问题讨论】:

    标签: php postgresql codeigniter codeigniter-3


    【解决方案1】:

    确保所有这些语句在单个数据库事务中运行,那么应该没有问题。

    【讨论】:

    • 从我在 CodeIgniter documentation 中读到的内容来看,应该是这样的,对吗? $this->db->trans_start(); $this->db->insert(); $this->db->insert_id(); $this->db->trans_complete();
    猜你喜欢
    • 2021-02-27
    • 2014-05-25
    • 2021-03-13
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 2013-05-05
    • 2017-03-03
    • 2010-11-09
    相关资源
    最近更新 更多