[PATCH] Implement motd for PostgreSQL

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org, "Michael Paquier" <michael(at)paquier(dot)xyz>
Subject: [PATCH] Implement motd for PostgreSQL
Date: 2021-04-02 20:46:16
Message-ID: 52ea0d51-7377-4a0a-aa24-f0fdf4c8bce1@www.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear fellow hackers,

This patch is one day late, my apologies for missing the deadline this year.

PostgreSQL has since long been suffering from the lack of a proper UNIX style motd (message of the day).

DBAs have no ways of conveying important information to users,
having to rely on external protocols, such as HTTPS and "websites" to provide such information.

By adding a motd configuration parameter, the DBA can set this to a text string,
which will be automatically presented to the user as a NOTICE when logging on to the server.

While at it, fix escape_single_quotes_ascii() to properly escape newlines,
so that such can be used in ALTER SYSTEM values.
This makes sense, since parsing \n in config values works just fine.

To demonstrate the usefulness of this feature,
I've setup an open public PostgreSQL server at "pit.org",
to which anyone can connect without a password.

You need to know the username though,
which will hopefully make problems for bots.

$ psql -U brad -h pit.org motd
NOTICE:
____ ______ ___
/ )/ /
( / __ _ )
(/ o) ( o) )
_ (_ ) ) /
/_/ )_/
/ //| |\
v | | v
__/

This was accomplished by setting the "motd",
which requires superuser privileges:

$ psql motd
psql (14devel)
Type "help" for help.

motd=# ALTER SYSTEM SET motd TO E'\u001B[94m'
'\n ____ ______ ___ '
'\n / )/ \/ \ '
'\n ( / __ _\ )'
'\n \ (/ o) ( o) )'
'\n \_ (_ ) \ ) / '
'\n \ /\_/ \)_/ '
'\n \/ //| |\\ '
'\n v | | v '
'\n \__/ '
'\u001b[0m';
ALTER SYSTEM
motd=# SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)

motd=# \q

Ascii elephant in example by Michael Paquier [1], with ANSI colors added by me.

[1] https://www.postgresql.org/message-id/CAB7nPqRaacwcaANOYY3Hxd3T0No5RdZXyqM5HB6fta%2BCoDLOEg%40mail.gmail.com

Happy Easter!

/Joel

Attachment Content-Type Size
0001-quote-newlines.patch application/octet-stream 900 bytes
0002-motd.patch application/octet-stream 1.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2021-04-02 20:51:39 Re: [PATCH] Implement motd for PostgreSQL
Previous Message Andres Freund 2021-04-02 20:44:22 Re: Making wait events a bit more efficient