Skip to content

Q&A · Answered

How to create PostgreSQL database and user

asked 9 months, 1 week ago 1936 views 1 answer
2

I need to set up a new PostgreSQL database for my Django project.

1 Answer

One accepted
25

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago
# Login to PostgreSQL
sudo -u postgres psql

# Create database
CREATE DATABASE myproject_db;

# Create user
CREATE USER myproject_user WITH PASSWORD 'secure_password';

# Grant privileges
GRANT ALL PRIVILEGES ON DATABASE myproject_db TO myproject_user;

# For Django
ALTER ROLE myproject_user SET client_encoding TO 'utf8';
ALTER ROLE myproject_user SET default_transaction_isolation TO 'read committed';
ALTER ROLE myproject_user SET timezone TO 'UTC';

\q

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.