• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

PostgreSQL Command: GRANT

January 2, 2024

PostgreSQL Command: GRANT

PostgreSQL is a powerful open-source relational database management system that offers a wide range of features and functionalities. One of the essential commands in PostgreSQL is the GRANT command, which allows users to grant specific privileges to other users or roles within the database.

Understanding the GRANT Command

The GRANT command in PostgreSQL is used to grant privileges on database objects, such as tables, views, functions, and schemas, to other users or roles. Privileges determine what actions a user can perform on a particular object, such as SELECT, INSERT, UPDATE, DELETE, or even the ability to create or drop objects.

The basic syntax of the GRANT command is as follows:

GRANT privilege_type ON object_name TO user_or_role;

Here, privilege_type refers to the specific privilege that you want to grant, such as SELECT, INSERT, UPDATE, DELETE, or ALL. object_name represents the name of the object on which you want to grant the privilege, and user_or_role is the user or role to whom you want to grant the privilege.

Granting Privileges with Examples

Let’s explore some examples to understand how the GRANT command works:

Example 1: Granting SELECT Privilege

To grant the SELECT privilege on a table called “employees” to a user named “john,” you can use the following command:

GRANT SELECT ON employees TO john;

This command allows the user “john” to retrieve data from the “employees” table but does not grant any other privileges.

Example 2: Granting Multiple Privileges

You can grant multiple privileges to a user or role by specifying them in the GRANT command. For example, to grant both SELECT and INSERT privileges on a table called “orders” to a role named “sales,” you can use the following command:

GRANT SELECT, INSERT ON orders TO sales;

This command allows the role “sales” to retrieve data from the “orders” table and also insert new records into it.

Example 3: Granting Privileges on All Tables

If you want to grant privileges on all tables within a schema, you can use the wildcard (*) symbol. For instance, to grant the UPDATE privilege on all tables in the “public” schema to a user named “manager,” you can use the following command:

GRANT UPDATE ON ALL TABLES IN SCHEMA public TO manager;

This command grants the user “manager” the ability to update records in any table within the “public” schema.

Revoking Privileges with the REVOKE Command

In addition to granting privileges, PostgreSQL also provides the REVOKE command to revoke previously granted privileges. The syntax of the REVOKE command is similar to the GRANT command.

For example, to revoke the SELECT privilege on a table called “customers” from a user named “jane,” you can use the following command:

REVOKE SELECT ON customers FROM jane;

This command removes the SELECT privilege from the user “jane” for the “customers” table.

Conclusion

The GRANT command in PostgreSQL is a powerful tool for managing privileges and controlling access to database objects. By granting specific privileges to users or roles, you can ensure that they have the necessary permissions to perform their tasks while maintaining the security and integrity of your database.

For more information about PostgreSQL and its features, you can visit the Server.HK website, a leading VPS hosting company that offers reliable and high-performance hosting solutions.

Recent Posts

  • How to Deploy a Node.js Application on Hong Kong VPS: Complete Guide
  • How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  • How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  • CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  • Top 5 Use Cases for a Hong Kong Dedicated Server in 2026

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot