Check the History of Executed Queries in PostgreSQL Easily

If someone asks you to name any database-related operation, chances are that data querying will spring to your mind immediately. It's a ubiquitous operation that can be simplified for the user in more ways than one. For instance, when we talk about writing queries, we've got autocompletion, formatting, and code snippets to help us do it faster. And if we talk about executing queries and keeping track of what's been executed, we've got query history.

Why check query history in PostgreSQL?

Nearly everyone who works with databases, including developers, analysts, and DBAs, will most certainly mention data querying as one of their most frequently performed operations. And if you deal with queries just as often, you will find query history highly useful for several reasons. First, it eliminates the need to manually rewrite or save every query that you need to run on a regular basis. All you need to do is return to query history, find the required query there, and run it whenever you need. Second, for audit purposes, you have quick access to every query you have executed over the specified timespan. Note that the history is complete with detailed information, so you can sort and filter executed queries any way you like. Third, you can easily share query history with your colleagues by exporting it to a CSV file with just a few clicks.

Accessing query history in dbForge Studio for PostgreSQL

dbForge Studio for PostgreSQL has everything you need to write queries and execute them against PostgreSQL databases in the simplest and most effective manner. This includes the aforementioned query history. Now, let's see how to open it.

Steps to open query history

To open query history, use either of the two following ways:

  • Click the Query History icon on the toolbar
  • Go to the View menu > Other Windows > Query History
Open Query History

Whichever way you choose, you will be greeted by the Query History window, where you'll see a grid with every query that has been executed. The columns in the grid include the following:

  • Status: The corresponding green or red icon that reflects the success or failure of the execution
  • Query Text: The text of the executed query; it will also be available in the preview section under the grid
  • Size (Bytes): The size of the query
  • Executed On: The exact time and date the query was executed
  • Duration: The duration of the execution
  • File: The name of the SQL document file with the executed query
  • Server: The server on which the query was executed
  • User: The user who initiated the execution
  • Database: The name of the database against which the query was executed

If you hover over the required query in the grid, you will get all the info in a conveniently-looking card. Additionally, you can check the full query text in the preview section.

Query History

Features of query history in dbForge Studio

To quickly find the required query in the history, simply start typing the search string in the box. Additionally, you can narrow down your search by specifying the execution timespan.

Find the required query

You may just as well point to any column title and click the filter icon to apply additional search filters.

Filter executed queries

Exporting query history

You can easily share your current query history with your colleagues by exporting it into a CSV file. This can be done directly from the toolbar with a corresponding button.

Exported query history

Configuring query history settings

You can fine-tune the query history of dbForge Studio to your preferences. To do that, go to the Tools menu > Options > Environment > Documents > Query History. Here, you can do the following:

  • Select the Store query history checkbox to activate the history
  • In Storage location, enter a name for the history file and a path to the folder where it will be stored
  • In Max script size, indicate the maximum script size to be stored in the history; it is set to 1024 KB by default
  • Select the checkbox to automatically remove queries after a specified period of time; by default, this option is set to auto-delete queries that are older than 60 days
Configure query history settings

Conclusion

Query history is the perfect tool that helps you keep track of your queries and revisit them whenever such need arises. dbForge Studio is very detail-oriented in that respect. And you don't have to take our word for it. Just download the Studio for a free 30-day trial and see the entire range of its features, which includes context-aware code completion and formatting, query profiling, test data generation, database comparison and synchronization, and a multitude of other nifty little features that might make up a perfect IDE for your PostgreSQL databases. Give it a go today!

dbForge Studio for PostgreSQL

Your cutting-edge IDE for PostgreSQL development and management