diff --git a/README.md b/README.md index 781d86f..f3dff47 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1069 TILs and counting..._ +_1070 TILs and counting..._ --- @@ -599,6 +599,7 @@ _1069 TILs and counting..._ - [Terminating A Connection](postgres/terminating-a-connection.md) - [Timestamp Functions](postgres/timestamp-functions.md) - [Toggling The Pager In PSQL](postgres/toggling-the-pager-in-psql.md) +- [Track psql History Separately Per Database](postgres/track-psql-history-separately-per-database.md) - [Truncate All Rows](postgres/truncate-all-rows.md) - [Truncate Tables With Dependents](postgres/truncate-tables-with-dependents.md) - [Turning Timing On](postgres/turn-timing-on.md) diff --git a/postgres/track-psql-history-separately-per-database.md b/postgres/track-psql-history-separately-per-database.md new file mode 100644 index 0000000..a315463 --- /dev/null +++ b/postgres/track-psql-history-separately-per-database.md @@ -0,0 +1,22 @@ +# Track psql History Separately Per Database + +By default, `psql` will keep track of all recent queries and commands in the +`.psql_history` file in your home directory. + +When in a `psql` session, you can hit the `Up` key to go back through the +history to find a previously entered query. That means you can quickly retrieve +and rerun past queries. + +However the default `psql` configuration means that your history can contain +queries from a `psql` session with another database that don't make sense in +the context of the current database. + +You can keep these query histories separate by configuring `psql` to use +separate history files per database. This can be done by adding the following +line to your `~/.psqlrc` file. + +``` +\set HISTFILE ~/.psql_history-:DBNAME +``` + +[source](https://github.com/hashrocket/dotmatrix/commit/1bd581db3a7192eb7aaa766a97e4b4b82d544067)