Chapter 21. Database Roles lists the default roles of PostgreSQL. But I don't find user
postgresthere, which has been created by default in PostgreSQL. Ispostgresa default role? Does the manual miss it or do I misunderstand?In PostgreSQL, is
postgresa special user, or a regular user just like one created manually? Does the PostgreSQL server need the userpostgres? Will removing it cause some trouble to the server or something else?The following two commands run in psql provide default roles or usernames, which both include
postgres. Why do they differ?# select usename from pg_catalog.pg_user; usename ---------- postgres (1 row) # select rolname from pg_catalog.pg_roles; rolname ---------------------- postgres pg_monitor pg_read_all_settings pg_read_all_stats pg_stat_scan_tables pg_signal_backend (6 rows)
2 Answers
postgresis not a default role.When you create the PostgreSQL database cluster with
initdb, you can specify the name of the installation superuser with the-Uoption. If you omit that option, the name of the superuser will be the same as the name of the operating system user you are using.Since it is customary to have
initdbPostgreSQL run by an operating system userpostgres, the superuser is usually calledpostgrestoo, but that isn't in any way required.postgresis just a normal superuser like any other.You will have trouble dropping it because it owns all the system objects, and you cannot easily modify those objects. You are advised not to try.
pg_read_all_settingsand the others don't show up inpg_userbecause they are not login roles.
7 Comments
sudo apt install postgresqlpostgres is the first user that is available after an installation. it is a super user. But, it is possible to define your own super users which will have equivalent permissions to the postgres user.
A user is a role that has the ability to log in.
Roles without login privilege are used for various system level uses and are sometimes also used to manage access control rules through inheritance (e.g. you may have a role analysts and a user hal that is granted membership to the analysts role)
Thus pg_user only returns those roles that are able to log into the database.
2 Comments
postgres not listed as default role in the link? (2) Is it correct that a user == a role which can log in, and, a group == a role which can't log in? (3) Does the PostgreSQL server need the user postgres? WIll removing it cause some trouble to the server or something else? (4) Is there a command to show whether a user such as postgres is a superuser, and a command which can show all the superusers?
techhelpnotes DOT com/is-postgres-a-default-and-special-user-of-postgresql/(that is, plagiarised).