Postgres cheatsheet

Basics Connect as user postgres: 1 psql -U postgres Connect to a specific database: \c database_name; Quit the psql: \q List all databases: \l Lists all tables in the current database: \dt List all users: \du Create a new role username with a password: 1 CREATE ROLE username NOINHERIT LOGIN PASSWORD password; Managing tables Create a new table or a temporary table 1 2 3 4 5 6 7 CREATE [TEMP] TABLE [IF NOT EXISTS] table_name( pk SERIAL PRIMARY KEY, c1 type(size) NOT NULL, c2 type(size) NULL, ....

April 24, 2019 · SergeM