PostgreSQL Common Command You Need to know
Creating user,Creating Database,Giving the user a password & Granting privileges on database
sudo -u postgres psql postgres=# create database mydb; postgres=# create user myuser with encrypted password 'mypass'; postgres=# grant all privileges on database mydb to myuser;
Creating user
$ sudo -u postgres createuser <username>
Creating Database
$ sudo -u postgres createdb <dbname>
Giving the user a password
$ sudo -u postgres psql psql=# alter user <username> with encrypted password '<password>';
Granting privileges on database
psql=# grant all privileges on database <dbname> to <username> ;
Psql commands
psql=# \lList available databases
psql=# \c dbnameSwitch connection to a new database
psql=#\dtList available tables
psql=#\d table_nameDescribe a table such as a column, type, modifiers of columns, etc.
psql=#\dnList all schemes of the currently connected database
psql=#\dfList available functions in the current database
psql=#\dvList available views in the current database
psql=#\duList all users and their assign roles
psql=#\hGet help
psql=#\?Know all available psql commands
psql=#\qExit psql shell
psql=#SELECT version();*Retrieve the current version of PostgreSQL server`
Thank you
Top comments (0)