Visitar URL original
query temp table is routed to standby node. · Issue #154 · pgpool/pgpool2 · GitHub
Skip to content

query temp table is routed to standby node. #154

Description

@liujinyang-highgo

Hi,
I met an issue as below:

  • environment

    pgpool 4.6.2 with three backend nodes, one primary and two standby(weight: 0:1:1).

  • reproduce steps

    1. start pgpool
    2. create table t1(id1 int,id2 int);
    3. select * from t1; //this query will be routed to standby node
    4. drop table t1;
    5. create temp table t1(id1 int,id2 int);
    6. select * from t1; //this query will be routed to standby node and execute failed.
  • analyze

    1. in step 3. this query is routed to standby, that's OK. During the process, pgpool will check if 't1' is an temp table, since this is the first time do this query, there is no result in local cache and shared cache, so pgpool will first do query from backend and save the result to shared cached and local cache, 't1' is marked as a non-temporary table.
    2. when drop t1 and re-create t1 as a temp table, pgpool will call discard_temp_table_relcache() to clear local cache, but not clear shared cache.
    3. in step 6, do query "select * from t1;" , pgpgool will check if 't1' is temp table, can not get result from local cache, but can get the result from shared cache, result is 't1' is not an temp table , so routed to standby and execute failed.
  • concern
    so do we have any mechanism to avoid this? I know we can set expire time, but it won't take effect in a timely manner.
    in addition, unlog table,function maybe have same issue.

thanks~

Activity

  1. changed the title [-]query temp table is routed primary node.[/-] [+]query temp table is routed to standby node.[/+] on Mar 12, 2026
  2. self-assigned this
    on Mar 15, 2026
  3. pengbo0328 commented on Mar 15, 2026

    @pengbo0328
    Collaborator

    Your analysis is correct.

    With the current behavior, the cache is not invalidated even if the system catalog changes. As a workaround, you can either disable enable_shared_relcache or configure relcache_expire.

    We will discuss within the development team whether this behavior can be improved.

  4. tatsuo-ishii commented on Mar 15, 2026

    @tatsuo-ishii
    Collaborator

    Or you can set check_temp_table = trace to avoid the issue.

    in addition, unlog table,function maybe have same issue.

    That's a known limitation of the system catalog lookup cache system.

  5. liujinyang-highgo commented on Mar 17, 2026

    @liujinyang-highgo
    Author

    thanks for your reply.
    set check_temp_table = trace or disable enable_shared_relcache is only available to temp table, but not available to unlog table.
    configure relcache_expire is only effective to a certain extent.

    if you can improve that in future, that's great!

  6. tatsuo-ishii commented on Mar 20, 2026

    @tatsuo-ishii
    Collaborator

    For temp table case, I found a bug. In your scenario iii, a shared relation cache for t1 (t1 is not a temp table") is created. And the query in vi refers to the shared relation cache and believes that t1 is not a temp table. I posted a patch to pgpool-hackes.
    https://www.postgresql.org/message-id/20260320.115354.1808938375091443061.ishii%40postgresql.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions