Skip to content

Instantly share code, notes, and snippets.

@jayliew
Last active June 18, 2024 19:45
Show Gist options
  • Save jayliew/9612d025e36f628ab9abfd4fa1fa397a to your computer and use it in GitHub Desktop.
Save jayliew/9612d025e36f628ab9abfd4fa1fa397a to your computer and use it in GitHub Desktop.
postgres cheat / psql cheat

create user: CREATE ROLE username WITH LOGIN PASSWORD 'password';

show users: \du

create database: CREATE DATABASE databasename;

show databases: \l

use a specific db: \c dbnamehere;

give user permissions: GRANT ALL PRIVILEGES ON DATABASE super_awesome_database TO johndoe;

give user ownership of db: ALTER DATABASE db_name OWNER TO new_owner_username;

change table owner: ALTER TABLE <tablename> OWNER TO <username>

show tables: \dt

describe table: \d <table name>

insert (use single quote for strings):

insert into mm_thoughts_contexts (t_id, mm_id) VALUES
(41, 289),
(5, 289),
(35, 289);
@jayliew
Copy link
Author

jayliew commented Jun 11, 2024

limited dev user. only permission to connect and do CRUD

GRANT CONNECT
ON database next13dbdev TO limiteddevuser;

GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO limiteddevuser;

GRANT USAGE ON SEQUENCE tablenamehere TO limiteddevuser;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment