Postgres

From I Will Fear No Evil
Revision as of 12:06, 3 April 2024 by Chubbard (talk | contribs) (Created page with "== Postgres Notes == I generally use MySQL, however there have been cases where I need to use Postgres. I can never remember the exact syntax to do basic things, so here we are... === Create User and Database === Admin login to Postgeres (fresh install Pg14) <pre> sudo -u postgres psql postgres </pre> Create User <pre> CREATE ROLE someUser LOGIN PASSWORD 'somePassword'; </pre> Create database and add someUser as the owner <pre> CREATE DATABASE databaseName with owner =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Postgres Notes

I generally use MySQL, however there have been cases where I need to use Postgres. I can never remember the exact syntax to do basic things, so here we are...

Create User and Database

Admin login to Postgeres (fresh install Pg14)

sudo -u postgres psql postgres

Create User

CREATE ROLE someUser LOGIN PASSWORD 'somePassword';

Create database and add someUser as the owner

CREATE DATABASE databaseName with owner = someUser;

Validate that this worked

psql -h localhost -d databaseName -U someUser -p 5432
Password for user someUser: somePassword
psql (14.11 (Ubuntu 14.11-0ubuntu0.22.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

Useful commands to remember

  • \q quit
  • \dt display tables
  • \l list databases

Links

Stack Overflow fresh install notes