Postgre SQL Installation In Linux
This tutorial will guide you step by step for the installation of postgres in linux distribution .
InstallationUbuntu's default repositories contain Postgres packages, so we can install them without a hassle using the apt packaging system. Since we haven't updated our local apt repository lately, let's do that now. We can then get the Postgres package and a "contrib" package that adds some additional utilities and functionality:
sudo apt-get update sudo apt-get install postgresql postgresql-contribNow that our software is installed, we can go over how it works and how it may be different from similar database management systems you may have used.
Access PostgreSQL command promptThe installation procedure created a user account called "postgres" that is associated with the default Postgres role. In order to use Postgres, we'll need to log into that account. You can do that by typing:
sudo -u postgres psql postgresTo exit from postgre SQL prompt, type
\qin the psql prompt return back to the Terminal.
Set “postgres” user passwordLogin to postgre sql prompt,
sudo -u postgres psql postgresand set postgres password with following command:
postgres=# \password postgresTo install Postgre SQL Adminpack, enter the command in postgre sql prompt:
postgres=# CREATE EXTENSION adminpack; CREATE EXTENSION
Create New User and DatabaseFor example, let us create a new user called “demo” with password “demo”, and database called “mydb”.
sudo -u postgres createuser -D -A -P demo
sudo -u postgres createdb -O demo mydb
Delete Users and DatabasesTo delete the database, switch to postgres user:
sudo -u postgres psql postgresEnter command:
$ drop database (database-name)To delete a user, enter the following command:
$ drop user (user-name)