Sometimes customers request implementing a banner while connecting to the postgresql server, which will help them to identify if that is a production environment, testing environment or Dev environment.
Simply we can set up a banner which at login will display the details about the server which we would like to show.
- As the enterprisedb or postgres user, create a
.psqlrc
file in your home directory that contains something like:
\echo 'Welcome to ENTERPRISEDB!'
- The above banner will display the message "Welcome to ENTERPRISEDB!". We can modify the message as per our requirements.
[enterprisedb@localhost ~]$ vi ~/.psqlrc
[enterprisedb@localhost ~]$
[enterprisedb@localhost ~]$ vi ~/.psqlrc
[enterprisedb@localhost ~]$
-bash-4.2$ psql edb
Welcome to ENTERPRISEDB!
psql (14.5.0, server 14.5.0)
Type "help" for help.
edb=#
edb=# \q
-bash-4.2$ cat .psqlrc
\echo 'Welcome to ENTERPRISEDB!'
-bash-4.2$ pwd
/var/lib/edb
-bash-4.2$
[enterprisedb@localhost ~]$ ls -la .psqlrc
-rw-rw-r--. 1 enterprisedb enterprisedb 36 Jan 18 17:29 .psqlrc
[enterprisedb@localhost ~]$
- Version-specific psqlrc files can be created if there are multiple PostgreSQL installations. Just add the version number to the end.
For Example:
touch ~/.psqlrc-14.5