Skip to content

Instantly share code, notes, and snippets.

@hmasum52
Created May 30, 2022 11:45
Show Gist options
  • Save hmasum52/3613607438527351965cb1391e435274 to your computer and use it in GitHub Desktop.
Save hmasum52/3613607438527351965cb1391e435274 to your computer and use it in GitHub Desktop.

Login in psql

psql -U postgres -h localhost

See list of database

\l 

See list of users with list of roles

\du

Create new user

CREATE USER <username> WITH ENCRYPTED PASSWORD '<password>';

Create new database

CREATE DATABASE <databasename> WITH OWNER <username>;

DELETE database

DROP DATABASE IF EXISTS <databasename>;

GRANT Privilages

GRANT ALL PRIVILAGES ON DATABASE <databasename> TO <username>;

Import a dump file

psql -U username -d database_name -f dump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment