I have installed latest Drupal 8.1.1 also Devel module installed there is no any option for Display query log on devel setting page while it's present on D7 Devel module. I have created a view with relationship now I want to display SQL Query of that view at the front end.

How do I print the SQL query of a view in front end?


The Devel module includes the webprofiler module; you have to enable that to see the query log.

Note that there's currently a bug in core in 8.1 that prevents it from being used.


You can enable on "Show the SQL query" and "Show other queries run during render during live preview" on "www.example.com/admin/structure/views/settings"

enter image description here

Hope it will help you.

  • Thnx for the fast reply, all the options are already enabled("Show the SQL query" and "Show other queries run during render during live preview") this is only for admin preview I want this one for end user(authenticated and anonymous user). – Sanjay May 21 '16 at 6:17

While you could install webprofiler module, if you've already got a custom module, it might be quicker to do this:

 * Implements hook_views_post_execute().
function MY_MODULE_views_post_execute(ViewExecutable $view) {
  if ($view->id() != 'MY_SPECIAL_VIEW') {

If you're using the database abstraction layer to run your own queries, you can do use the addTag method and pass in 'debug', too.



You can simply do dpq($query->query()); That will put the query in the message area of your frontend. Edit - You will need devel module to use this feature.

$query = $db->query('MY QUERY');
print_r($query); // In the result you'll see a key "queryString" containing the actual query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.