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 for more code blurbs, or on Twitter @connorbode

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git