What code should I use where I used db_query()?
As quick replacement for queries on the database Drupal uses by default, you can use the following code.

use Drupal\Core\Database\Database;

$db = Drupal::database();
$result = $db-&gt;query("SHOW TABLES");


Keep in mind that:


db_query() will not be removed before Drupal 9 goes off; you can still use it, even if it is preferable to refactor your code to be more object oriented
The code I shown should be used in legacy procedural code; when possible, you should consider refactoring it to be object oriented and use Drupal 8 services and Dependency Injection Container