Postgres: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
(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 =...")
 
Line 32: Line 32:
[https://stackoverflow.com/questions/2172569/how-to-login-and-authenticate-to-postgresql-after-a-fresh-install| Stack Overflow fresh install notes]
[https://stackoverflow.com/questions/2172569/how-to-login-and-authenticate-to-postgresql-after-a-fresh-install| Stack Overflow fresh install notes]


[https://serverfault.com/questions/198002/postgresql-what-does-grant-all-privileges-on-database-do| Server Fault Grants and permissions information]





Revision as of 12:08, 3 April 2024

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

Server Fault Grants and permissions information