Skip to content

Commit

Permalink
Use the right SQL commands for killing a process on PostgreSQL. See h…
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarbecker committed Oct 31, 2016
1 parent bf9f6c6 commit aa373aa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions out/locale/en/LC_MESSAGES/default.po
Expand Up @@ -4748,8 +4748,8 @@ msgid "Displaying objects from \"%s\" ..."
msgstr "Displaying objects from \"%s\" ..."

#: main.pas:4784
msgid "Ignoring own process id #%s when trying to kill it."
msgstr "Ignoring own process id #%s when trying to kill it."
msgid "Ignoring own process id #%d when trying to kill it."
msgstr "Ignoring own process id #%d when trying to kill it."

#: main.pas:5158
msgid "Uptime"
Expand Down
5 changes: 4 additions & 1 deletion source/dbconnection.pas
Expand Up @@ -284,7 +284,7 @@ TConnectionParameters = class(TObject)
spAddColumn, spChangeColumn,
spSessionVariables, spGlobalVariables,
spISTableSchemaCol,
spUSEQuery, spKillQuery,
spUSEQuery, spKillQuery, spKillProcess,
spFuncLength, spFuncCeil);

TDBConnection = class(TComponent)
Expand Down Expand Up @@ -2029,6 +2029,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spISTableSchemaCol] := 'TABLE_SCHEMA';
FSQLSpecifities[spUSEQuery] := 'USE %s';
FSQLSpecifities[spKillQuery] := 'KILL %d';
FSQLSpecifities[spKillProcess] := 'KILL %d';
FSQLSpecifities[spFuncLength] := 'LENGTH';
FSQLSpecifities[spFuncCeil] := 'CEIL';
end;
Expand All @@ -2044,6 +2045,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spISTableSchemaCol] := 'TABLE_CATALOG';
FSQLSpecifities[spUSEQuery] := 'USE %s';
FSQLSpecifities[spKillQuery] := 'KILL %d';
FSQLSpecifities[spKillProcess] := 'KILL %d';
FSQLSpecifities[spFuncLength] := 'LEN';
FSQLSpecifities[spFuncCeil] := 'CEILING';
end;
Expand All @@ -2059,6 +2061,7 @@ procedure TDBConnection.DoBeforeConnect;
FSQLSpecifities[spISTableSchemaCol] := 'table_schema';
FSQLSpecifities[spUSEQuery] := 'SET search_path TO %s';
FSQLSpecifities[spKillQuery] := 'SELECT pg_cancel_backend(%d)';
FSQLSpecifities[spKillProcess] := 'SELECT pg_cancel_backend(%d)';
FSQLSpecifities[spFuncLength] := 'LENGTH';
FSQLSpecifities[spFuncCeil] := 'CEIL';
end;
Expand Down
10 changes: 5 additions & 5 deletions source/main.pas
Expand Up @@ -5441,7 +5441,7 @@ procedure TMainForm.ValidateQueryControls(Sender: TObject);
procedure TMainForm.KillProcess(Sender: TObject);
var
t: Boolean;
pid: String;
pid: Int64;
Node: PVirtualNode;
Conn: TDBConnection;
begin
Expand All @@ -5452,12 +5452,12 @@ procedure TMainForm.KillProcess(Sender: TObject);
begin
Node := GetNextNode(ListProcesses, nil, True);
while Assigned(Node) do begin
pid := ListProcesses.Text[Node, ListProcesses.Header.MainColumn];
pid := StrToInt64Def(ListProcesses.Text[Node, ListProcesses.Header.MainColumn], 0);
// Don't kill own process
if pid = IntToStr(Conn.ThreadId) then
LogSQL(f_('Ignoring own process id #%s when trying to kill it.', [pid]))
if pid = Conn.ThreadId then
LogSQL(f_('Ignoring own process id #%d when trying to kill it.', [pid]))
else try
Conn.Query('KILL '+pid);
Conn.Query(Format(Conn.GetSQLSpecifity(spKillProcess), [pid]));
except
on E:EDatabaseError do begin
if Conn.LastErrorCode <> 1094 then
Expand Down

0 comments on commit aa373aa

Please sign in to comment.