psql -d postgres -c "CREATE USER app WITH PASSWORD 'secret';"

Category: Databases & SQL

psql -d postgres -c "CREATE USER app WITH PASSWORD 'secret';"

Create a login role with a password

Creates a login-capable role, the PostgreSQL term for a user, with the given password, stored hashed in pg_authid. Prefer a long random secret over demo values. sudo -u postgres createuser -P app does the same from the shell.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.