One of my favorite PostgreSQL features is the ability to attach a comment to an object.
COMMENT ON object_type object_name IS 'text'
For example, create a schema and add a comment to it:
create schema comment_demo;
comment on schema comment_demo is 'comments demo';
Append +
to the psql meta-command to list schemas (\dn
) to show comments:
stan=> \dn+ comment_demo
List of schemas
Name │ Owner │ Access privileges │ Description
──────────────┼───────┼───────────────────┼───────────────
comment_demo │ stan │ │ comments demo
Set a comment to NULL to remove it:
comment on schema comment_demo is NULL;
Unless you have superuser privileges, you can’t add a comment to an object you don’t own:
stan=> comment on schema public is 'not owned by me';
ERROR: must be owner of schema public
A comment can be attached to a wide variety of objects, as shown by psql’s auto-completion options:
For more information, see the PostgreSQL documentation for COMMENT.