Postgres
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