SQL queries text log analyzing
I have a text log file (log4net) with many SQL queries in parametrized format and with stacktraces. It also contains output from other loggers which should be ignored.
An example of one log entry:
2016-06-27 22:17:14,181 [98] DEBUG NHibernate.SQL [(null)] - select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570 [Type: Int32 (0)]
at NHibernate.AdoNet.Util.SqlStatementLogger.LogCommand(String message, IDbCommand command, FormatStyle style) in p:nhibernate-coresrcNHibernateAdoNetUtilSqlStatementLogger.cs:line 56
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in p:nhibernate-coresrcNHibernateAdoNetAbstractBatcher.cs:line 216
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1200
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 419
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 251
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1564
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1472
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRLoaderQueryLoader.cs:line 288
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRQueryTranslatorImpl.cs:line 109
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in p:nhibernate-coresrcNHibernateEngineQueryHQLQueryPlan.cs:line 106
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in p:nhibernate-coresrcNHibernateImplSessionImpl.cs:line 654
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in p:nhibernate-coresrcNHibernateImplAbstractSessionImpl.cs:line 93
at NHibernate.Impl.ExpressionQueryImpl.List() in p:nhibernate-coresrcNHibernateImplExpressionQueryImpl.cs:line 58
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 103
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 35
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 40
...
I want to analyze which queries are executed more often than others and show the list of stacktraces for them.
How can I do it?
logs profiler tools hibernate
bumped to the homepage by Community♦ 2 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 2 more comments
I have a text log file (log4net) with many SQL queries in parametrized format and with stacktraces. It also contains output from other loggers which should be ignored.
An example of one log entry:
2016-06-27 22:17:14,181 [98] DEBUG NHibernate.SQL [(null)] - select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570 [Type: Int32 (0)]
at NHibernate.AdoNet.Util.SqlStatementLogger.LogCommand(String message, IDbCommand command, FormatStyle style) in p:nhibernate-coresrcNHibernateAdoNetUtilSqlStatementLogger.cs:line 56
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in p:nhibernate-coresrcNHibernateAdoNetAbstractBatcher.cs:line 216
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1200
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 419
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 251
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1564
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1472
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRLoaderQueryLoader.cs:line 288
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRQueryTranslatorImpl.cs:line 109
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in p:nhibernate-coresrcNHibernateEngineQueryHQLQueryPlan.cs:line 106
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in p:nhibernate-coresrcNHibernateImplSessionImpl.cs:line 654
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in p:nhibernate-coresrcNHibernateImplAbstractSessionImpl.cs:line 93
at NHibernate.Impl.ExpressionQueryImpl.List() in p:nhibernate-coresrcNHibernateImplExpressionQueryImpl.cs:line 58
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 103
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 35
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 40
...
I want to analyze which queries are executed more often than others and show the list of stacktraces for them.
How can I do it?
logs profiler tools hibernate
bumped to the homepage by Community♦ 2 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20
|
show 2 more comments
I have a text log file (log4net) with many SQL queries in parametrized format and with stacktraces. It also contains output from other loggers which should be ignored.
An example of one log entry:
2016-06-27 22:17:14,181 [98] DEBUG NHibernate.SQL [(null)] - select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570 [Type: Int32 (0)]
at NHibernate.AdoNet.Util.SqlStatementLogger.LogCommand(String message, IDbCommand command, FormatStyle style) in p:nhibernate-coresrcNHibernateAdoNetUtilSqlStatementLogger.cs:line 56
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in p:nhibernate-coresrcNHibernateAdoNetAbstractBatcher.cs:line 216
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1200
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 419
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 251
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1564
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1472
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRLoaderQueryLoader.cs:line 288
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRQueryTranslatorImpl.cs:line 109
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in p:nhibernate-coresrcNHibernateEngineQueryHQLQueryPlan.cs:line 106
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in p:nhibernate-coresrcNHibernateImplSessionImpl.cs:line 654
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in p:nhibernate-coresrcNHibernateImplAbstractSessionImpl.cs:line 93
at NHibernate.Impl.ExpressionQueryImpl.List() in p:nhibernate-coresrcNHibernateImplExpressionQueryImpl.cs:line 58
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 103
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 35
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 40
...
I want to analyze which queries are executed more often than others and show the list of stacktraces for them.
How can I do it?
logs profiler tools hibernate
I have a text log file (log4net) with many SQL queries in parametrized format and with stacktraces. It also contains output from other loggers which should be ignored.
An example of one log entry:
2016-06-27 22:17:14,181 [98] DEBUG NHibernate.SQL [(null)] - select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570 [Type: Int32 (0)]
at NHibernate.AdoNet.Util.SqlStatementLogger.LogCommand(String message, IDbCommand command, FormatStyle style) in p:nhibernate-coresrcNHibernateAdoNetUtilSqlStatementLogger.cs:line 56
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in p:nhibernate-coresrcNHibernateAdoNetAbstractBatcher.cs:line 216
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1200
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 419
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 251
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1564
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateLoaderLoader.cs:line 1472
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRLoaderQueryLoader.cs:line 288
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) in p:nhibernate-coresrcNHibernateHqlAstANTLRQueryTranslatorImpl.cs:line 109
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) in p:nhibernate-coresrcNHibernateEngineQueryHQLQueryPlan.cs:line 106
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in p:nhibernate-coresrcNHibernateImplSessionImpl.cs:line 654
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in p:nhibernate-coresrcNHibernateImplAbstractSessionImpl.cs:line 93
at NHibernate.Impl.ExpressionQueryImpl.List() in p:nhibernate-coresrcNHibernateImplExpressionQueryImpl.cs:line 58
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 103
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 35
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression) in p:nhibernate-coresrcNHibernateLinqDefaultQueryProvider.cs:line 40
...
I want to analyze which queries are executed more often than others and show the list of stacktraces for them.
How can I do it?
logs profiler tools hibernate
logs profiler tools hibernate
edited Jun 27 '16 at 23:56
Vlad
asked Jun 27 '16 at 22:41
VladVlad
233312
233312
bumped to the homepage by Community♦ 2 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20
|
show 2 more comments
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20
|
show 2 more comments
1 Answer
1
active
oldest
votes
As previously suggested, this problem is far more tractable through programming than through SQL (if at all). Not that SQL is not programming, but it's not procedural, it's declarative. The problem with that is that this means that you have to have a good idea of the data's underlying structure in order for SQL to work.
Posrgresql (the only one of the F/LOSS databases up to the task IMHO), Oracle and MS SQL Server have very sophisticated procedural programming languages of their own which might do the job, which when combined with regular expressions might get what you want done.
A further MAJOR problem is that you'll have to implement it differently for each RDBMS - more code, more errors, more debugging, more testing, more time and more money, not to mention tedious.
Same goes for parsing this file through Python or C or whatever takes your fancy. Only advantage here is that you only have to go through the pain once.
However, I would rather take a "why reinvent the wheel?" approach.
A Google of "hibernate sql logging log4j" led me here and also to here.
You're using .net, so I Googled "hibernate sql logging log4net" and arrived here.
From that page:
Running without Log4Net
If you only want NHibernate to log the queries it sends to the data
source when running unit tests you don't have to configure Log4Net at
all. It suffices to add the show_sql key to the NHibernate
configuration. If you are using a separate xml file to configure
NHibernate (e.g. the hibernate.cfg.xml) then its content might look
similar to the one below
This would appear to be a much more profitable approach, i.e. rather than spending hours programming, "hey presto", just flick a switch.
Another alternative you may wish to consider is using the logging capabilities of your database server itself. You haven't mentioned your RDBMS, but they all have logging features of some sort or another - you may wish to make use of them.
So, in reverse order (IMHO) of desirability:
Programming on the server.
Programming using one of the standard languages.
Using the RDBMS's own logging facilities.
Using your ORM's own logging facilities.
The reason that I'm marginally in favour of using the ORM over the RDBMS is the same as for my preference for a standard language over server programming: works for any server.
Hoewever, having said that, switching on a server's logging facility is noramlly as simple as modifying a .config file and bouncing.
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
|
show 4 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f142418%2fsql-queries-text-log-analyzing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As previously suggested, this problem is far more tractable through programming than through SQL (if at all). Not that SQL is not programming, but it's not procedural, it's declarative. The problem with that is that this means that you have to have a good idea of the data's underlying structure in order for SQL to work.
Posrgresql (the only one of the F/LOSS databases up to the task IMHO), Oracle and MS SQL Server have very sophisticated procedural programming languages of their own which might do the job, which when combined with regular expressions might get what you want done.
A further MAJOR problem is that you'll have to implement it differently for each RDBMS - more code, more errors, more debugging, more testing, more time and more money, not to mention tedious.
Same goes for parsing this file through Python or C or whatever takes your fancy. Only advantage here is that you only have to go through the pain once.
However, I would rather take a "why reinvent the wheel?" approach.
A Google of "hibernate sql logging log4j" led me here and also to here.
You're using .net, so I Googled "hibernate sql logging log4net" and arrived here.
From that page:
Running without Log4Net
If you only want NHibernate to log the queries it sends to the data
source when running unit tests you don't have to configure Log4Net at
all. It suffices to add the show_sql key to the NHibernate
configuration. If you are using a separate xml file to configure
NHibernate (e.g. the hibernate.cfg.xml) then its content might look
similar to the one below
This would appear to be a much more profitable approach, i.e. rather than spending hours programming, "hey presto", just flick a switch.
Another alternative you may wish to consider is using the logging capabilities of your database server itself. You haven't mentioned your RDBMS, but they all have logging features of some sort or another - you may wish to make use of them.
So, in reverse order (IMHO) of desirability:
Programming on the server.
Programming using one of the standard languages.
Using the RDBMS's own logging facilities.
Using your ORM's own logging facilities.
The reason that I'm marginally in favour of using the ORM over the RDBMS is the same as for my preference for a standard language over server programming: works for any server.
Hoewever, having said that, switching on a server's logging facility is noramlly as simple as modifying a .config file and bouncing.
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
|
show 4 more comments
As previously suggested, this problem is far more tractable through programming than through SQL (if at all). Not that SQL is not programming, but it's not procedural, it's declarative. The problem with that is that this means that you have to have a good idea of the data's underlying structure in order for SQL to work.
Posrgresql (the only one of the F/LOSS databases up to the task IMHO), Oracle and MS SQL Server have very sophisticated procedural programming languages of their own which might do the job, which when combined with regular expressions might get what you want done.
A further MAJOR problem is that you'll have to implement it differently for each RDBMS - more code, more errors, more debugging, more testing, more time and more money, not to mention tedious.
Same goes for parsing this file through Python or C or whatever takes your fancy. Only advantage here is that you only have to go through the pain once.
However, I would rather take a "why reinvent the wheel?" approach.
A Google of "hibernate sql logging log4j" led me here and also to here.
You're using .net, so I Googled "hibernate sql logging log4net" and arrived here.
From that page:
Running without Log4Net
If you only want NHibernate to log the queries it sends to the data
source when running unit tests you don't have to configure Log4Net at
all. It suffices to add the show_sql key to the NHibernate
configuration. If you are using a separate xml file to configure
NHibernate (e.g. the hibernate.cfg.xml) then its content might look
similar to the one below
This would appear to be a much more profitable approach, i.e. rather than spending hours programming, "hey presto", just flick a switch.
Another alternative you may wish to consider is using the logging capabilities of your database server itself. You haven't mentioned your RDBMS, but they all have logging features of some sort or another - you may wish to make use of them.
So, in reverse order (IMHO) of desirability:
Programming on the server.
Programming using one of the standard languages.
Using the RDBMS's own logging facilities.
Using your ORM's own logging facilities.
The reason that I'm marginally in favour of using the ORM over the RDBMS is the same as for my preference for a standard language over server programming: works for any server.
Hoewever, having said that, switching on a server's logging facility is noramlly as simple as modifying a .config file and bouncing.
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
|
show 4 more comments
As previously suggested, this problem is far more tractable through programming than through SQL (if at all). Not that SQL is not programming, but it's not procedural, it's declarative. The problem with that is that this means that you have to have a good idea of the data's underlying structure in order for SQL to work.
Posrgresql (the only one of the F/LOSS databases up to the task IMHO), Oracle and MS SQL Server have very sophisticated procedural programming languages of their own which might do the job, which when combined with regular expressions might get what you want done.
A further MAJOR problem is that you'll have to implement it differently for each RDBMS - more code, more errors, more debugging, more testing, more time and more money, not to mention tedious.
Same goes for parsing this file through Python or C or whatever takes your fancy. Only advantage here is that you only have to go through the pain once.
However, I would rather take a "why reinvent the wheel?" approach.
A Google of "hibernate sql logging log4j" led me here and also to here.
You're using .net, so I Googled "hibernate sql logging log4net" and arrived here.
From that page:
Running without Log4Net
If you only want NHibernate to log the queries it sends to the data
source when running unit tests you don't have to configure Log4Net at
all. It suffices to add the show_sql key to the NHibernate
configuration. If you are using a separate xml file to configure
NHibernate (e.g. the hibernate.cfg.xml) then its content might look
similar to the one below
This would appear to be a much more profitable approach, i.e. rather than spending hours programming, "hey presto", just flick a switch.
Another alternative you may wish to consider is using the logging capabilities of your database server itself. You haven't mentioned your RDBMS, but they all have logging features of some sort or another - you may wish to make use of them.
So, in reverse order (IMHO) of desirability:
Programming on the server.
Programming using one of the standard languages.
Using the RDBMS's own logging facilities.
Using your ORM's own logging facilities.
The reason that I'm marginally in favour of using the ORM over the RDBMS is the same as for my preference for a standard language over server programming: works for any server.
Hoewever, having said that, switching on a server's logging facility is noramlly as simple as modifying a .config file and bouncing.
As previously suggested, this problem is far more tractable through programming than through SQL (if at all). Not that SQL is not programming, but it's not procedural, it's declarative. The problem with that is that this means that you have to have a good idea of the data's underlying structure in order for SQL to work.
Posrgresql (the only one of the F/LOSS databases up to the task IMHO), Oracle and MS SQL Server have very sophisticated procedural programming languages of their own which might do the job, which when combined with regular expressions might get what you want done.
A further MAJOR problem is that you'll have to implement it differently for each RDBMS - more code, more errors, more debugging, more testing, more time and more money, not to mention tedious.
Same goes for parsing this file through Python or C or whatever takes your fancy. Only advantage here is that you only have to go through the pain once.
However, I would rather take a "why reinvent the wheel?" approach.
A Google of "hibernate sql logging log4j" led me here and also to here.
You're using .net, so I Googled "hibernate sql logging log4net" and arrived here.
From that page:
Running without Log4Net
If you only want NHibernate to log the queries it sends to the data
source when running unit tests you don't have to configure Log4Net at
all. It suffices to add the show_sql key to the NHibernate
configuration. If you are using a separate xml file to configure
NHibernate (e.g. the hibernate.cfg.xml) then its content might look
similar to the one below
This would appear to be a much more profitable approach, i.e. rather than spending hours programming, "hey presto", just flick a switch.
Another alternative you may wish to consider is using the logging capabilities of your database server itself. You haven't mentioned your RDBMS, but they all have logging features of some sort or another - you may wish to make use of them.
So, in reverse order (IMHO) of desirability:
Programming on the server.
Programming using one of the standard languages.
Using the RDBMS's own logging facilities.
Using your ORM's own logging facilities.
The reason that I'm marginally in favour of using the ORM over the RDBMS is the same as for my preference for a standard language over server programming: works for any server.
Hoewever, having said that, switching on a server's logging facility is noramlly as simple as modifying a .config file and bouncing.
edited May 23 '17 at 12:40
Community♦
1
1
answered Jun 28 '16 at 15:51
VéraceVérace
15.9k33349
15.9k33349
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
|
show 4 more comments
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
You understood me wrong, I already have query logging and I need to analyze an output log file. E.g. a tool takes my 20mb log file and reports that there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects) and 5 of them are called much often than other 25, the most used table is X, etc...
– Vlad
Jun 28 '16 at 21:05
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
I may be wrong, but AFAICS there is a way to just output the SQL statements and not all that other verbiage which may or may not be useful for Java programmers, but it's no good for SQL. Or, as I suggested, why not log on the DB server? I respectfully suggest that you're in for a lot of pain - getting "select usertourna0_.id as id64_0_, tournament1_.id as id44_1_, usertourna0_.timestamp as timestamp64_0_ from some_table_name where usertourna0_.id=:p0 and not (1=0) order by usertourna0_.timestamp desc limit :p1;:p0 = 8570" and similar is a "fate worse than death" - sorry Michael Stonebraker.
– Vérace
Jun 28 '16 at 21:17
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
1. If by "other verbiage" you mean stack traces: it's very important to have a possibility to find which exactly line of code does some bad thing instead of just knowing that it's located somewhere in your application (especially with ORM). 2. Logging directly on DB server won't change the fact that the output is just a plain text file without any meaningful analytics like "there are 30 unique queries of 1000 total (and 10 of them are updates, 20 selects)..." 3. I'm already using my ORM logging possibilities, please don't suggest any "loggers", it's not my question.
– Vlad
Jun 29 '16 at 8:02
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
It will be much easier to parse a database query log than the file that you have posted above. And, yes, I do understand (I was also a programmer) that stack traces have their place, but in this case, for your needs of "there are 30 unique queries of 1000 total...", it is overkill. I thought there was a way you could cut out the stack traces, but if not then I believe that your task is virtually impossible.
– Vérace
Jun 29 '16 at 8:19
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
What RDBMS(s) do you use?
– Vérace
Jun 29 '16 at 8:25
|
show 4 more comments
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f142418%2fsql-queries-text-log-analyzing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As far as I can see, there's only one query in there. Plus, that log file is obscenely verbose. Why not just switch on logging at the database level?
– Vérace
Jun 27 '16 at 23:39
@Vérace this is just an example of one log entry but there are many of them
– Vlad
Jun 27 '16 at 23:44
Fair enough - anyway there's a limit on the size of posts here. However, there's no way that what you're asking can be done by a database - unless perhaps PLSQL or similar. Personally, I think that this is a job for Python or other programming language - it's a programming job not one for SQL, that's for certain. Can't you use the app itself to log its own queries?
– Vérace
Jun 27 '16 at 23:49
@Vérace, queries are already logged by the app but I need to analyze them (find most "popular").
– Vlad
Jun 27 '16 at 23:55
I think that you should maybe try on a log4net forum or Hibernate or something. How do you think database people can get the data you want from a file in that format? You could try sed/awk/grep - I believe that they're going native on Windows now.
– Vérace
Jun 28 '16 at 0:20