文档 / SQL 状态码 / Class 53 资源不足
53200 out_of_memory
ERROR 源码确认 详解 未实测
- 条件名
out_of_memory- 宏名称
ERRCODE_OUT_OF_MEMORY- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
53200 是 PostgreSQL 的内存不足条件。固定调用者包括普通 memory context 分配、共享内存和锁表容量、扩展/统计文件读取以及 WAL 读取处理器;应诊断具体操作和分配上下文,不能把所有内存失败归为一个原因。
含义
固定源码有几类不同边界:MemoryContextAllocationFailure 报告带请求大小和 memory context 名称的 out of memory;ShmemAlloc 和锁表建立路径报告 out of shared memory,后者可能提示 max_locks_per_transaction。扩展路径把操作写入 detail:pg_stat_statements 以 out of memory 记录文件读取分配失败,WAL reader 也以相同 primary 搭配分配 detail。pg_stat_statements 这一分支的 severity 是 LOG,并从加载器返回,因此不等同于使客户端当前事务中止的 ERROR;核心和 WAL reader 的 ERROR 分支才需要正常事务恢复。两阶段事务源码路径实际是 WAL reader 分配路径,不能据此说达到 max_prepared_transactions 本身就发出 53200。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
out of memory
Could not allocate enough memory to read file "%s".
来源:contrib/pg_stat_statements/pg_stat_statements.c @ REL_18_6
out of memory
Failed while allocating a WAL reading processor.
out of memory
Failed while allocating a WAL reading processor.
out of memory
Failed while creating memory context "%s".
out of memory
Failed on request of size %zu in memory context "%s".
out of shared memory (%zu bytes requested)
out of shared memory
You might need to increase "max_locks_per_transaction".
诊断
保留 severity、primary、detail、hint、操作、backend 和服务器日志,判断是在 backend memory context、共享内存/锁表、文件/统计结构还是 WAL reader 分配。若 primary 为 out of shared memory 且 hint 指向 max_locks_per_transaction,检查持锁事务与锁表配置;提高它会在启动时消耗共享内存。不要只凭 SQLSTATE 推断主机内存。
处理
确认平台限制和影响后,再降低或重塑操作、释放应用压力或调整消息指向的容量。先结束或回滚持有过多锁的事务,再考虑调整 max_locks_per_transaction;该 hint 不等于操作系统 OOM。文件/WAL/统计操作失败后先验证对象。核心/WAL reader 的 ERROR 会使显式事务失败,重试前执行 ROLLBACK 或 ROLLBACK TO SAVEPOINT;自动提交只有在分配原因修复后才能重试。pg_stat_statements 的 LOG 分支属于后台加载器,本身不要求客户端恢复事务。本页不在真实主机制造 OOM。
版本
锁定目录从 7.4 记录;引用扩展和核心路径来自 PostgreSQL 18.6,未执行 OOM 运行。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 409 行
- 上游源码 contrib/pg_stat_statements/pg_stat_statements.c 第 2346 行
- 上游源码 contrib/pg_walinspect/pg_walinspect.c 第 121 行
- 上游源码 src/backend/access/transam/twophase.c 第 1417 行
- 上游源码 src/backend/utils/mmgr/aset.c 第 444 行
- 上游源码 src/backend/utils/mmgr/mcxt.c 第 1157 行
- 上游源码 src/backend/storage/ipc/shmem.c 第 151 行
- 上游源码 src/backend/storage/lmgr/lock.c 第 2957 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
53200 is out_of_memory in SQLSTATE Class 53.
-
The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described.
-
Core memory-context allocation uses 53200 for allocator failure, shared-memory allocation uses an out-of-shared-memory primary, and lock-table exhaustion can add a max_locks_per_transaction hint; these contexts are distinct from extension file/WAL allocation details.
-
The source report groups keep out of memory as the primary and the operation-specific allocation text as DETAIL; the pg_stat_statements group is LOG while the WAL reader groups are ERROR.
-
The locked catalogue records 53200 from 7.4; that boundary does not prove exact implementation introduction.
同类 SQL 状态码
| 状态码 | 条件名 | 宏名称 | 严重等级 | 版本 |
|---|---|---|---|---|
| 53000 | insufficient_resources | ERRCODE_INSUFFICIENT_RESOURCES |
ERROR | 7.4 |
| 服务器资源不足的宽泛条件,需看消息定位资源。 | 活跃 | |||
| 53100 | disk_full | ERRCODE_DISK_FULL |
ERROR | 7.4 |
| 写文件时发生短写,通常是磁盘空间耗尽。 | 活跃 | |||
| 53200 | out_of_memory | ERRCODE_OUT_OF_MEMORY |
ERROR | 7.4 |
| 内存分配失败,涵盖会话内存与共享内存不足。 | 活跃 | |||
| 53300 | too_many_connections | ERRCODE_TOO_MANY_CONNECTIONS |
ERROR | 7.4 |
| 连接数达到角色、库或服务器上限,新连接被拒。 | 活跃 | |||
| 53400 | configuration_limit_exceeded | ERRCODE_CONFIGURATION_LIMIT_EXCEEDED |
ERROR | 9.2 |
| 配置上限或进程槽位耗尽,如后台 worker 槽位。 | 活跃 | |||