Snippets / Postgres / Cheat Sheet

Postgres

By Marcelo Fernandes Jul 28, 2017

Shortcuts:

Login
Create an User
Change Password
Create a New Database
Connection Info
Viewing Tables
Drop / Creating Schema
Connecting to the Database
Checking all databases
Checking all schemas
Checking all users

Log in


# Switch over to the postgres account on your server by typing:
sudo -i -u postgres

# Access the prompt
psql

# Quit
\q

Create an User:


# Creating an User
createuser --interactive

Create a New Database


create database marcelo;

Connection info


\conninfo

Viewing Tables


# Option 1 (showing the seq tables)
\d

# Option 2
\dt

Droping/Creating Schema


drop schema public cascade;
create schema public;

Connecting to Database


\connect database_name

Checking all databases


\list
# Or
\l

Checking all Schemas


\dn

Checking all Users


\u

Changing User Password


\password


Notes


Quick commands:

psql