HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Add banner motd to postgres database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresmotddatabasebanneradd

Problem

I would like to present a banner motd (message of the day) to users that connect to a Postgresql database. Similar to cisco router and switch cli where you use:

banner motd "Seien Sie bitte vorsichtig....."


And then upon logging into the switch/router you see that message.

I'd like to see something similar when connecting to a database.

example:

$ psql postgres
psql (12.0)
Type "help" for help.
Seien Sie bitte vorsichtig.....

postgres=#

Solution

You cannot force that on the server side, because the server cannot control what a client displays.

But yan can do it on the client side: create a .psqlrc file in your home directory that contains something like:

\echo Seien Sie bitte vorsichtig.....


But I assume, given the text of the warning, that you want this bannet only for certain sensitive databases.

For that, you could have banner table in every database, and the statement in .psqlrc would be like:

\set QUIET on
\pset format unaligned
SELECT * FROM banner;
\pset format aligned
\set QUIET off

Code Snippets

\echo Seien Sie bitte vorsichtig.....
\set QUIET on
\pset format unaligned
SELECT * FROM banner;
\pset format aligned
\set QUIET off

Context

StackExchange Database Administrators Q#251337, answer score: 7

Revisions (0)

No revisions yet.