Docker 上的 Postgres - 超出堆栈深度限制
Postgres on Docker - stack depth limit exeeded
我在本地安装了 Postgres(最新版本)Docker:
docker-撰写:
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:
我的tables:
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();
我想在我的 table:
中插入一些内容
insert into word(id,name,translation,language_abbr_id,level,last_reviewed) values(1,'fabulous', 'bajeczny, fantastyczny' , 1 , 6 , '11/09/2018 23:58' );
然后我得到错误:
Query execution failed
Reason: SQL Error [54001]: ERROR: stack depth limit exceeded Hint:
Increase the configuration parameter "max_stack_depth" (currently
7680kB), after ensuring the platform's stack depth limit is adequate.
Where: 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 SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement ...
会不会和我的触发器有关?我不知道如何解决我的问题
您的插入触发器将新行插入到 table word
中,这又会触发插入触发器,插入触发器会插入新行并触发触发器....等等。
据我所知,您只是想为该列设置一个默认值。
您可以通过更改触发器处理的记录来执行此操作,而不是将一个全新的行插入 table:
只需将触发器更改为:
CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
RETURNS trigger as
$$
BEGIN
new.last_reviewed := now();
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
我在本地安装了 Postgres(最新版本)Docker:
docker-撰写:
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:
我的tables:
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();
我想在我的 table:
中插入一些内容insert into word(id,name,translation,language_abbr_id,level,last_reviewed) values(1,'fabulous', 'bajeczny, fantastyczny' , 1 , 6 , '11/09/2018 23:58' );
然后我得到错误:
Query execution failed
Reason: SQL Error [54001]: ERROR: stack depth limit exceeded Hint: Increase the configuration parameter "max_stack_depth" (currently 7680kB), after ensuring the platform's stack depth limit is adequate. Where: 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 SQL statement "INSERT INTO
dictionary.word(last_reviewed)
VALUES(now())" PL/pgSQL function set_last_reviewed() line 3 at SQL statement ...
会不会和我的触发器有关?我不知道如何解决我的问题
您的插入触发器将新行插入到 table word
中,这又会触发插入触发器,插入触发器会插入新行并触发触发器....等等。
据我所知,您只是想为该列设置一个默认值。
您可以通过更改触发器处理的记录来执行此操作,而不是将一个全新的行插入 table:
只需将触发器更改为:
CREATE OR REPLACE FUNCTION dictionary.set_last_reviewed()
RETURNS trigger as
$$
BEGIN
new.last_reviewed := now();
RETURN NEW;
END;
$$
LANGUAGE plpgsql;