Contents
- 問題のクエリを含む
plr.sql - share/extension
内にある plr.sql とは別 - 実際のサーバクラッシュ時
怖いと言っても「ある種の
「古いバージョンで」というのも
開発側は当然分かっていて、修正に伴う確認用クエリを追加しただけと思いますが、現時点ではコミット履歴を見ないとそのことが分かりません。何気なく「テストクエリがあるから実行してみよ~」とかやると危険なので、以下メモ。
問題のクエリを含む plr.sql
下記です。今年35
-- -- test simple input/output types -- CREATE OR REPLACE FUNCTION rint2(i int2) RETURNS int2 AS $$ return (as.integer(i)) $$ LANGUAGE plr; select rint2(1::int2); select rint2(NULL);-- Postgres crashes on previous PL/R.
修正されたのは
# CREATE OR REPLACE FUNCTION rint2_rev(i int2) RETURNS int2 AS $$ if (! is.null(i)) return (as.integer(i)) $$ LANGUAGE plr; # select rint2_rev(1::int2); +-----------+ | rint2_rev | +-----------+ | 1 | +-----------+ (1 row) # select rint2_rev(NULL); +-----------+ | rint2_rev | +-----------+ | | +-----------+ (1 row)
上記の実行環境は
share/extension 内にある plr.sql とは別
ややこしい。問題の$ ls /usr/pgsql-9.5/share/extension/plr* /usr/pgsql-9.5/share/extension/plr--8.3.0.16.sql /usr/pgsql-9.5/share/extension/plr--unpackaged--8.3.0.16.sql /usr/pgsql-9.5/share/extension/plr.control /usr/pgsql-9.5/share/extension/plr.sql
実際のサーバクラッシュ時
どんなエラーが出るかの記録として。クライアント側では ↓ サーバとの接続が突然切れたことしか分かりません。その下がサーバのログ。-- source of the function # \sf public.rint2 CREATE OR REPLACE FUNCTION public.rint2(i smallint) RETURNS smallint LANGUAGE plr AS $function$ return (as.integer(i)) $function$ -- query to terminate server # select rint2(NULL); server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed.
$ cat $PGDATA/pg_log/postgresql-Tue.log Error: CHAR() can only be applied to a 'CHARSXP', not a 'logical' *** stack smashing detected ***: postgres: postgres test_plr [local] SELECT terminated < 2016-07-19 08:48:09.664 JST >LOG: server process (PID 12699) was terminated by signal 11: Segmentation fault < 2016-07-19 08:48:09.664 JST >DETAIL: Failed process was running: select rint2(NULL); < 2016-07-19 08:48:09.664 JST >LOG: terminating any other active server processes < 2016-07-19 08:48:09.665 JST >WARNING: terminating connection because of crash of another server process < 2016-07-19 08:48:09.665 JST >DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. < 2016-07-19 08:48:09.665 JST >HINT: In a moment you should be able to reconnect to the database and repeat your command. < 2016-07-19 08:48:09.666 JST >LOG: all server processes terminated; reinitializing < 2016-07-19 08:48:09.676 JST >LOG: database system was interrupted; last known up at 2016-07-19 08:31:26 JST < 2016-07-19 08:48:09.771 JST >LOG: database system was not properly shut down; automatic recovery in progress < 2016-07-19 08:48:09.772 JST >LOG: invalid record length at 0/1805348 < 2016-07-19 08:48:09.772 JST >LOG: redo is not required < 2016-07-19 08:48:09.775 JST >LOG: MultiXact member wraparound protections are now enabled < 2016-07-19 08:48:09.778 JST >LOG: database system is ready to accept connections < 2016-07-19 08:48:09.778 JST >LOG: autovacuum launcher started
というわけで