Create Database:
-> A database is a named collection of SQL objects (“database objects”). Generally, every database object (tables, functions, etc.) belongs to one and only one database.
-> The full hierarchy is: server, database, schema, table (or some other kind of object, such as a function).
Syntax:/usr/local/pgsql/bin/createdb sandbox_db -p 5435
Connect to Database:
cmd:/usr/local/pgsql/bin/psql sandbox_db -p 5435
To list all the available databes:
cmd:select datname from pg_database;
Create Schema:
-> Schemas are a purely logical structure and who can access what is managed by the privilege system.
cmd:create schema dev_schema;
Set Search Path:
-> It is used to group the tables in the particular schema and while looking for the object first search in the schema if the object is not available then error is reported.
-> By default all the tables are under public schema.
-> To see the current search path use the cmd.
cmd:show search_path;
-> To set the deatch path
cmd:set search_path=’dev_schema’;
Drop Database:
-> If the databse is not needed then we can remove the database to free the space.
cmd:drop database test_db;
Tablespace:
-> It allows database administrators to define locations in the file system where the files representing database objects can be stored.
USES:
1. If the partition or volume on which the cluster was initialized runs out of space and cannot be extended, a tablespace can be created on a different partition and used until the system can be reconfigured.
2. To optimize performance by the following
-> An index which is very heavily used can be placed on a very fast, highly available disk, such as an expensive solid state device.
-> At the same time a table storing archived data which is rarely used or not performance critical could be stored on a less expensive, slower disk system.
Syntax:CREATE TABLESPACE fastspace LOCATION ‘/DB/postgresql/data’;
-> To see the available tablespaces
cmd:select spcname from pg_tablespace;
-> To set the default table space
cmd:SET default_tablespace = space1;
-> To create the table in specified tablespace
cmd:CREATE TABLE test(no varchar,name varchar) TABLESPACE fastspace;