Customizing Your PostgreSQL Prompt: How to Set a Colorful and Eye-Catching psql Prompt

 


The psql interactive command line prompt can be customized through the psqlrc file, which comes in three variations:

  1. The system-wide startup file, called psqlrc, can be found in the installation's "system configuration" directory. The directory can be identified by running pg_config --sysconfdir, and its name can be set explicitly through the PGSYSCONFDIR environment variable.
  2. The user's personal startup file, named .psqlrc, can be found in the user's home directory. On Windows, the personal startup file is named %APPDATA%\postgresql\ psqlrc.conf due to the lack of a home directory concept. The location of the user's startup file can be set explicitly through the PSQLRC environment variable.
  3. Both the system-wide startup file and the user's personal startup file can be made psql-version-specific by appending a dash and the PostgreSQL major or minor release number to the file name. For example, the user's startup file for PostgreSQL 9.2 or 9.2.5 would be ~/.psqlrc-9.2 or ~/.psqlrc-9.2.5.
Prompting settings:

%M   The full host name (with domain name) of the database server
%m   The host name of the database server, truncated at the first dot
%>   The port number at which the database server is listening.
%n   The database session username.
%/   The name of the current database.

Colors
Please find the below values for various colours:

32 for green
33 for yellow
34 for blue
35 for magenta
36 for cyan
37 for white
1;31;40 red

By default, the psqlrc file displays welcome messages and various informational outputs after being edited. To hide these, you can set the QUIET flag at the beginning and end of the psql file.

su - postgres
vi ~/.psqlrc

Non-prod

\set QUIET 1
\pset border 2
\timing
\set QUIET 0
\conninfo
\set PROMPT1 '%001%[%033[1;32;40m%][%`hostname`] %002%n@%/%R%001%[%033[0m%]%002%# '

Prod:

\set QUIET 1
\pset border 2
\timing
\set QUIET 0
\conninfo
\set PROMPT1 '%001%[%033[1;31;40m%][%`hostname`] %002%n@%/%R%001%[%033[0m%]%002%# '

Demo:




DISCLAIMER

The purpose of sharing the content on this website is to Educate. The author/owner of the content do not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions.The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website. So, use the content of this website at your own risk.

This content has been shared under Educational And Non-Profit Purposes Only. No Copyright Infringement Intended, All Rights Reserved to the Actual Owner.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com


Tags: PostgreSQL administration,PostgreSQL database management,PostgreSQL performance tuning,PostgreSQL backup and recovery,PostgreSQL security,PostgreSQL monitoring,PostgreSQL replication,PostgreSQL migration,PostgreSQL high availability,PostgreSQL clustering,PostgreSQL optimization,PostgreSQL troubleshooting,PostgreSQL query optimization,PostgreSQL indexing,PostgreSQL partitioning,PostgreSQL DBA training,Learn PostgreSQL DBA,PostgreSQL database administration course,Online PostgreSQL DBA certification,PostgreSQL DBA tutorial,PostgreSQL DBA workshop,PostgreSQL DBA bootcamp,PostgreSQL DBA classes,Advanced PostgreSQL DBA,PostgreSQL DBA best practices,PostgreSQL DBA skills,PostgreSQL DBA fundamentals,PostgreSQL DBA basics,PostgreSQL DBA for beginners,PostgreSQL DBA career,PostgreSQL database administration,PostgreSQL DBA best practices,PostgreSQL DBA skills,PostgreSQL DBA training,PostgreSQL DBA certification,PostgreSQL DBA tutorial,PostgreSQL DBA course,PostgreSQL DBA workshop,Advanced PostgreSQL DBA,PostgreSQL DBA job description,PostgreSQL DBA responsibilities,PostgreSQL DBA salary,PostgreSQL DBA interview questions,PostgreSQL DBA performance tuning,PostgreSQL DBA backup and recovery,Top PostgreSQL interview questions,Common PostgreSQL interview questions,PostgreSQL interview questions and answers,PostgreSQL DBA interview questions,PostgreSQL developer interview questions,latest PostgreSQL interview questions,PostgreSQL interview questions 2023,PostgreSQL interview questions 2024,latest PostgreSQL DBA,,PostgreSQL for beginners,PostgreSQL tutorial for beginners,PostgreSQL basics,Learn PostgreSQL,PostgreSQL introduction,PostgreSQL beginner course,PostgreSQL training for beginners,PostgreSQL fundamentals,Getting started with PostgreSQL,PostgreSQL crash course,PostgreSQL 101,PostgreSQL beginner's guide,PostgreSQL beginner's tutorial, PostgreSQL beginner's workshop, PostgreSQL beginner's online course,#PostgreSQL,#PostgreSQLAdministration,#DatabaseManagement, #Database Administration,#PostgreSQLPerformance,#BackupAndRecovery,#Security,#Monitoring,#Replication,#Migration,#HighAvailability,#Clustering,#Optimization,#Troubleshooting,#QueryOptimization,#Indexing,#Partitioning,#Training,#Certification,#OnlineCourse

Post a Comment

Previous Post Next Post