• 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: CREATE USER

January 2, 2024

PostgreSQL Command: CREATE USER

PostgreSQL is a powerful open-source relational database management system that offers a wide range of features and capabilities. One of the essential commands in PostgreSQL is the CREATE USER command, which allows you to create new users and grant them specific privileges within the database.

Creating a User

To create a new user in PostgreSQL, you can use the CREATE USER command followed by the username and password. Here’s the basic syntax:

CREATE USER username WITH PASSWORD 'password';

For example, to create a user named “john” with the password “secretpassword”, you would run the following command:

CREATE USER john WITH PASSWORD 'secretpassword';

By default, the newly created user will not have any special privileges or roles assigned to them. They will only have the ability to connect to the database.

Granting Privileges

Once you have created a user, you can grant them specific privileges using the GRANT command. Privileges determine what actions a user can perform within the database.

Here’s an example of granting the SELECT privilege on a table to the user “john”:

GRANT SELECT ON table_name TO john;

This command allows the user “john” to retrieve data from the specified table.

In addition to table-level privileges, you can also grant privileges at the database level or even the entire PostgreSQL server level. Some common privileges include INSERT, UPDATE, DELETE, and CREATE.

Modifying User Attributes

PostgreSQL provides several options to modify user attributes using the ALTER USER command. Here are a few examples:

  • Renaming a User: You can change the username using the RENAME TO option.
  • Changing Password: Use the PASSWORD option to set a new password for the user.
  • Setting User Roles: Assign specific roles to the user using the SET ROLE option.

For example, to change the password for the user “john”, you would run the following command:

ALTER USER john WITH PASSWORD 'newpassword';

Deleting a User

If you no longer need a user in PostgreSQL, you can delete them using the DROP USER command. Here’s the syntax:

DROP USER username;

For example, to delete the user “john”, you would run the following command:

DROP USER john;

Be cautious when deleting a user, as it will permanently remove their access and any associated privileges.

Summary

The CREATE USER command in PostgreSQL allows you to create new users and assign specific privileges to them. By using the GRANT command, you can control what actions a user can perform within the database. Additionally, the ALTER USER command enables you to modify user attributes such as username, password, and roles. Finally, the DROP USER command allows you to delete a user when they are no longer needed.

For more information about PostgreSQL and its features, consider exploring Hong Kong VPS Hosting. With their reliable and high-performance VPS solutions, you can leverage the power of PostgreSQL for your database needs.

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