Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDwA3-0003ZA-K4 for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 13:17:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDwA2-0005Ga-JM for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 13:17:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDgoo-0008Du-TP for pgsql-bugs@postgresql.org; Wed, 12 Feb 2014 20:54:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDgol-0000Xi-B1 for pgsql-bugs@postgresql.org; Wed, 12 Feb 2014 20:54:06 +0000 MIME-Version: 1.0 Subject: BUG #9202: C Functions crash database too easily To: pgsql-bugs@postgresql.org From: rotten@windfish.net Date: Wed, 12 Feb 2014 20:53:02 +0000 Message-ID: <20140212205302.2708.53160@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 9202 Logged by: Rick Otten Email address: rotten@windfish.net PostgreSQL version: 9.3.2 Operating system: Ubuntu 12.04 Description: While setting up a third party (commerical) provided C library functions I've observed PostgreSQL 9.3.2 to be very sensitive to simple typos. 1) If you create the function with a different number of arguments than the C function expects, the create works just fine. However, every time you do a select, the database chokes: 2014-02-11 13:03:27.989 EST mydb [local] postgresLOG: statement: create function myschema.my_6_argument_function(character, character, character, character, character) returns character as '/some/path/lib/some.so', 'My_6_Arg_Function' LANGUAGE C STRICT; ... 2014-02-11 13:03:33.919 EST LOG: server process (PID 9090) was terminated by signal 11: Segmentation fault 2014-02-11 13:03:33.920 EST DETAIL: Failed process was running: select myschema.my_6_argument_function('arg1', 'arg2', 'arg3', 'arg4', 'arg5'); 2014-02-11 13:03:33.920 EST LOG: terminating any other active server processes 2014-02-11 13:03:33.922 EST [unknown] [unknown]LOG: connection received: host=[local] 2014-02-11 13:03:33.922 EST mydb [local] postgresFATAL: the database system is in recovery mode 2014-02-11 13:03:33.929 EST WARNING: terminating connection because of crash of another server process 2014-02-11 13:03:33.929 EST 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. 2014-02-11 13:03:33.929 EST HINT: In a moment you should be able to reconnect to the database and repeat your command. 2014-02-11 13:03:33.933 EST LOG: all server processes terminated; reinitializing 2014-02-11 13:03:34.061 EST LOG: database system was interrupted; last known up at 2014-02-11 13:02:37 EST 2014-02-11 13:03:34.061 EST LOG: database system was not properly shut down; automatic recovery in progress 2014-02-11 13:03:34.066 EST LOG: redo starts at 10/203C360 2014-02-11 13:03:34.067 EST LOG: record with zero length at 10/20433C8 2014-02-11 13:03:34.067 EST LOG: redo done at 10/2043398 2014-02-11 13:03:34.067 EST LOG: last completed transaction was at log time 2014-02-11 13:03:27.994445-05 2014-02-11 13:03:34.101 EST LOG: autovacuum launcher started 2014-02-11 13:03:34.101 EST LOG: database system is ready to accept connections 2) The same thing happens if you try to create the same function twice: 2014-02-12 15:20:45.626 EST mydb [local] postgresLOG: statement: create function myschema.myfunction(character, character) returns character as '/some/path/somelib', 'MY_Function' LANGUAGE C STRICT; 2014-02-12 15:20:45.626 EST mydb [local] postgresWARNING: using index "pg_event_trigger_evtname_index" despite IgnoreSystemIndexes 2014-02-12 15:20:45.627 EST mydb [local] postgresPANIC: function "myfunction" already exists with same argument types 2014-02-12 15:20:45.627 EST mydb [local] postgresSTATEMENT: create function myschema.myfunction(character, character) returns character as '/some/path/somelib', 'My_Function' LANGUAGE C STRICT; 2014-02-12 15:20:45.768 EST LOG: server process (PID 2316) was terminated by signal 6: Aborted 2014-02-12 15:20:45.768 EST DETAIL: Failed process was running: create function myschema.myfunction(character, character) returns character as '/some/path/somelib', 'MY_Function' LANGUAGE C STRICT; 2014-02-12 15:20:45.768 EST LOG: terminating any other active server processes 2014-02-12 15:20:45.777 EST [unknown] [unknown]LOG: connection received: host=[local] 2014-02-12 15:20:45.778 EST mydb [local] postgresFATAL: the database system is in recovery mode 2014-02-12 15:20:45.778 EST WARNING: terminating connection because of crash of another server process 2014-02-12 15:20:45.778 EST 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. 2014-02-12 15:20:45.778 EST HINT: In a moment you should be able to reconnect to the database and repeat your command. 2014-02-12 15:20:45.783 EST LOG: all server processes terminated; reinitializing 2014-02-12 15:20:45.926 EST LOG: database system was interrupted; last known up at 2014-02-12 07:05:01 EST 2014-02-12 15:20:45.927 EST LOG: database system was not properly shut down; automatic recovery in progress 2014-02-12 15:20:45.934 EST LOG: record with zero length at 10/4000090 2014-02-12 15:20:45.934 EST LOG: redo is not required 2014-02-12 15:20:45.968 EST LOG: autovacuum launcher started 2014-02-12 15:20:45.969 EST LOG: database system is ready to accept connections For case (1) I think you shouldn't be able to create a C function without the right number of arguments. Or at least if you do a select, instead of crashing the database, PostgreSQL should catch the error and reports it. For case (2) accidentally creating an object with the same name as an existing object seems like a regular sort of thing that could happen. It shouldn't crash the database when the name collision occurs. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs