↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

42P03 — 重复游标

游标或 portal 名称与已有的冲突。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Syntax Error or Access Rule Violation
condition name
duplicate_cursor
lang
en
sqlstate
42P03

版本定义 PG 18

42P03 — 重复游标

速览 {#at-a-glance}

42P03(duplicate_cursor)报告游标或 portal 名称冲突,但同一 SQLSTATE 覆盖 ERROR、替换时的 WARNING,以及 PL/pgSQL 活动游标的 ERROR。调用方和 CreatePortal 选项决定具体行为。

含义 {#meaning}

CreatePortal(name, allowDup, dupSilent) 在 allowDup 为 false 时报告 ERROR cursor "%s" already exists。allowDup 为 true 时,若 dupSilent 未设置,会先发 WARNING closing existing cursor "%s",随后删除旧 portal 并创建新 portal。PL/pgSQL 是另一条路径:SPI_cursor_find 发现同名活动游标时报告 ERROR cursor "%s" already in use。

诊断 {#diagnosis}

记录准确名称、来源(SQL portal 创建还是 PL/pgSQL OPEN)、严重性和事务状态。SQL 路径检查 portal 创建/复用及适用时的 pg_cursors;PL/pgSQL 路径检查游标变量和 OPEN/CLOSE 流程。allowDup 的替换分支不能推出所有重复声明都会 WARNING,PL/pgSQL 分支也不是 portal 管理器的替换路径。

处理 {#response}

非替换 portal 路径报 ERROR 时,关闭旧 portal 或使用符合事务生命周期的新名称。WARNING 替换路径已经关闭旧 portal,应用仍应确认替换是预期行为。PL/pgSQL 应在重新打开前关闭命名游标,或使用不同变量/名称。只有 ERROR 路径需要通过回滚保存点或回滚事务恢复显式事务;重连不能替代查清连接池所有权。

消息变体 {#messages}

18.6 代表报文如下:

| 路径 | 严重性 | 主消息 | | --- | --- | --- | | CreatePortal(..., allowDup=false, ...) | ERROR | cursor "%s" already exists | | CreatePortal(..., allowDup=true, dupSilent=false) | WARNING | closing existing cursor "%s" | | 已找到 PL/pgSQL 命名游标 | ERROR | cursor "%s" already in use |

%s 为动态游标名称,本页不声称具体名称。

版本 {#versions}

目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是 18.6 固定 portal 管理器和 PL/pgSQL 源码路径,未运行数据库。

相关 {#related}

来源 {#sources}

  • src.errcodes.42P03.18.6 — src/backend/utils/errcodes.txt line 378,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。

  • src.call.42P03.800a8278cf453417f5af6d6e — src/backend/utils/mmgr/portalmem.c lines 185-187,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 8e29a302a7837316765acc798f9ff6eb22a330e8098a02794cd4d683601d3b04(源码)。

  • src.call.42P03.208bdd3b576b5021fb35916d — src/backend/utils/mmgr/portalmem.c lines 189-192,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 8e29a302a7837316765acc798f9ff6eb22a330e8098a02794cd4d683601d3b04(源码)。

  • src.call.42P03.06c0580b43488eece2de1973 — src/pl/plpgsql/src/pl_exec.c lines 2895-2897,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 0df3c70a6bccf6dddf443fb99e152a16a67009827c44a820597e98e585cb8b20(源码)。

  • src.calls.REL_18_6.42P03 — 固定本地核心调用扫描;SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。

  • 作者证据 — 记录源码断言、消息角色和运行边界。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity.class-and-condition
{
  "claim_id": "identity.class-and-condition",
  "limits": "Identity does not enumerate all source branches or client failures.",
  "method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.42P03.18.6"
  ],
  "statement": "42P03 is the duplicate_cursor condition in Class 42."
}
claims · mechanism.selected-source-path
{
  "claim_id": "mechanism.selected-source-path",
  "limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
  "method": "Read complete resolved REL_18_6 report groups and message roles.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.call.42P03.800a8278cf453417f5af6d6e",
    "src.call.42P03.208bdd3b576b5021fb35916d",
    "src.call.42P03.06c0580b43488eece2de1973"
  ],
  "statement": "CreatePortal(name, allowDup, dupSilent) reports ERROR `cursor \"%s\" already exists` when allowDup is false, can report WARNING `closing existing cursor \"%s\"` before dropping a duplicate when allowDup is true and dupSilent is false, and PL/pgSQL separately reports ERROR `cursor \"%s\" already in use` when SPI_cursor_find finds an active named cursor."
}
claims · versions.catalogue-boundary
{
  "claim_id": "versions.catalogue-boundary",
  "limits": "First observed release is a lower bound, not precise behavioral introduction.",
  "method": "Read locked catalogue facts and definition snapshots.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.42P03.18.6"
  ],
  "statement": "From 7.4 through 18.6 and 19beta3; the selected portal-manager and PL/pgSQL branches are fixed 18.6 source paths and runtime was not run."
}
messages · message.variant-1
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-1",
  "path": "",
  "position": 0,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "cursor \"%s\" already exists",
    "roles": [
      {
        "role": "errmsg",
        "template": "cursor \"%s\" already exists"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P03.800a8278cf453417f5af6d6e"
    ],
    "sqlstate": "42P03"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P03.800a8278cf453417f5af6d6e"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cursor \" \" already exists",
      "position": 0,
      "role": "",
      "template": "cursor \"%s\" already exists"
    }
  ]
}
messages · message.variant-2
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-2",
  "path": "",
  "position": 1,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "closing existing cursor \"%s\"",
    "roles": [
      {
        "role": "errmsg",
        "template": "closing existing cursor \"%s\""
      }
    ],
    "severity_source": "explicit WARNING",
    "sources": [
      "src.call.42P03.208bdd3b576b5021fb35916d"
    ],
    "sqlstate": "42P03"
  },
  "severity": "explicit WARNING",
  "sources": [
    "src.call.42P03.208bdd3b576b5021fb35916d"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "closing existing cursor \" \"",
      "position": 0,
      "role": "",
      "template": "closing existing cursor \"%s\""
    }
  ]
}
messages · message.variant-3
{
  "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
  "message_id": "message.variant-3",
  "path": "",
  "position": 2,
  "raw": {
    "detail_templates": [],
    "hint_templates": [],
    "id": "message.variant-3",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "cursor \"%s\" already in use",
    "roles": [
      {
        "role": "errmsg",
        "template": "cursor \"%s\" already in use"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P03.06c0580b43488eece2de1973"
    ],
    "sqlstate": "42P03"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P03.06c0580b43488eece2de1973"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cursor \" \" already in use",
      "position": 0,
      "role": "",
      "template": "cursor \"%s\" already in use"
    }
  ]
}
sources · src.errcodes.42P03.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 378",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P03.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L378"
}
sources · src.call.42P03.800a8278cf453417f5af6d6e
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 185-187",
  "path": "src/backend/utils/mmgr/portalmem.c",
  "position": 1,
  "sha256": "8e29a302a7837316765acc798f9ff6eb22a330e8098a02794cd4d683601d3b04",
  "source_id": "src.call.42P03.800a8278cf453417f5af6d6e",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/mmgr/portalmem.c#L185-L187"
}
sources · src.call.42P03.208bdd3b576b5021fb35916d
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 189-192",
  "path": "src/backend/utils/mmgr/portalmem.c",
  "position": 2,
  "sha256": "8e29a302a7837316765acc798f9ff6eb22a330e8098a02794cd4d683601d3b04",
  "source_id": "src.call.42P03.208bdd3b576b5021fb35916d",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/mmgr/portalmem.c#L189-L192"
}
sources · src.call.42P03.06c0580b43488eece2de1973
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 2895-2897",
  "path": "src/pl/plpgsql/src/pl_exec.c",
  "position": 3,
  "sha256": "0df3c70a6bccf6dddf443fb99e152a16a67009827c44a820597e98e585cb8b20",
  "source_id": "src.call.42P03.06c0580b43488eece2de1973",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_exec.c#L2895-L2897"
}
sources · src.calls.REL_18_6.42P03
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 4,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P03",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:d27355120217f732026b1e5ecc24092c4ae150ad963e5e9c2bd50b97943bd1f3

正文语言: zh-Hans · english-manuals:d27355120217f732026b1e5ecc24092c4ae150ad963e5e9c2bd50b97943bd1f3