postgresqlHow can I view my PostgreSQL query history?
You can view your PostgreSQL query history by using the psql
command-line interface. The \s
command will show you the history of queries that have been run in the current session.
For example:
postgres=# \s
List of relations
Schema | Name | Type | Owner
--------+-----------------------+-------+----------
public | accounts | table | postgres
public | customers | table | postgres
public | orders | table | postgres
(3 rows)
postgres=# select * from accounts;
id | name | balance
----+--------+---------
1 | Alice | 1000
2 | Bob | 2000
(2 rows)
postgres=# \s
List of relations
Schema | Name | Type | Owner
--------+-----------------------+-------+----------
public | accounts | table | postgres
public | customers | table | postgres
public | orders | table | postgres
(3 rows)
History of queries run in this session:
1. select * from accounts;
The \s
command will show you the history of queries that have been run in the current session, including the query number, the query itself, and the time it was run. You can also use the \h
command to view the syntax of a query that has been run previously.
Code explanation
psql
command-line interface - This is a command-line interface for interacting with PostgreSQL databases.\s
command - This command will show you the history of queries that have been run in the current session.\h
command - This command will show you the syntax of a query that has been run previously.
Helpful links
More of Postgresql
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I set a PostgreSQL interval to zero?
- How can I use PostgreSQL's "zero if null" feature?
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL and ZFS together?
- How can I integrate PostgreSQL with Yii2?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
See more codes...