Estou trabalhando dentro do postgres.c (dentro do exexc_simple_query) do postgresql 9.1 (linha 1094 de http://doxygen.postgresql.org/postgres_8c_source.html#l00829 ). Preciso inserir algumas informações de consulta em uma tabela que verificarei em um segundo momento. Estou tentando fazer isso com SPI usando essas três linhas:
SPI_connect();
SPI_exec("INSERT INTO testvalues (11,6)", 5);
SPI_finish();
mas quando inicio o servidor e envio uma consulta recebo falha de segmentação:
LOG: server process (PID 13856) was terminated by signal 11: Segmentation fault
LOG: terminating any other active server processes
WARNING: terminating connection because of crash of another server process
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.
HINT: In a moment you should be able to reconnect to the database and repeat your command.
FATAL: the database system is in recovery mode
LOG: all server processes terminated; reinitializing
LOG: database system was interrupted; last known up at 2013-07-14 00:40:22 CEST
LOG: database system was not properly shut down; automatic recovery in progress
LOG: record with zero length at 0/17D7368
LOG: redo is not required
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
Você tem alguma ideia de como posso consertar isso? Existe uma maneira melhor de inserir dados do postgres.c?
Achei o erro. As funções SPI devem estar dentro da transação e, no meu caso, entre
start_xact_command
efinish_xact_command
.