Docker上的Postgres - 超出堆栈深度限制
Posted
技术标签:
【中文标题】Docker上的Postgres - 超出堆栈深度限制【英文标题】:Postgres on Docker - stack depth limit exeeded 【发布时间】:2019-08-05 18:54:23 【问题描述】:我在本地 Docker 上安装了 Postgres(最新版本):
码头工人撰写:
version: '3.1'
services:
postgres:
image: postgres
restart: always
ports:
- 5435:5432
environment:
POSTGRES_PASSWORD: xxxxxxx
volumes:
- pgdata:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
command:
- "postgres"
- "-c"
- "max_stack_depth=7680"
volumes:
pgdata:
networks:
network1:
我的桌子:
create TABLE dictionary.language (
id bigserial NOT NULL PRIMARY KEY,
lang_name text NOT NULL
);
create TABLE dictionary.level (
id bigserial NOT NULL PRIMARY KEY,
level smallint NOT NULL
);
create TABLE dictionary.word (
id bigserial NOT NULL PRIMARY KEY,
name text,
translation text,
language_abbr_id bigint references language(id),
level_id smallint references level(id),
last_reviewed TIMESTAMP not null DEFAULT clock_timestamp()
);
create TABLE dictionary.examples (
id bigserial NOT NULL PRIMARY KEY,
sentence text NOT NULL,
translation text NOT NULL,
word_id bigint references word(id)
);
create TABLE dictionary.user (
id bigserial NOT NULL PRIMARY KEY,
username text NOT NULL,
password text NOT NULL
);
CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
RETURNS trigger as
$$
BEGIN
INSERT INTO dictionary.word(last_reviewed)
VALUES(now());
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
create trigger updateLastReviewedAfterUpdate
before update on dictionary.word
for each row
execute procedure dictionary.set_last_reviewed();
create trigger updateLastReviewedAfterInsert
before insert on dictionary.word
for each row
execute procedure dictionary.set_last_reviewed();
我想在我的表中插入一些东西:
insert into word(id,name,translation,language_abbr_id,level,last_reviewed) values(1,'fabulous', 'bajeczny, fantastyczny' , 1 , 6 , '11/09/2018 23:58' );
然后我得到错误:
查询执行失败
原因:SQL 错误 [54001]:错误:超出堆栈深度限制提示: 增加配置参数“max_stack_depth”(目前 7680kB),在确保平台的堆栈深度限制足够之后。 其中:SQL 语句“INSERT INTO dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement ...
这可能与我的触发器有关吗?我不知道如何解决我的问题
【问题讨论】:
【参考方案1】:您的插入触发器在表word
中插入一个新行,这反过来会触发插入触发器,它会插入一个新行来触发触发器......等等。
据我所知,您只是想为该列设置一个默认值。
您可以通过更改触发器处理的记录来做到这一点,而不是通过在表中插入一个全新的行:
只需将触发器更改为:
CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
RETURNS trigger as
$$
BEGIN
new.last_reviewed := now();
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
【讨论】:
以上是关于Docker上的Postgres - 超出堆栈深度限制的主要内容,如果未能解决你的问题,请参考以下文章
IOS 上的 React-native:无法调整当前堆栈顶部超出可用视图
在主机上的客户端 docker 和 postgres 服务器之间连接 [重复]
docker-compose ECONNREFUSED 用于 nodeJS 上的 Postgres