9951 explained code solutions for 126 technologies


postgresqlHow do I grant all privileges on a PostgreSQL database?


To grant all privileges on a PostgreSQL database, you can use the GRANT command.

Below is an example of granting all privileges on a database called mydb to a user called myuser:

GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

This command grants myuser the following privileges on mydb:

  • SELECT: Allows myuser to read the data in the database.
  • INSERT: Allows myuser to add new rows to tables in the database.
  • UPDATE: Allows myuser to modify existing rows in tables in the database.
  • DELETE: Allows myuser to delete rows from tables in the database.
  • TRUNCATE: Allows myuser to delete all rows from tables in the database.
  • REFERENCES: Allows myuser to create foreign key constraints on tables in the database.
  • TRIGGER: Allows myuser to create triggers on tables in the database.
  • CREATE: Allows myuser to create new tables and other objects in the database.
  • CONNECT: Allows myuser to connect to the database.
  • TEMPORARY: Allows myuser to create temporary tables and other objects in the database.

For more information about the GRANT command, please refer to the PostgreSQL documentation.

Edit this code on GitHub