Logging executed SQL

65 views
Skip to first unread message

Stephen Zander

unread,
Jan 20, 2022, 6:59:17 PM1/20/22
to SQL Workbench/J - DBMS independent SQL tool
Is it possible (using log4j if necessary) to log successfully execute SQL?

I know I can log SQL that fails (although I've forgotten how I turned that on), but can't see any way of logging on successful execution.

I'd like to do this because I find myself keeping an every growing list of open tabs because I can't remember what I was doing in the previous tabs but don't want to drop them incase I need the SQL again.

If SQL/Workbench J logged successfully executed SQL, then at least I could rep through the log when trying to find some query I did three weeks ago

Thomas Kellerer

unread,
Jan 21, 2022, 2:04:05 AM1/21/22
to sql-wo...@googlegroups.com
Yes, those statements can be logged

Tools -> Options -> General -> "Log all SQL statements as INFO messages".

Additionally every SQL editor keeps a history of its content, which is persisted in the connections's workspace. You can scroll through the editor content through e.g. "SQL -> Editor history back" (similar to the history in a browser).

As this is stored in the profile's workspace, this history is retained over a restart (or switch of a connection/profile with a different workspace).
You can configure the size of the editor's history in "Tools -> Options -> Editor -> History size"

And finally there is the "WbHistory" command that shows you the list of statements executed in the current editor since the connection was established.
This history is not retained across a restart.

In my experience, a huge number of open tabs is a sign, that you should really look into using workspaces (see: https://www.sql-workbench.eu/manual/workspace-usage.html )
I recommend to have one workspace per connection profile.

I also keep many workspaces around, that are not directly related to a specific profile, but a specific task (or set of tasks). I then load that workspace using "Workspace -> Load workspace". The 10 recently loaded workspaces (through that menu) will be kept in the "Recent Workspaces" menu, so if you have workspaces that you need frequently, they are easy to reach.



Regards
Thomas

Stephen Zander

unread,
Jan 21, 2022, 2:56:56 PM1/21/22
to SQL Workbench/J - DBMS independent SQL tool
Thanks, Thomas!

I actually use a Workspace for each connection today.  I just end up doing multiple, unrelated tasks against our DWH connection, which leads to the plethora of tabs as I'm afraid to delete old work whose purpose I can no longer remember.  I guess I need task specific workplaces instead of connection specific ones

Two questions about workplaces and editor history:
1.  How does it handle closed tabs?  Are they just lost?
2. Should SQL -> Editor history back just work?  Or do I have to set an option first?

As you can see from the screenshot below,  the editor functions are all disabled in my SQL menu.  The history size has a value so it's not that.

Screen Shot 2022-01-21 at 13.40.53.png
Screen Shot 2022-01-21 at 13.46.59.png

Thomas Kellerer

unread,
Jan 21, 2022, 5:36:27 PM1/21/22
to sql-wo...@googlegroups.com
> Two questions about workplaces and editor history:
> 1. How does it handle closed tabs? Are they just lost?

If you close SQL Workbench and thus save the workspace, then yes, the tab (and all content) is gone.

As long as SQL Workbench is still open, you can restore the closed ones through "Tools -> Recently closed"


> 2. Should SQL -> Editor history back just work? Or do I have to set an option first?

You can't go back unless you have executed a statement.

> As you can see from the screenshot below, the editor functions are all disabled in my SQL menu. The history size has a value so it's not that.

This looks like you just created an empty workspace and have not executed any SQL statement.

Regards
Thomas



Stephen Zander schrieb am 21.01.2022 um 20:56:
> Thanks, Thomas!
>
> I actually use a Workspace for each connection today.  I just end up doing multiple, unrelated tasks against our DWH connection, which leads to the plethora of tabs as I'm afraid to delete old work whose purpose I can no longer remember.  I guess I need task specific workplaces instead of connection specific ones
>
> Two questions about workplaces and editor history:
> 1.  How does it handle closed tabs?  Are they just lost?
> 2. Should SQL -> Editor history back just work?  Or do I have to set an option first?
>
>
> Screen Shot 2022-01-21 at 13.40.53.png
> --
> You received this message because you are subscribed to the Google Groups "SQL Workbench/J - DBMS independent SQL tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sql-workbenc...@googlegroups.com <mailto:sql-workbenc...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sql-workbench/5de6a7fe-2a01-4665-83cf-c516c8e206b2n%40googlegroups.com <https://groups.google.com/d/msgid/sql-workbench/5de6a7fe-2a01-4665-83cf-c516c8e206b2n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Thomas Kellerer

unread,
Jan 22, 2022, 9:09:21 AM1/22/22
to sql-wo...@googlegroups.com
> I just end up doing multiple, unrelated tasks against our DWH connection, which leads to the plethora of tabs

You might also want to consider defining those SQL statements as macros, so that they are available for any connection.
You can also have a different set of macros for each profile.

Regards
Thomas


Stephen Zander schrieb am 21.01.2022 um 20:56:
> Thanks, Thomas!
>
> I actually use a Workspace for each connection today.  I just end up doing multiple, unrelated tasks against our DWH connection, which leads to the plethora of tabs as I'm afraid to delete old work whose purpose I can no longer remember.  I guess I need task specific workplaces instead of connection specific ones
>
> Two questions about workplaces and editor history:
> 1.  How does it handle closed tabs?  Are they just lost?
> 2. Should SQL -> Editor history back just work?  Or do I have to set an option first?
>
> As you can see from the screenshot below,  the editor functions are all disabled in my SQL menu.  The history size has a value so it's not that.
>
> Screen Shot 2022-01-21 at 13.40.53.png
Reply all
Reply to author
Forward
0 new messages