PostgreSQL: How to Create User in PostgreSQL
PostgreSQL: How to Create User in PostgreSQL
In PostgreSQL, a user is essentially a role with login privileges. Creating a user allows you to manage access and permissions for your database.
Step-by-Step: Create a PostgreSQL User
Here’s how to create a new user in PostgreSQL:
-- Connect to PostgreSQL CLI (psql)
CREATE USER new_username WITH PASSWORD 'secure_password';
-- To grant login privileges
ALTER USER new_username WITH LOGIN;
You can also grant privileges to the new user as needed:
GRANT ALL PRIVILEGES ON DATABASE your_database TO new_username;
What This Does
- The
CREATE USERstatement defines a new login role. ALTER USER … WITH LOGINensures the account can connect to databases.GRANTassigns permissions on a specific database.
PostgreSQL considers users and roles as part of its access control system. You can tailor permissions for security and functionality. :contentReference[oaicite:0]{index=0}
Comments
Post a Comment