Useful Postgresql Commands

The following are a set of simple commands to configure your PostgreSQL database.    These commands are after you have successfully installed the database application.

Creating a database

To create a database you can use the following. Please note the semicolon at the end 
of each command.

CREATE DATABASE test;

Creating a User

To Create a user, you can use the following command.  In this case a user named "test"
 with password "test" will be created.  Please note that the password must be enclosed 
in single quote and don't forget about the semicolon.

CREATE USER test WITH PASSWORD 'test';

Granting Permissions

A user might need access rights to a given database.  The GRANT command can be used 
to give privileges to a user.  In the following example the user test will be given 
all rights to database test.

GRANT ALL ON DATABASE  test TO test;

Changing the user roles

The ALTER command is used to give a user special a roles such as Superuser.  

ALTER USER test WITH Superuser;

Some useful display commands

To get a listing of all the commands - Help:  \?

To list tables, views, and sequences: \d[S+] 

Similarly, to describe table, view, sequence, or index:  \d[S+]
To show all users (roles) and attributes:  \du To get a listing of all database:  \l

To connect to databases, users, hosts or ports: \c
example: \c test connects to database test created above

 

2,242 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website