DEV Community

Connor Bode
Connor Bode

Posted on

Creating a Postgres database + user

Let's create a new database + a user to access it.

  1. su - postgres to get a shell as the postgres user
  2. psql to get a postgres shell
  3. create database db_name; to create the database
  4. create user user_name with encrypted password 'user_password'; to create the user
  5. grant all privileges on database db_name to user_name; to grant the user all privileges on the database.

That's it really.


As a brief aside, I like to write my SQL in all lowercase. I find it really annoying to use all caps for statements and all lowercase for variables, which seems to be a syntactic standard with no real benefit? Anyone else do this / have a comment on this?


Follow me on dev.to for more code blurbs, or on Twitter @connorbode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay