SlideShare a Scribd company logo
1 of 85
PostgreSQL



                By
         OpenGurukul.com
Free/Open Source Software Laboratory
PostgreSQL




Module : PostgreSQL Setup




        www.opengurukul.com   2
PostgreSQL Setup : Manuals
PostgreSQL Manuals : all versions
   http://www.postgresql.org/docs/manuals/
For PostgreSQL 9.1 - with user comments
   http://www.postgresql.org/docs/9.1/interactive/index.html
For PostgreSQL 9.1 - without user comments
   http://www.postgresql.org/docs/9.1/static/index.html




                          www.opengurukul.com                  3
PostgreSQL Setup : Install
Install PostgreSQL
  yum install postgresql
  yum install postgresql-server
  yum install postgresql-libs
Install pgadmin tool
  yum install pgadmin3




                       www.opengurukul.com   4
PostgreSQL Setup : Version
The postgres server version can be found by
 using --version on the postmaster




$ postmaster --version
postgres (PostgreSQL) 8.4.5
$

                   www.opengurukul.com        5
PostgreSQL




Module : pg_ctl : Control PostgreSQL Server




                 www.opengurukul.com          6
pg_ctl
The pg_ctl utility is used to
Initialize PostgreSQL database cluster
Start PostgreSQL database server
Stop PostgreSQL database server
Restart PostgreSQL database server
Display status of a running PostgreSQL database
 server


                     www.opengurukul.com      7
pg_ctl : PGDATA variable
The pg_ctl commands are dependent on the
 PGDATA variable that contains directory
 location of database cluster.
The PGDATA directory location can be specified
 using -D in case PGDATA environment
 variable is not set.
Generally, we switch to “postgres” user in case
 the database cluster was created by “postgres”
 user.

                   www.opengurukul.com            8
pg_lsclusters : Location of
    Database Clusters : Ubuntu
pg_lsclusters :
$ pg_lsclusters # to clusters and data directory




                    www.opengurukul.com            9
pg_ctl : Control PostgreSQL
                  Server
Start Server :                              Stop Server :
$ pg_ctl start                              $ pg_ctl stop
server starting                             waiting for server to shut down....
                                              done
$
                                            server stopped
                                            $
Restart Server :                            Server Status :
$ pg_ctl restart                            $ pg_ctl status
waiting for server to shut down....         pg_ctl: server is running (PID: 8384)
  done
                                            /usr/bin/postgres
server stopped
                                            $
server starting
                                 www.opengurukul.com                                10
$
PostgreSQL




Module : PostgreSQL Admin Tools




           www.opengurukul.com    11
PhpPgAdmin : Download & Install
Download phpPgAdmin from
  http://sourceforge.net/projects/phppgadmin/
Install phpPgAdmin using
  yum install phpPgAdmin




                     www.opengurukul.com        12
PhpPgAdmin : phppgadmin
/etc/apache2/conf.d/phppgadmin
  Uncomment # allow from all




                    www.opengurukul.com   13
PhpPgAdmin : Configure
/usr/share/phpPgAdmin/conf/config.inc.php :
Modify extra_login_security to false in
 /usr/share/phpPgAdmin/conf/config.inc.php
If extra login security is true, then logins via phpPgAdmin
   with no password or certain usernames (pgsql, postgres,
   root, administrator) will be denied.
Set this to FALSE to access it using postgres etc.
Its default value is true.
   // $conf['extra_login_security'] = true;
Set it to false
   $conf['extra_login_security'] = false;
                        www.opengurukul.com                   14
PhpPgAdmin : Configure
pg_hba.conf :
Modify /var/lib/pgsql/data/pg_hba.conf file to change the method to "trust" from
  "ident".
New Settings:
   local all      all                     trust
Old Settings:
   #local all      all                    ident
Restart :
Apache Web Server
Restart PostgreSQL Server



                                www.opengurukul.com                            15
PgAdmin: Download & Install
Download & Install pgadmin3 from
 www.pgadmin.org
  pgadmin3-1.12.2-2.fc14.i686
  rpm -i pgadmin3-1.12.2-2.fc14.i686
Directly Install pgadmin3
  yum install pgadmin3
Invoke pgadmin3
  $ pgadmin3
                   www.opengurukul.com   16
PgAdmin: Configure
1> pg_hba.conf : edit pg_hba.conf file (use trust) otherwise you
  wiill not be able to connect
# TYPE DATABASE        USER             CIDR-ADDRESS
  METHOD
host   all    all     127.0.0.1/32            trust
host   all    all     ::1/128                 trust
2> restart PostgresSQL Server
3> Configure a Server using PgAdmin3
Host localhost, Port 5432
user – postgres, password - postgres
service – postgresql, database - postgres, edb etc.
                            www.opengurukul.com                    17

4> The configuration can be checked in postgresql.conf
PostgreSQL




       psql




  www.opengurukul.com   18
psql : PGDATA
$ su - postgres
$ pwd
/var/lib/pgsql
$
$ echo $PGDATA
/var/lib/pgsql/data
$

                      www.opengurukul.com   19
psql : command line
$ psql -U<user_name> -d<db_name>
<DB_NAME>=# help
You are using psql, the command-line interface to PostgreSQL.
Type: copyright for distribution terms
h for help with SQL commands
? for help with psql commands
g or terminate with semicolon to execute query
q to quit
<DB_NAME>=# q
$
                           www.opengurukul.com                  20
psql : default database
NOTE :
The default database is postgres.


Example : Default connect to postgres
$ psql
psql (8.4.5)
Type "help" for help.
postgres=# q
$
                        www.opengurukul.com   21
psql : -d : connect to database
Example : Connect to template1


$ psql -dtemplate1
psql (8.4.5)
Type "help" for help.
template1=# q
$




                        www.opengurukul.com   22
psql : s : display history or save
                history
Syntax :
s [FILE]       display history or save it to file




Example : will list history of commands executed.
postgres-# s




                        www.opengurukul.com          23
psql : i : execute commands from
                  file
Syntax :
i FILE             execute commands from file


Example :
$ cat /tmp/in.sql
l
$
postgres=# i /tmp/in.sql
...will give a list of databases ...
postgres=#
                             www.opengurukul.com   24
psql : o : send all query results to
                 file
Syntax :
o [FILE]            send all query results to file or |pipe


Example :
postgres=# o /tmp/out.txt l


Output :
$ cat /tmp/out.txt
will have list of databases
$
                               www.opengurukul.com             25
psql : ! : execute command in
                  shell
Syntax :
! [COMMAND]       execute command in shell or
                   start interactive shell
Example :
postgres-# ! sh
sh-4.1$ pwd
/var/lib/pgsql
sh-4.1$ exit
exit
postgres-#         www.opengurukul.com           26
psql : internal variables
Syntax :
prompt [TEXT] NAME   prompt user to set internal
                      variable
set [NAME [VALUE]]   set internal variable, or list all if
                      no parameters
unset NAME           unset (delete) internal variable




                      www.opengurukul.com                     27
psql : Display Internal Variables
postgres-# set
AUTOCOMMIT = 'on'
PROMPT1 = '%/%R%# '
PROMPT2 = '%/%R%# '
PROMPT3 = '>> '
VERBOSITY = 'default'
VERSION = 'PostgreSQL 8.4.5 on i386-redhat-linux-gnu, compiled by GCC gcc
  (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4), 32-bit'
DBNAME = 'postgres'
USER = 'postgres'
PORT = '5432'
ENCODING = 'UTF8'
                             www.opengurukul.com                       28
postgres-#
psql : set variables : Example
postgres-# prompt 'name: ' SITE
name: www.opengurukul.com
postgres-# set
...
SITE = 'www.opengurukul.com'
postgres-#



                   www.opengurukul.com   29
psql : prompt
The psql prompt will be
databasename=# for database super user
databasename=> for users without super user
 privileges.


NOTE :
Whichever user has done initdb will have DB
 super user privileges or if added otherwise.

                   www.opengurukul.com          30
PostgreSQL




PostgreSQL Introduction




       www.opengurukul.com   31
Introduction : postgres
To start PostgreSQL server, you can directly use
  /usr/bin/postgres


$ /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
-D : pgdata directory
-p : port




                        www.opengurukul.com          32
Introduction : postmaster
The postmaster is an alias for PostgreSQL Database Server.
$ which postmaster
/usr/bin/postmaster
$
$ ls -l /usr/bin/postmaster
lrwxrwxrwx. 1 root root 8 Jan 27 2011 /usr/bin/postmaster ->
   postgres
$




                              www.opengurukul.com              33
Introduction : Initialize database
          cluster : initdb
The initdb command is used to initalize a database
  cluster.
A database cluster consists of a data directory that can
  have multiple databases served be a postgres
  instance.
The initdb creates the directories in which the database
  data will live.
The initdb generates the shared catalog tables (tables
  that belong to the whole cluster rather than to any
  particular database).
The initdb creates two databases :
                       www.opengurukul.com                 34
 template1 and postgres
Introduction: initdb : template1
Whenever you create a new database in the
 cluster, everything in the template1 database is
 copied.
We should install only those things in template1
 that we would like to copy to other databases.




                    www.opengurukul.com            35
Introduction: initdb : example
Syntax :
$ initdb --pgdata | -D pgdata_directory
Generally, The default pgdata directory is /var/lib/pgsql/data.
If you don't specify any pgdata directory, it will be picked up from
   PGDATA environment variable


Example : Create a D/B cluster data1 in home directory
$ initdb -D ~/data1
$


                            www.opengurukul.com                        36
Introduction: start d/b cluster
Export PGDATA
   $ export PGDATA=~/data1
Modify the port in ~/data1/postgresql.conf to 5433.
   $ export PGPORT=5433 # export port
Add user (the one who did initdb) to group “postgres” in /etc/group
  file to allow writing to /var/run/postgres/
Start D/B
   pg_ctl start
Invoke psql with new port
   psql -p <new port> -d postgres

                            www.opengurukul.com                   37
Introduction : Create Database :
             createdb
The createdb (executable) or
  "CREATE DATABASE" (psql
                                  # from psql prompt
  command) is used to create
  database on PostgreSQL.         CREATE DATABASE name;




                                  # from shell command line
                                  createdb name;



                       www.opengurukul.com                    38
Introduction : Create Database :
          createdb : Example
$ su - postgres
$ createdb x


Example :
postgres=# CREATE DATABASE sample;
CREATE DATABASE
postgres=# l
    [List of databases]
Postgres=# q
                          www.opengurukul.com   39
$
Introduction : Delete Database :
              dropdb
The dropdb command can be used to delete the
  PostgreSQL database.


Syntax :
$ dropdb <dbname>




                    www.opengurukul.com        40
Introduction : Connect to
                database
c[onnect] [DBNAME|- USER|- HOST|- PORT|-]
connect to new database (currently "postgres")


Example :
postgres-# c sample
psql (8.4.5)
You are now connected to database "sample".
sample-#

                       www.opengurukul.com       41
Introduction : psql : S, +
Informational
(options: S = show system objects, + = additional detail)
d[S+]           list tables, views, and sequences
NOTE: dS+ shows size also
For postgrres, we must specify "S" otherwise objects will not
  be shown.
Example :
postgres-# dS
 [List of relations]
 ......
                         www.opengurukul.com                42
Introduction : psql : d : Describe
                  Table
postgres=# dS pg_roles

             View "pg_catalog.pg_roles"

+---------------+--------------------------+-----------+

|   Column       |         Type           | Modifiers |

+---------------+--------------------------+-----------+

| rolname        | name                      |               |

| rolsuper      | boolean                    |               |

| rolinherit   | boolean                 |               |

| rolcreaterole | boolean                        |               |

| rolcreatedb | boolean                          |               |

| rolcatupdate | boolean                             |               |

| rolcanlogin | boolean                          |               |

| rolconnlimit | integer                  |              |

| rolpassword | text                      |              |
                                                                         www.opengurukul.com   43
| rolvaliduntil | timestamp with time zone |                               |
Introduction : vacuumdb : garbage-
            collect database
The vacuumdb is a utility for cleaning a
 PostgreSQL database.
VACUUM reclaims storage occupied by dead
 tuples.
In normal PostgreSQL operation, tuples that are
  deleted or obsoleted by an update are not
  physically removed from their table; they
  remain present until a VACUUM is done.
It is necessary to do VACUUM periodically,
   especially on frequently-updated tables.
                    www.opengurukul.com           44
Introduction : vacuumdb : options
--full : Perform full vaccuming
--dbname <dbname> : name of the pariculat database
  to be cleaned or analyzed
--table table [ (column [,...]) ] : table to be cleaned.
   columns can also be specified.
--all : Vacuum all databases
--analyze : Calculate statistics for use by the optimizer
--verbose : verbose display


                         www.opengurukul.com                45
Introduction : vacuumdb : Example

Example :


-bash-4.1$ vacuumdb --full --all --analyze
vacuumdb: vacuuming database "postgres"
vacuumdb: vacuuming database "template1"
-bash-4.1$



                    www.opengurukul.com      46
PostgreSQL




pg_dump : Backup & Resotre




        www.opengurukul.com   47
pg_dump : plain dump : script file
The pg_dump command is used to extract a
  PostgreSQL database into a .sql script file.
Syntax :
pg_dump database_name > database.sql




                       www.opengurukul.com       48
pg_dump : plain dump : usage
To dump a database called "mydb" into a SQL-
 script file:
  $ pg_dump mydb > db.sql
To reload such a script into a (freshly created)
 database named "newdb".
  $ psql -d newdb -f db.sql




                    www.opengurukul.com            49
pg_dump : table
To dump specific tables, specify them after -t
To skip specific tables, specify them after -T
Both -t and -T supports regular expression.
Example :
$ pg_dump -t 'mytab1_*' -T 'mytab2_*' mydb > db.sql




                       www.opengurukul.com        50
pg_dump : archive file
To dump a database into a custom-format archive file:
$ pg_dump -Fc mydb > db.dump
To reload an archive file into a (freshly created)
  database named newdb :
$ pg_restore -d newdb db.dump
The default dump format is plain (p) script file that is
  specified using -Fp.




                        www.opengurukul.com                51
PostgreSQL




Users & Privileges




    www.opengurukul.com   52
createuser : create user account
To create a user account (also called role),
 createuser command is used.
Only superusers and users with CREATEROLE
 privilege can create new users.
You can also use "CREATE ROLE" to achieve it.




                    www.opengurukul.com        53
createuser : create user account :
              example
Example :
To create a user matsya1 on the default database
  server:
$ createuser matsya1
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases?
 (y/n) n
Shall the new role be allowed to create more new roles?
 (y/n) n

                       www.opengurukul.com           54
dropuser - remove user account
The dropuser is used to remove an existing
 PostgreSQL user.
Only superusers and users with the
 CREATEROLE privilege can remove
 PostgreSQL users.
You can also use "DROP ROLE <rolename>" to
 achieve it.



                  www.opengurukul.com        55
dropuser - remove user account :
             example
Example :
To remove user matsya1 from the default database
  server:
$ dropuser matsya1




                     www.opengurukul.com           56
list users : du
You can use psql command du to see the users (also called roles).
Example :
List Users / Roles
postgres=> du
         List of roles
Role name | Attributes | Member of
-----------+-------------+-----------
postgres | Superuser | {}
        : Create role
        : Create DB
surikuma | Create role | {}
        : Create DB
                                        www.opengurukul.com          57
postgres=>
list users : pg_roles
The users (also called roles) are present in pg_roles. We can also
  check rolename in pg_roles.
Example :
Users/Roles from pg_roles
postgres=# select rolname from pg_roles;
rolname
----------
postgres
surikuma
(2 rows)
postgres=#                www.opengurukul.com                    58
Role Membership : Grant & Revoke
A group role is created using "CREATE ROLE" command.
This role will also represent a group.
A group role (priviliges) will not have LOGIN attribute generally but
  it is not mandatory.
Syntax:
GRANT <group role> to <user role>;
GRANT <group role> from <user role>;




                           www.opengurukul.com                     59
Role Membership : Grant & Revoke :
            Example
Example :
create a group role and assign priviliges to a user
CREATE ROLE admin NOINHERIT;
CREATE ROLE guru LOGIN INHERIT;
GRANT admin TO guru;




                       www.opengurukul.com            60
PostgreSQL




  PL/pgSQL




  www.opengurukul.com   61
createlang : add procedural
              language
The createlang is used to add a support of a procedural
  language in the database.


Syntax :
$ createlang plpgsql
$ createlang plperl




                       www.opengurukul.com                62
createlang : list procedural
               languages
$ createlang --list
Procedural Languages
    Name | Trusted?
---------+----------
plpgsql | yes
plperl | yes


$

                       www.opengurukul.com   63
pg_language : list procedural
               languages :
postgres=# select * from pg_language;
+------------+--------------+---------+---------------+-----------------+----------------+--------+
| lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl |
+------------+-------------+---------+----------------+-----------------+---------------+---------+
| internal |       10      |f        |f               |           0     |       2246 |                |
|c           |     10      |f        |f                |          0     |       2247 |                |
| sql        |     10      |f        |t               |           0     |       2248 |               |
| plpgsql |        10     |t         |t               |       16810 |         16811 |                |
+-----------+-------------+---------+----------------+----------------+----------------+---------+
(4 rows)
postgres=#
                                            www.opengurukul.com                                           64
PL/pgSQL : Structure
PL/pgSQL is a block-structured language.
PL/pgSQL Block Structure
[ <<label>> ]
[ DECLARE
  declarations ]
BEGIN
  statements
END [ label ];

                     www.opengurukul.com   65
PL/pgSQL : Data Types
Frequently used data type are
integer - for numbers
varchar - for variable length character array
char - for fixed length character array
date - for calendar date (year, month, day)
time - for time of day
timestamp - for date & time
The data types table is present on
http://www.postgresql.org/docs/9.1/interactive/datatype.html
                          www.opengurukul.com                  66
PL/pgSQL : Variable Declarations
PL/pgSQL variables can              Examples :
  have any SQL data type,
                                    user_id integer;
  such as integer, varchar,
  a
  and char.                         quantity numeric(5);
The variable name is                url varchar;
  specified first and data          myrow tablename
  type is specified next.            %ROWTYPE;
                                    myfield
                                     tablename.columnname
                                     %TYPE;


                         www.opengurukul.com                67
PL/pgSQL : Variable Assignment
In PL/pgSQL the              Example :
  assignment operator        x := 20;
  is :=




                  www.opengurukul.com    68
PL/pgSQL : RAISE : Report
             Messages
The RAISE can be used to report messages on PL/pgSQL.
Syntax:
RAISE LEVEL 'format' [,expression [, ...]] ;
Possible levels are DEBUG, LOG, INFO, NOTICE, WARNING,
  and EXCEPTION.
EXCEPTION raises an error.
Inside the format string, % is replaced by the next optional
  argument's string representation
Example :
RAISE NOTICE 'Calling cs_create_job(%)', v_job_id;

                           www.opengurukul.com                 69
PL/pgSQL : Create or Replace Function

The CREATE OR REPLACE FUNCTION call is
 used to create (replace) a function.




               www.opengurukul.com       70
PL/pgSQL : Create or Replace Function
             : Example
$ cat add.sql                              $ psql
create or replace function                 postgres=#i add.sql
add(x integer, y integer)                  CREATE FUNCTION
returns integer AS $$                      postgres=#q
declare                                    $
  total integer;
begin
          total := x + y +z ;
        RETURN total;
end;
$$
language plpgsql;               www.opengurukul.com               71
PL/pgSQL : List of Functions: df
To get List of Functions use df
Syntax :
    df [PATTERN]
Example : Get list of functions using df
postgres=# df
                        List of functions
+--------+--------+------------------+---------------------------------+--------+
| Schema | Name | Result data type | Argument data types | Type |
+--------+--------+------------------+---------------------------------+--------+
| public | add     | integer        | x integer, y integer             | normal |
+--------+--------+------------------+---------------------------------+--------+
(1 rows)                               www.opengurukul.com                          72
PL/pgSQL : Call Function
Use select to call the              Example :
  function.
                                    postgres=# select
select funcname(funcargs);            add(1,2);
                                    sum
                                    -----
                                    3
                                    (1 row)
                                    postgres=#


                         www.opengurukul.com            73
PL/pgSQL : Drop Function
Use DROP FUNCTION to drop a function.


Example :
postgres=# drop function sum(integer, integer);
DROP FUNCTION
postgres=#


NOTE :
The drop function must be called with argument types otherwise it
  will not work.
                          www.opengurukul.com                   74
PL/pgSQL : Develop Function :
                 Example 2
$ cat msg.sql
create or replace function msg()
RETURNS INTEGER
AS
$$
begin
       RAISE NOTICE 'hello world';
       RETURN 0;
end;
$$
language plpgsql;            www.opengurukul.com   75

$
PL/pgSQL : Create Function : Example
                 2

postgres=# i msg.sql
CREATE FUNCTION
postgres=#




                  www.opengurukul.com   76
PL/pgSQL : List Function : Example 2
List Function :
postgres=# df msg
                    List of functions
+-----------+---------+---------------------+-----------------------------+-----------+
| Schema | Name | Result data type | Argument data types | Type |
+-----------+---------+----------------------+-----------------------------+----------+
| public    | msg      | integer             |                             | normal |
+-----------+---------+----------------------+-----------------------------+-----------+
(1 row)
postgres=#

                                    www.opengurukul.com                                    77
PL/pgSQL : Call Function : Example 2
Call Function :
postgres=# select msg();
NOTICE: hello world
msg
-----
  0
(1 row)
postgres=#

                      www.opengurukul.com   78
PL/pgSQL : Drop Function : Example 2

Drop Function :


postgres=# drop function msg();
DROP FUNCTION
postgres=




                   www.opengurukul.com   79
PostgreSQL




 Transactions




  www.opengurukul.com   80
Transactions
Transactions are a fundamental concept of all database
  systems.
A transaction bundles multiple steps into a single, all-or-
  nothing operation.
The intermediate states between the steps are not
  visible to other concurrent transactions.
If some failure occurs that prevents the transaction from
   completing, then none of the steps affect the database
   at all.
A transaction is said to be atomic: from the point of view
  of other transactions, it either happens completely or
  not at all.           www.opengurukul.com               81
Transactions : Savepoint &
              Rollback
Create a savepoint
  SAVEPOINT [<savepoint_name>];
Rollback to a savepoint
  ROLLBACK [to <savepoint_name>];
Commit the changes
  COMMIT;




                      www.opengurukul.com   82
Transactions : Savepoint &
           Rollback : Example
Take a case of Bank Database, suppose we debit $100.00 fro Ram's account, and credit
  Laxman's account, only to find later that we should have credited Sita's account
BEGIN
  UPDATE accounts SET balance = balance - 100.00 WHERE name = 'Ram';
   SAVEPOINT my_savepoint;
   UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Laxman';
   -- oops ... forget that and use Sita's account
   ROLLBACK TO my_savepoint;
   UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Sita';
   COMMIT;
END;


                                     www.opengurukul.com                          83
PostgreSQL




   Thanks




  www.opengurukul.com   84
Thanks

       Thanks for attending the session.


For additional support, please post your query on
          PostgreSQL discussion forum at


             www.opengurukul.com


                   www.opengurukul.com          85

More Related Content

What's hot

MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestI Goo Lee
 
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.NAVER D2
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PGPgDay.Seoul
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesJonathan Katz
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3PoguttuezhiniVP
 
MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바NeoClova
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스PgDay.Seoul
 
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe Pereira
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe PereiraPgBouncer: Pool, Segurança e Disaster Recovery | Felipe Pereira
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe PereiraPGDay Campinas
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep InternalEXEM
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlMydbops
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanGabriele Bartolini
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxNeoClova
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres MonitoringDenish Patel
 
MySQL 8.0 achitecture and enhancement
MySQL 8.0 achitecture and enhancementMySQL 8.0 achitecture and enhancement
MySQL 8.0 achitecture and enhancementlalit choudhary
 
Get Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAMGet Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAMJonathan Katz
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsCommand Prompt., Inc
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenPostgresOpen
 

What's hot (20)

MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling StrategiesWebscale PostgreSQL - JSONB and Horizontal Scaling Strategies
Webscale PostgreSQL - JSONB and Horizontal Scaling Strategies
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe Pereira
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe PereiraPgBouncer: Pool, Segurança e Disaster Recovery | Felipe Pereira
PgBouncer: Pool, Segurança e Disaster Recovery | Felipe Pereira
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in Postgresql
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with Barman
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptx
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
 
MySQL 8.0 achitecture and enhancement
MySQL 8.0 achitecture and enhancementMySQL 8.0 achitecture and enhancement
MySQL 8.0 achitecture and enhancement
 
Get Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAMGet Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAM
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 

Viewers also liked

OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpen Gurukul
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
064 و تكونون لي شهوداً القس كرم لامعى
064 و تكونون لي شهوداً  القس كرم لامعى064 و تكونون لي شهوداً  القس كرم لامعى
064 و تكونون لي شهوداً القس كرم لامعىIbrahimia Church Ftriends
 
Sådan får du succes som hjertearbejder i 5 enkle trin
Sådan får du succes som hjertearbejder i 5 enkle trinSådan får du succes som hjertearbejder i 5 enkle trin
Sådan får du succes som hjertearbejder i 5 enkle trinBetinna Larsen
 
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...Instant GMP Compliance Series -Better Compliance through Master Manufacturing...
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...InstantGMP™
 
Boomers Cafe - MKT412
Boomers Cafe - MKT412Boomers Cafe - MKT412
Boomers Cafe - MKT412MNSXPRESS
 
Game wardenpowerpoint2
Game wardenpowerpoint2Game wardenpowerpoint2
Game wardenpowerpoint2TravisCramp
 
Sin With Sebastian introduction
Sin With Sebastian introductionSin With Sebastian introduction
Sin With Sebastian introductionClaudiaVonSinner
 
Building a mobile website
Building a mobile websiteBuilding a mobile website
Building a mobile websiteli_gordon
 
Senior project speech
Senior project speechSenior project speech
Senior project speechlukas115
 
Mgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeMgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeRohit Mishra
 
Little league: Professional Development Presentation
Little league: Professional Development PresentationLittle league: Professional Development Presentation
Little league: Professional Development PresentationCory Massei
 
Pc hardware overview part 2
Pc hardware overview  part 2Pc hardware overview  part 2
Pc hardware overview part 2Duy Hieu
 
2011 0125 platt uscc_model_state_policies
2011 0125 platt uscc_model_state_policies2011 0125 platt uscc_model_state_policies
2011 0125 platt uscc_model_state_policiesspickell
 
realestate and MySQL devops melbourne
realestate and MySQL devops melbournerealestate and MySQL devops melbourne
realestate and MySQL devops melbournemysqldbahelp
 

Viewers also liked (20)

OpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell ScriptingOpenGurukul : Language : Shell Scripting
OpenGurukul : Language : Shell Scripting
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
انجيل يوحنا
انجيل يوحناانجيل يوحنا
انجيل يوحنا
 
064 و تكونون لي شهوداً القس كرم لامعى
064 و تكونون لي شهوداً  القس كرم لامعى064 و تكونون لي شهوداً  القس كرم لامعى
064 و تكونون لي شهوداً القس كرم لامعى
 
Canribas ci
Canribas ciCanribas ci
Canribas ci
 
Sådan får du succes som hjertearbejder i 5 enkle trin
Sådan får du succes som hjertearbejder i 5 enkle trinSådan får du succes som hjertearbejder i 5 enkle trin
Sådan får du succes som hjertearbejder i 5 enkle trin
 
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...Instant GMP Compliance Series -Better Compliance through Master Manufacturing...
Instant GMP Compliance Series -Better Compliance through Master Manufacturing...
 
Boomers Cafe - MKT412
Boomers Cafe - MKT412Boomers Cafe - MKT412
Boomers Cafe - MKT412
 
Game wardenpowerpoint2
Game wardenpowerpoint2Game wardenpowerpoint2
Game wardenpowerpoint2
 
Sin With Sebastian introduction
Sin With Sebastian introductionSin With Sebastian introduction
Sin With Sebastian introduction
 
Maria chimborazo primero d
Maria chimborazo  primero dMaria chimborazo  primero d
Maria chimborazo primero d
 
Building a mobile website
Building a mobile websiteBuilding a mobile website
Building a mobile website
 
Senior project speech
Senior project speechSenior project speech
Senior project speech
 
Evaluation 4
Evaluation 4Evaluation 4
Evaluation 4
 
Mgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeMgt. process & organizational behaviour complete
Mgt. process & organizational behaviour complete
 
Little league: Professional Development Presentation
Little league: Professional Development PresentationLittle league: Professional Development Presentation
Little league: Professional Development Presentation
 
Pc hardware overview part 2
Pc hardware overview  part 2Pc hardware overview  part 2
Pc hardware overview part 2
 
2011 0125 platt uscc_model_state_policies
2011 0125 platt uscc_model_state_policies2011 0125 platt uscc_model_state_policies
2011 0125 platt uscc_model_state_policies
 
realestate and MySQL devops melbourne
realestate and MySQL devops melbournerealestate and MySQL devops melbourne
realestate and MySQL devops melbourne
 

Similar to OpenGurukul : Database : PostgreSQL

Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.Vijay Kumar N
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linuxchinkshady
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Denish Patel
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
Postgresql 12 streaming replication hol
Postgresql 12 streaming replication holPostgresql 12 streaming replication hol
Postgresql 12 streaming replication holVijay Kumar N
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniZalando Technology
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbSmartTools
 
ProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationSuyog Shirgaonkar
 
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Composeraccoony
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Postgresql quick guide
Postgresql quick guidePostgresql quick guide
Postgresql quick guideAshoka Vanjare
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Denish Patel
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuWirabumi Software
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Puppet
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Denish Patel
 

Similar to OpenGurukul : Database : PostgreSQL (20)

Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
Postgresql 12 streaming replication hol
Postgresql 12 streaming replication holPostgresql 12 streaming replication hol
Postgresql 12 streaming replication hol
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
ProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfigurationProstgreSQLFailoverConfiguration
ProstgreSQLFailoverConfiguration
 
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
 
GUC Tutorial Package (9.0)
GUC Tutorial Package (9.0)GUC Tutorial Package (9.0)
GUC Tutorial Package (9.0)
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Postgresql quick guide
Postgresql quick guidePostgresql quick guide
Postgresql quick guide
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014Writing and Publishing Puppet Modules - PuppetConf 2014
Writing and Publishing Puppet Modules - PuppetConf 2014
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
 

More from Open Gurukul

Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : PythonOpen Gurukul
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpen Gurukul
 
OpenGurukul : Operating System : Linux
OpenGurukul : Operating System : LinuxOpenGurukul : Operating System : Linux
OpenGurukul : Operating System : LinuxOpen Gurukul
 

More from Open Gurukul (6)

Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
OpenGurukul : Operating System : Linux
OpenGurukul : Operating System : LinuxOpenGurukul : Operating System : Linux
OpenGurukul : Operating System : Linux
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

OpenGurukul : Database : PostgreSQL

  • 1. PostgreSQL By OpenGurukul.com Free/Open Source Software Laboratory
  • 2. PostgreSQL Module : PostgreSQL Setup www.opengurukul.com 2
  • 3. PostgreSQL Setup : Manuals PostgreSQL Manuals : all versions http://www.postgresql.org/docs/manuals/ For PostgreSQL 9.1 - with user comments http://www.postgresql.org/docs/9.1/interactive/index.html For PostgreSQL 9.1 - without user comments http://www.postgresql.org/docs/9.1/static/index.html www.opengurukul.com 3
  • 4. PostgreSQL Setup : Install Install PostgreSQL yum install postgresql yum install postgresql-server yum install postgresql-libs Install pgadmin tool yum install pgadmin3 www.opengurukul.com 4
  • 5. PostgreSQL Setup : Version The postgres server version can be found by using --version on the postmaster $ postmaster --version postgres (PostgreSQL) 8.4.5 $ www.opengurukul.com 5
  • 6. PostgreSQL Module : pg_ctl : Control PostgreSQL Server www.opengurukul.com 6
  • 7. pg_ctl The pg_ctl utility is used to Initialize PostgreSQL database cluster Start PostgreSQL database server Stop PostgreSQL database server Restart PostgreSQL database server Display status of a running PostgreSQL database server www.opengurukul.com 7
  • 8. pg_ctl : PGDATA variable The pg_ctl commands are dependent on the PGDATA variable that contains directory location of database cluster. The PGDATA directory location can be specified using -D in case PGDATA environment variable is not set. Generally, we switch to “postgres” user in case the database cluster was created by “postgres” user. www.opengurukul.com 8
  • 9. pg_lsclusters : Location of Database Clusters : Ubuntu pg_lsclusters : $ pg_lsclusters # to clusters and data directory www.opengurukul.com 9
  • 10. pg_ctl : Control PostgreSQL Server Start Server : Stop Server : $ pg_ctl start $ pg_ctl stop server starting waiting for server to shut down.... done $ server stopped $ Restart Server : Server Status : $ pg_ctl restart $ pg_ctl status waiting for server to shut down.... pg_ctl: server is running (PID: 8384) done /usr/bin/postgres server stopped $ server starting www.opengurukul.com 10 $
  • 11. PostgreSQL Module : PostgreSQL Admin Tools www.opengurukul.com 11
  • 12. PhpPgAdmin : Download & Install Download phpPgAdmin from http://sourceforge.net/projects/phppgadmin/ Install phpPgAdmin using yum install phpPgAdmin www.opengurukul.com 12
  • 13. PhpPgAdmin : phppgadmin /etc/apache2/conf.d/phppgadmin Uncomment # allow from all www.opengurukul.com 13
  • 14. PhpPgAdmin : Configure /usr/share/phpPgAdmin/conf/config.inc.php : Modify extra_login_security to false in /usr/share/phpPgAdmin/conf/config.inc.php If extra login security is true, then logins via phpPgAdmin with no password or certain usernames (pgsql, postgres, root, administrator) will be denied. Set this to FALSE to access it using postgres etc. Its default value is true. // $conf['extra_login_security'] = true; Set it to false $conf['extra_login_security'] = false; www.opengurukul.com 14
  • 15. PhpPgAdmin : Configure pg_hba.conf : Modify /var/lib/pgsql/data/pg_hba.conf file to change the method to "trust" from "ident". New Settings: local all all trust Old Settings: #local all all ident Restart : Apache Web Server Restart PostgreSQL Server www.opengurukul.com 15
  • 16. PgAdmin: Download & Install Download & Install pgadmin3 from www.pgadmin.org pgadmin3-1.12.2-2.fc14.i686 rpm -i pgadmin3-1.12.2-2.fc14.i686 Directly Install pgadmin3 yum install pgadmin3 Invoke pgadmin3 $ pgadmin3 www.opengurukul.com 16
  • 17. PgAdmin: Configure 1> pg_hba.conf : edit pg_hba.conf file (use trust) otherwise you wiill not be able to connect # TYPE DATABASE USER CIDR-ADDRESS METHOD host all all 127.0.0.1/32 trust host all all ::1/128 trust 2> restart PostgresSQL Server 3> Configure a Server using PgAdmin3 Host localhost, Port 5432 user – postgres, password - postgres service – postgresql, database - postgres, edb etc. www.opengurukul.com 17 4> The configuration can be checked in postgresql.conf
  • 18. PostgreSQL psql www.opengurukul.com 18
  • 19. psql : PGDATA $ su - postgres $ pwd /var/lib/pgsql $ $ echo $PGDATA /var/lib/pgsql/data $ www.opengurukul.com 19
  • 20. psql : command line $ psql -U<user_name> -d<db_name> <DB_NAME>=# help You are using psql, the command-line interface to PostgreSQL. Type: copyright for distribution terms h for help with SQL commands ? for help with psql commands g or terminate with semicolon to execute query q to quit <DB_NAME>=# q $ www.opengurukul.com 20
  • 21. psql : default database NOTE : The default database is postgres. Example : Default connect to postgres $ psql psql (8.4.5) Type "help" for help. postgres=# q $ www.opengurukul.com 21
  • 22. psql : -d : connect to database Example : Connect to template1 $ psql -dtemplate1 psql (8.4.5) Type "help" for help. template1=# q $ www.opengurukul.com 22
  • 23. psql : s : display history or save history Syntax : s [FILE] display history or save it to file Example : will list history of commands executed. postgres-# s www.opengurukul.com 23
  • 24. psql : i : execute commands from file Syntax : i FILE execute commands from file Example : $ cat /tmp/in.sql l $ postgres=# i /tmp/in.sql ...will give a list of databases ... postgres=# www.opengurukul.com 24
  • 25. psql : o : send all query results to file Syntax : o [FILE] send all query results to file or |pipe Example : postgres=# o /tmp/out.txt l Output : $ cat /tmp/out.txt will have list of databases $ www.opengurukul.com 25
  • 26. psql : ! : execute command in shell Syntax : ! [COMMAND] execute command in shell or start interactive shell Example : postgres-# ! sh sh-4.1$ pwd /var/lib/pgsql sh-4.1$ exit exit postgres-# www.opengurukul.com 26
  • 27. psql : internal variables Syntax : prompt [TEXT] NAME prompt user to set internal variable set [NAME [VALUE]] set internal variable, or list all if no parameters unset NAME unset (delete) internal variable www.opengurukul.com 27
  • 28. psql : Display Internal Variables postgres-# set AUTOCOMMIT = 'on' PROMPT1 = '%/%R%# ' PROMPT2 = '%/%R%# ' PROMPT3 = '>> ' VERBOSITY = 'default' VERSION = 'PostgreSQL 8.4.5 on i386-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4), 32-bit' DBNAME = 'postgres' USER = 'postgres' PORT = '5432' ENCODING = 'UTF8' www.opengurukul.com 28 postgres-#
  • 29. psql : set variables : Example postgres-# prompt 'name: ' SITE name: www.opengurukul.com postgres-# set ... SITE = 'www.opengurukul.com' postgres-# www.opengurukul.com 29
  • 30. psql : prompt The psql prompt will be databasename=# for database super user databasename=> for users without super user privileges. NOTE : Whichever user has done initdb will have DB super user privileges or if added otherwise. www.opengurukul.com 30
  • 31. PostgreSQL PostgreSQL Introduction www.opengurukul.com 31
  • 32. Introduction : postgres To start PostgreSQL server, you can directly use /usr/bin/postgres $ /usr/bin/postgres -D /var/lib/pgsql/data -p 5432 -D : pgdata directory -p : port www.opengurukul.com 32
  • 33. Introduction : postmaster The postmaster is an alias for PostgreSQL Database Server. $ which postmaster /usr/bin/postmaster $ $ ls -l /usr/bin/postmaster lrwxrwxrwx. 1 root root 8 Jan 27 2011 /usr/bin/postmaster -> postgres $ www.opengurukul.com 33
  • 34. Introduction : Initialize database cluster : initdb The initdb command is used to initalize a database cluster. A database cluster consists of a data directory that can have multiple databases served be a postgres instance. The initdb creates the directories in which the database data will live. The initdb generates the shared catalog tables (tables that belong to the whole cluster rather than to any particular database). The initdb creates two databases : www.opengurukul.com 34 template1 and postgres
  • 35. Introduction: initdb : template1 Whenever you create a new database in the cluster, everything in the template1 database is copied. We should install only those things in template1 that we would like to copy to other databases. www.opengurukul.com 35
  • 36. Introduction: initdb : example Syntax : $ initdb --pgdata | -D pgdata_directory Generally, The default pgdata directory is /var/lib/pgsql/data. If you don't specify any pgdata directory, it will be picked up from PGDATA environment variable Example : Create a D/B cluster data1 in home directory $ initdb -D ~/data1 $ www.opengurukul.com 36
  • 37. Introduction: start d/b cluster Export PGDATA $ export PGDATA=~/data1 Modify the port in ~/data1/postgresql.conf to 5433. $ export PGPORT=5433 # export port Add user (the one who did initdb) to group “postgres” in /etc/group file to allow writing to /var/run/postgres/ Start D/B pg_ctl start Invoke psql with new port psql -p <new port> -d postgres www.opengurukul.com 37
  • 38. Introduction : Create Database : createdb The createdb (executable) or "CREATE DATABASE" (psql # from psql prompt command) is used to create database on PostgreSQL. CREATE DATABASE name; # from shell command line createdb name; www.opengurukul.com 38
  • 39. Introduction : Create Database : createdb : Example $ su - postgres $ createdb x Example : postgres=# CREATE DATABASE sample; CREATE DATABASE postgres=# l [List of databases] Postgres=# q www.opengurukul.com 39 $
  • 40. Introduction : Delete Database : dropdb The dropdb command can be used to delete the PostgreSQL database. Syntax : $ dropdb <dbname> www.opengurukul.com 40
  • 41. Introduction : Connect to database c[onnect] [DBNAME|- USER|- HOST|- PORT|-] connect to new database (currently "postgres") Example : postgres-# c sample psql (8.4.5) You are now connected to database "sample". sample-# www.opengurukul.com 41
  • 42. Introduction : psql : S, + Informational (options: S = show system objects, + = additional detail) d[S+] list tables, views, and sequences NOTE: dS+ shows size also For postgrres, we must specify "S" otherwise objects will not be shown. Example : postgres-# dS [List of relations] ...... www.opengurukul.com 42
  • 43. Introduction : psql : d : Describe Table postgres=# dS pg_roles View "pg_catalog.pg_roles" +---------------+--------------------------+-----------+ | Column | Type | Modifiers | +---------------+--------------------------+-----------+ | rolname | name | | | rolsuper | boolean | | | rolinherit | boolean | | | rolcreaterole | boolean | | | rolcreatedb | boolean | | | rolcatupdate | boolean | | | rolcanlogin | boolean | | | rolconnlimit | integer | | | rolpassword | text | | www.opengurukul.com 43 | rolvaliduntil | timestamp with time zone | |
  • 44. Introduction : vacuumdb : garbage- collect database The vacuumdb is a utility for cleaning a PostgreSQL database. VACUUM reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a VACUUM is done. It is necessary to do VACUUM periodically, especially on frequently-updated tables. www.opengurukul.com 44
  • 45. Introduction : vacuumdb : options --full : Perform full vaccuming --dbname <dbname> : name of the pariculat database to be cleaned or analyzed --table table [ (column [,...]) ] : table to be cleaned. columns can also be specified. --all : Vacuum all databases --analyze : Calculate statistics for use by the optimizer --verbose : verbose display www.opengurukul.com 45
  • 46. Introduction : vacuumdb : Example Example : -bash-4.1$ vacuumdb --full --all --analyze vacuumdb: vacuuming database "postgres" vacuumdb: vacuuming database "template1" -bash-4.1$ www.opengurukul.com 46
  • 47. PostgreSQL pg_dump : Backup & Resotre www.opengurukul.com 47
  • 48. pg_dump : plain dump : script file The pg_dump command is used to extract a PostgreSQL database into a .sql script file. Syntax : pg_dump database_name > database.sql www.opengurukul.com 48
  • 49. pg_dump : plain dump : usage To dump a database called "mydb" into a SQL- script file: $ pg_dump mydb > db.sql To reload such a script into a (freshly created) database named "newdb". $ psql -d newdb -f db.sql www.opengurukul.com 49
  • 50. pg_dump : table To dump specific tables, specify them after -t To skip specific tables, specify them after -T Both -t and -T supports regular expression. Example : $ pg_dump -t 'mytab1_*' -T 'mytab2_*' mydb > db.sql www.opengurukul.com 50
  • 51. pg_dump : archive file To dump a database into a custom-format archive file: $ pg_dump -Fc mydb > db.dump To reload an archive file into a (freshly created) database named newdb : $ pg_restore -d newdb db.dump The default dump format is plain (p) script file that is specified using -Fp. www.opengurukul.com 51
  • 52. PostgreSQL Users & Privileges www.opengurukul.com 52
  • 53. createuser : create user account To create a user account (also called role), createuser command is used. Only superusers and users with CREATEROLE privilege can create new users. You can also use "CREATE ROLE" to achieve it. www.opengurukul.com 53
  • 54. createuser : create user account : example Example : To create a user matsya1 on the default database server: $ createuser matsya1 Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n www.opengurukul.com 54
  • 55. dropuser - remove user account The dropuser is used to remove an existing PostgreSQL user. Only superusers and users with the CREATEROLE privilege can remove PostgreSQL users. You can also use "DROP ROLE <rolename>" to achieve it. www.opengurukul.com 55
  • 56. dropuser - remove user account : example Example : To remove user matsya1 from the default database server: $ dropuser matsya1 www.opengurukul.com 56
  • 57. list users : du You can use psql command du to see the users (also called roles). Example : List Users / Roles postgres=> du List of roles Role name | Attributes | Member of -----------+-------------+----------- postgres | Superuser | {} : Create role : Create DB surikuma | Create role | {} : Create DB www.opengurukul.com 57 postgres=>
  • 58. list users : pg_roles The users (also called roles) are present in pg_roles. We can also check rolename in pg_roles. Example : Users/Roles from pg_roles postgres=# select rolname from pg_roles; rolname ---------- postgres surikuma (2 rows) postgres=# www.opengurukul.com 58
  • 59. Role Membership : Grant & Revoke A group role is created using "CREATE ROLE" command. This role will also represent a group. A group role (priviliges) will not have LOGIN attribute generally but it is not mandatory. Syntax: GRANT <group role> to <user role>; GRANT <group role> from <user role>; www.opengurukul.com 59
  • 60. Role Membership : Grant & Revoke : Example Example : create a group role and assign priviliges to a user CREATE ROLE admin NOINHERIT; CREATE ROLE guru LOGIN INHERIT; GRANT admin TO guru; www.opengurukul.com 60
  • 61. PostgreSQL PL/pgSQL www.opengurukul.com 61
  • 62. createlang : add procedural language The createlang is used to add a support of a procedural language in the database. Syntax : $ createlang plpgsql $ createlang plperl www.opengurukul.com 62
  • 63. createlang : list procedural languages $ createlang --list Procedural Languages Name | Trusted? ---------+---------- plpgsql | yes plperl | yes $ www.opengurukul.com 63
  • 64. pg_language : list procedural languages : postgres=# select * from pg_language; +------------+--------------+---------+---------------+-----------------+----------------+--------+ | lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl | +------------+-------------+---------+----------------+-----------------+---------------+---------+ | internal | 10 |f |f | 0 | 2246 | | |c | 10 |f |f | 0 | 2247 | | | sql | 10 |f |t | 0 | 2248 | | | plpgsql | 10 |t |t | 16810 | 16811 | | +-----------+-------------+---------+----------------+----------------+----------------+---------+ (4 rows) postgres=# www.opengurukul.com 64
  • 65. PL/pgSQL : Structure PL/pgSQL is a block-structured language. PL/pgSQL Block Structure [ <<label>> ] [ DECLARE declarations ] BEGIN statements END [ label ]; www.opengurukul.com 65
  • 66. PL/pgSQL : Data Types Frequently used data type are integer - for numbers varchar - for variable length character array char - for fixed length character array date - for calendar date (year, month, day) time - for time of day timestamp - for date & time The data types table is present on http://www.postgresql.org/docs/9.1/interactive/datatype.html www.opengurukul.com 66
  • 67. PL/pgSQL : Variable Declarations PL/pgSQL variables can Examples : have any SQL data type, user_id integer; such as integer, varchar, a and char. quantity numeric(5); The variable name is url varchar; specified first and data myrow tablename type is specified next. %ROWTYPE; myfield tablename.columnname %TYPE; www.opengurukul.com 67
  • 68. PL/pgSQL : Variable Assignment In PL/pgSQL the Example : assignment operator x := 20; is := www.opengurukul.com 68
  • 69. PL/pgSQL : RAISE : Report Messages The RAISE can be used to report messages on PL/pgSQL. Syntax: RAISE LEVEL 'format' [,expression [, ...]] ; Possible levels are DEBUG, LOG, INFO, NOTICE, WARNING, and EXCEPTION. EXCEPTION raises an error. Inside the format string, % is replaced by the next optional argument's string representation Example : RAISE NOTICE 'Calling cs_create_job(%)', v_job_id; www.opengurukul.com 69
  • 70. PL/pgSQL : Create or Replace Function The CREATE OR REPLACE FUNCTION call is used to create (replace) a function. www.opengurukul.com 70
  • 71. PL/pgSQL : Create or Replace Function : Example $ cat add.sql $ psql create or replace function postgres=#i add.sql add(x integer, y integer) CREATE FUNCTION returns integer AS $$ postgres=#q declare $ total integer; begin total := x + y +z ; RETURN total; end; $$ language plpgsql; www.opengurukul.com 71
  • 72. PL/pgSQL : List of Functions: df To get List of Functions use df Syntax : df [PATTERN] Example : Get list of functions using df postgres=# df List of functions +--------+--------+------------------+---------------------------------+--------+ | Schema | Name | Result data type | Argument data types | Type | +--------+--------+------------------+---------------------------------+--------+ | public | add | integer | x integer, y integer | normal | +--------+--------+------------------+---------------------------------+--------+ (1 rows) www.opengurukul.com 72
  • 73. PL/pgSQL : Call Function Use select to call the Example : function. postgres=# select select funcname(funcargs); add(1,2); sum ----- 3 (1 row) postgres=# www.opengurukul.com 73
  • 74. PL/pgSQL : Drop Function Use DROP FUNCTION to drop a function. Example : postgres=# drop function sum(integer, integer); DROP FUNCTION postgres=# NOTE : The drop function must be called with argument types otherwise it will not work. www.opengurukul.com 74
  • 75. PL/pgSQL : Develop Function : Example 2 $ cat msg.sql create or replace function msg() RETURNS INTEGER AS $$ begin RAISE NOTICE 'hello world'; RETURN 0; end; $$ language plpgsql; www.opengurukul.com 75 $
  • 76. PL/pgSQL : Create Function : Example 2 postgres=# i msg.sql CREATE FUNCTION postgres=# www.opengurukul.com 76
  • 77. PL/pgSQL : List Function : Example 2 List Function : postgres=# df msg List of functions +-----------+---------+---------------------+-----------------------------+-----------+ | Schema | Name | Result data type | Argument data types | Type | +-----------+---------+----------------------+-----------------------------+----------+ | public | msg | integer | | normal | +-----------+---------+----------------------+-----------------------------+-----------+ (1 row) postgres=# www.opengurukul.com 77
  • 78. PL/pgSQL : Call Function : Example 2 Call Function : postgres=# select msg(); NOTICE: hello world msg ----- 0 (1 row) postgres=# www.opengurukul.com 78
  • 79. PL/pgSQL : Drop Function : Example 2 Drop Function : postgres=# drop function msg(); DROP FUNCTION postgres= www.opengurukul.com 79
  • 80. PostgreSQL Transactions www.opengurukul.com 80
  • 81. Transactions Transactions are a fundamental concept of all database systems. A transaction bundles multiple steps into a single, all-or- nothing operation. The intermediate states between the steps are not visible to other concurrent transactions. If some failure occurs that prevents the transaction from completing, then none of the steps affect the database at all. A transaction is said to be atomic: from the point of view of other transactions, it either happens completely or not at all. www.opengurukul.com 81
  • 82. Transactions : Savepoint & Rollback Create a savepoint SAVEPOINT [<savepoint_name>]; Rollback to a savepoint ROLLBACK [to <savepoint_name>]; Commit the changes COMMIT; www.opengurukul.com 82
  • 83. Transactions : Savepoint & Rollback : Example Take a case of Bank Database, suppose we debit $100.00 fro Ram's account, and credit Laxman's account, only to find later that we should have credited Sita's account BEGIN UPDATE accounts SET balance = balance - 100.00 WHERE name = 'Ram'; SAVEPOINT my_savepoint; UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Laxman'; -- oops ... forget that and use Sita's account ROLLBACK TO my_savepoint; UPDATE accounts SET balance = balance + 100.00 WHERE name = 'Sita'; COMMIT; END; www.opengurukul.com 83
  • 84. PostgreSQL Thanks www.opengurukul.com 84
  • 85. Thanks Thanks for attending the session. For additional support, please post your query on PostgreSQL discussion forum at www.opengurukul.com www.opengurukul.com 85