Psql Cheatsheet

Published 5 Jun, 2020


Working with PostgreSQL Cheatsheet

Listing general PostgreSQL commands here for my future self.

Start

This is the command I’m using to check if the psql running locally.

/etc/init.d/postgresql status

service postgresql status

Note: I’m using MacOS

Status

To check the status of the postgres services in your machine use this below command.

psql postgres

Create

User

Always create user when you’re working with PostgreSQL instance. It’s okay to create just database and use but using the username and password in the DATABASE_URL is the recommended way.

CREATE USER rajasimon with PASSWORD 'password';

Replace password with your user password.

Database

Creating database is easy with single line comment.

create database dbname

Permission

Assigning permission is really important if you’re working with user and database together.

GRANT ALL PRIVILEGES ON DATABASE "dbname" to rajasimon;

Password

TO change the password please use this command.

\password <password>

Connect

To use the database we must connect with it.

\connect webaccount

I’ve also created the gist for quick glance incase if you want to check my original source.

psql cheatsheet

This article published under development on postgresql tags. Please support me by subscribing to my Newsletter. By subscribing you will not miss any future articles in this category.