A Postgres user is an account that connects a person or an application to your PostgreSQL database. Each user has its own password and privileges, so every account you create decides who can reach your data.
This guide shows you how to create a user, grant the right access, list who has access today and audit it on a schedule. In PostgreSQL, users and groups are both roles, and CREATE USER is shorthand for CREATE ROLE with the LOGIN attribute.
Open a terminal and connect to the server:
psql -U your_admin_username -d your_database_name -h your_host
Replace your admin username, your database name and your host with your values. If the server doesn't use the default port, add -p and the port number.
Create the account, then set its password with the psql/password command:
CREATE USER your_new_username;
/password your-new-username
Don't type the password into a CREATE USER statement. It can land in your shell or psql history, in pg_stat activity while the statement runs and in the server logs. The /password command hashes it in your client before it reaches the server.
Check that password_encryption is set to scram-sha-256, which PostgreSQL 14 and later use by default. MD5 is weaker and deprecated.
Grant superuser only when the account can't work without it. A superuser bypasses every permission check:
ALTER USER your_new_username WITH SUPERUSER;
Start with connection and read access. Add privileges as the user needs them:
GRANT CONNECT ON DATABASE your_database_name TO your_new_username;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO your_new_username;
Avoid GRANT ALL PRIVILEGES. It gives the user more access than most accounts need.
Confirm the account exists:
SELECT * FROM pg_user WHERE username = 'your_new_username''
This command will display the details of the newly created customer.
Roles let you manage access once for many users. Create a group role, give it privileges and add users to it:
CREATE ROLE sales_team;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO sales_team;
GRANT sales_team TO sales_example_user;
This creates a role named sales_team, grants it read access and adds sales_example_user as a member. When the team's access changes, you change one role instead of every account. Build one role per project or business unit to match how your organization works.
Row-level security (RLS) limits which rows a user can see. This example lets each manager read only their own accounts:
CREATE TABLE accounts (manager text, company text, contact_email text);
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
GRANT SELECT ON accounts TO managers;
CREATE POLICY account_managers ON accounts TO managers USING (manager = current_user);
Users in the managers role can query accounts, but the policy returns only rows where the manager column matches their username.
Review who has access before you change it. Run \du in psql to list every role, or \du+ to add descriptions. For a filtered view, query the catalog:
SELECT rolname, rolsuper, rolcreaterole, rolcreatedb, rolcanlogin FROM pg_roles WHERE rolcanlogin = true;
This returns every role that can log in. The rolsuper column flags superusers, and rolcreaterole and rolcreatedb flag roles that can create other roles and databases. Then check what each user can do. Table, schema and database privileges each have a psql command:
\dp
\dn+
\l
To see group membership and inherited access, join the role tables:
SELECT r.rolname AS group_role, m.rolname AS member FROM pg_auth_members a JOIN pg_roles r ON r.oid = a.roleid JOIN pg_roles m ON m.oid = a.member;
Prefer a GUI? pgAdmin, DBeaver and DataGrip all list roles in their object browsers.
Remove privileges when a user's job changes:
REVOKE SELECT ON ALL TABLES IN SCHEMA public FROM your_new_username;
DROP ROLE fails while the user still owns objects. Reassign them, remove the user's remaining privileges, then drop the role. Run the first two statements in every database where the user owns objects:
REASSIGN OWNED BY your_new_username TO new_owner;
DROP OWNED BY your_new_username;
DROP ROLE your_new_username;
Access drifts. People change teams, contractors leave and service accounts pile up. Run the role and privilege checks above on a recurring schedule, compare the results with who should have access and revoke the rest. Keep each report. It's the evidence your auditor asks for.
Turn on logging so you can see what happens between reviews:
ALTER SYSTEM SET log_connections = on;
ALTER SYSTEM SET log_disconnections = on;
ALTER SYSTEM SET log_statement = 'ddl';
SELECT pg_reload_conf();
For statement-level detail, install the pgAudit extension. Add pgaudit to shared_preload_libraries, restart PostgreSQL and enable it:
CREATE EXTENSION pgaudit;
ALTER SYSTEM SET pgaudit.log = 'role, ddl';
SELECT pg_reload_conf();
Use pg_stat_statements to spot unusual query patterns. PostgreSQL doesn't enforce password complexity by default, so add the passwordcheck module or generate passwords outside the database.
Native PostgreSQL commands manage roles. They don't manage the passwords behind them, and those passwords tend to end up in scripts, tickets and chat threads.
Delinea Secret Server stores database credentials in a vault, rotates them and records each check-out, so you know who used an account and when. Delinea database access brings user management and audit logging for PostgreSQL and other databases into one place, so you can review access in a single view instead of running catalog queries server by server.
Try a demo today to enhance your PostgreSQL access security and simplify multiple-platform database access management.