Tuesday, July 18, 2017

Customizing My Postgres Shell

DZone Database Zone
Customizing My Postgres Shell

As a developer, your CLI is your home. You spend a lifetime of person-years in your shell, and even small optimizations can pay major dividends to your efficiency. For anyone that works with Postgres (and likely the PSQL editor), you should consider investing some love and care into PSQL. A little-known fact is that PSQL has a number of options you can configure it with, and these configuration options can all live within an RC file called psqlrc in your home directory. Here is my .psqlrc file, which I’ve customized to my liking. Let’s walk through some of the commands within my .psqlrc file:

\set QUIET 1 \pset null '¤' \set PROMPT1 '%[%033[1m%][%/] # ' -- SELECT * FROM<enter>. %R shows what type of input it expects. \set PROMPT2 '... > ' \timing \x auto \set VERBOSITY verbose \set HISTFILE ~/.psql_history- :DBNAME \set HISTCONTROL ignoredups \set COMP_KEYWORD_CASE upper \unset QUIET

First, you see that we set QUIET 1. This makes it less noisy when we start up. We also unset QUIET at the end so it’s back to a standard psql shell later.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...