Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts

Wednesday 13 July 2016

postgreSQL - PSQL MATA Commands


PSQL META CommandUsage
\dtList the table
\dnList the sachems
\lList the databases
\diList of Indexes
\d <table-name>Describe table(Columns and their type)
\dbList of table spaces(In which places tables are storing)
\duList of users
\dsList of system table
\dvsList of system views
\l+List of databases with size
\dt+List of tables with size
\!present working directory
\dpTable space privileges 
\qQuit from psql shell
select current_userTo view current user
How to switch to database/user?
\c <db> <user>

how to create database outside?
createdb -p 5444 <db-name> -u <user>

Note: we can refer for port in postgres.conf

How to write Query results in to file?

\o <path>
select * from <table-name>;
\o --->switching off

How to importing script?
\i <path of .sql file>

How to print time taken by query?
\timing
-->time take to run particular query
Query
\timtig -->turn off

How to write history of commands into file?
\s <path>

Alternate for \dt+

select pg_relation_size('<table-name>')
    output in bytes

select pg_size_pretty(pg_relation_size('<table-name>'))
    output in MBs or in GB

select pg_size_pretty(pg_database_size('<database-name>'))
    output in MBs or in GB

select pid from pg_stat_activity;

History of PostgreSQL

History of PostgreSQL

The world’s most advanced open source database
Designed for extensibility and customization .
Actively developed for more than 20 years
- University Postgres (1986-1993)
- Postgres95 (1994-1995)
- PostgreSQL (1996-current)

Features of PostgreSQL

Portable:

Written in ANSI C
Supports Windows, Linux, Mac OS/X and major UNIX platforms

Reliable:

  •  ACID Compliant
  •  Supports Transactions
  •  Supports Save points
  •  Uses Write Ahead Logging (WAL)

Secure:

  • Uses Multi-version Concurrency Control
  • Supports Table Partitioning
  • Supports Tablespaces

Recovery and Availability: 

  •  Streaming Replication
  •  Replication Slots
  •  Supports Hot-Backup, pg_basebackup
  •  Point-in-Time Recovery

Advanced:

  • Supports Triggers and Functions
  • Supports Custom Procedural Languages PL/pgSQL, PL/Perl, PL/TCL, PL/PHP, PL/Java - Upgrade using pg_upgrade
  • Unlogged Tables - Materialized Views


Why postgresSQL?

Why postgresSQL?


PostgreSQL is capable of processing big data and which has better capabilities as follows.

LimitValue
Maximum Database SizeUnlimited
Maximum Table Size32 TB
Maximum Row Size1.6 TB
Maximum Field Size1 GB
Maximum Rows per Table Unlimited
Maximum Columns per Table250-1600 (Depending on Column types)
Maximum Indexes per Table?Unlimited

what is postgreSQL

What is postgreSQL?


PostgreSQL is a Relational Database Management System(RDBMS) is a named collection of SQL objects. It is a collection of schemas and the schemas contain the tables, functions, etc.
  • Databases are created with the CREATE DATABASE command and
  • Databases are destroyed with the DROP DATABASE command.
To determine the set of existing databases:
-SQL: SELECT datname FROM pg_database;
Above command will list all the databases
-psql META COMMAND: \l(backslash lowercase L)
Using \l also we can list all the databases