SlideShare a Scribd company logo
04 - Perl Programming
Database
156
Danairat T.
Line ID: Danairat
FB: Danairat Thanabodithammachari
+668-1559-1446
Danairat T.
Perl at the client Side
Perl and Database
• Perl uses the DBI (Database Interface) for DB integration
purpose. The DBI is database-independent, which means that
it can work with vendor specific DBD (Database Driver) for any
of database, such as Postgres, mySQL, Oracle, Sybase,
Informix, Access, ODBC, etc.
157
Perl Program DBI
DBD::Pg
DBD::Oracle
Postgres
Oracle
Danairat T.
Perl and Database - Topics
• Perl Modules for Database
• Prepare Database Environment (Postgres)
• Database Handler
• Database Statement
• Database Manipulation
– Select
– Add
– Update
– Delete
158
Danairat T.
Perl Modules for Database
159
• Query your existing modules using command line:-
• perl -MFile::Find=find -MFile::Spec::Functions -lwe 'find { wanted =>
sub { print canonpath $_ if /.pmz/ }, no_chdir => 1 },
• The DBI is normally located at
/usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/
• The DBDs are normally located at
/usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/DBD/
Danairat T.
Perl Modules for Database
160
• Install the Perl DBI:-
1. Download DBI module “DBI-1.58.tar.gz” from
www.cpan.org
2. Unzip as a directory and cd to the directory
gzip -cd DBI-1.58.tar.gz | tar xf -
3. Run standard perl module installation
i. perl Makefile.PL
ii. make
iii. make test
iv. make install
4. Finished.
Danairat T.
Perl Modules for Database
161
• Install the Perl DBD for Postgres Database:-
1. Download DBD module “DBD-Pg-2.15.1.tar.gz” from
www.cpan.org
2. Unzip as a directory and cd to the directory
gzip -cd DBD-Pg-2.15.1.tar.gz | tar xf -
3. Run standard perl module installation
i. perl Makefile.PL
ii. make
iii. make test
iv. make install
4. Finished.
Danairat T.
Prepare Database Environment (Postgres)
162
1. Verify the system has the Postgres using pkginfo
• bash-3.00# pkginfo -i SUNWpostgr-server
• system SUNWpostgr-server The programs needed to create and run a PostgreSQL 8.1.1 7 server
• bash-3.00# pkginfo -i SUNWpostgr
• system SUNWpostgr PostgreSQL 8.1.17 client programs and libraries
• bash-3.00# pkginfo -i SUNWpostgr-libs
• system SUNWpostgr-libs The shared libraries required for any PostgreSQL 8.1.17 clients
• bash-3.00# pkginfo -i SUNWpostgr-server-data
• system SUNWpostgr-server-data The data directories needed to create and run a PostgreSQ L 8.1.8
server
• bash-3.00# pkginfo -i SUNWpostgr-contrib
• system SUNWpostgr-contrib Contributed source and binaries distributed with PostgreSQL 8.1.17
• bash-3.00# pkginfo -i SUNWpostgr-devel
• system SUNWpostgr-devel PostgreSQL 8.1.17 development header files and libraries
• bash-3.00# pkginfo -i SUNWpostgr-docs
• system SUNWpostgr-docs Extra documentation for PostgreSQL 8.1.8
Danairat T.
Prepare Database Environment (Postgres)
163
2. Create OS user for Postgres and Initialize the database:-
• #useradd -c 'PostgreSQL user' -d /export/home/postgres -m -s /bin/bash postgres
• #chown -R postgres:postgres /var/lib/pgsql
• #su - postgres
• bash-3.00$ initdb -D /var/lib/pgsql/data/mydata
• The files belonging to this database system will be owned by user "postgres".
• This user must also own the server process.
• The database cluster will be initialized with locale C.
• creating directory /var/lib/pgsql/data/mydata ... ok
• creating directory /var/lib/pgsql/data/mydata/global ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_xlog ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_xlog/archive_status ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_clog ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_subtrans ... ok
Danairat T.
Prepare Database Environment (Postgres)
164
• Create OS user for Postgres and Initialize the database (continue):-
• creating directory /var/lib/pgsql/data/mydata/pg_twophase ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_multixact/members ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_multixact/offsets ... ok
• creating directory /var/lib/pgsql/data/mydata/base ... ok
• creating directory /var/lib/pgsql/data/mydata/base/1 ... ok
• creating directory /var/lib/pgsql/data/mydata/pg_tblspc ... ok
• selecting default max_connections ... 100
• selecting default shared_buffers ... 1000
• creating configuration files ... ok
• creating template1 database in /var/lib/pgsql/data/mydata/base/1 ... ok
• initializing pg_authid ... ok
• enabling unlimited row size for system tables ... ok
• initializing dependencies ... ok
• creating system views ... ok
• loading pg_description ... ok
• creating conversions ... ok
• setting privileges on built-in objects ... ok
Danairat T.
Prepare Database Environment (Postgres)
165
• Create OS user for Postgres and Initialize the database (continue):-
• creating information schema ... ok
• vacuuming database template1 ... ok
• copying template1 to template0 ... ok
• copying template1 to postgres ... ok
• WARNING: enabling "trust" authentication for local connections
• You can change this by editing pg_hba.conf or using the -A option the
• next time you run initdb.
• Success. You can now start the database server using:
• postmaster -D /var/lib/pgsql/data/mydata
• or
• pg_ctl -D /var/lib/pgsql/data/mydata -l logfile start
Danairat T.
Prepare Database Environment (Postgres)
166
3. Start the Postgres database using:-
bash-3.00$ pg_ctl -D /var/lib/pgsql/data/mydata -l /tmp/postgres.log start
postmaster starting
bash-3.00$
4. See the Postgres Process ID
bash-3.00$ ps -ef |grep postgres
postgres 1281 1 0 12:02:58 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata
postgres 1283 1281 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata
postgres 1263 1134 0 11:59:13 pts/4 0:00 -bash
postgres 1327 1263 0 12:14:46 pts/4 0:00 ps -ef
postgres 1284 1281 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata
postgres 1285 1284 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata
Danairat T.
Prepare Database Environment (Postgres)
167
5. Access the database:-
-bash-3.00$ psql postgres
Welcome to psql 8.1.17, the PostgreSQL interactive terminal.
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
postgres=#
Postgres Command Line UI Postgres Graphical UI
Danairat T.
Prepare Database Environment (Postgres)
168
6(a). Select the database:-
postgres=# select * from megaliths;
id | name | location | description | site_type_id | mapref
----+-------------+---------------+--------------------------+--------------+------------
1 | Stonehenge | Wiltshire | "Stone Circle and Henge" | 1 | SU 123 422
2 | Avebury | Wiltshire | "Stone Circle and Henge" | 2 | SU 103 700
3 | Sunhoney | Aberdeenshire | "Recumbent Stone Circle" | 2 | NJ 716 058
4 | Lundin | Links Fife | "Four Poster" | 3 | NO 404 027
5 | Callanish I | Western Isles | "Stone Circle and Rows" | 3 | NB 213 330
(5 rows)
Postgres Command Line UI
Danairat T.
Prepare Database Environment (Postgres)
169
6(b). Select the database:-
Postgres Graphical UI
Danairat T.
Prepare Database Environment (Postgres)
170
7. Shutdown the Postgres database:-
bash-3.00$ pg_ctl -D /var/lib/pgsql/data/mydata stop
waiting for postmaster to shut down.... done
postmaster stopped
Danairat T.
Database Handler
171
• Using the DBI to connect to Postgress and return to the DB handler
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# db name is postgres, user is postgres and password is none
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
print "Connected.n";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBHandlerEx01.pl
Results:-
Connected.
Danairat T.
Database Statement
172
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# Connect to the database
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
# Statement from DB handler
my $sth = $dbh->prepare( "SELECT * FROM megaliths" )
or die "Can't prepare SQL statement: $DBI::errstrn";
# Execute the statement in the database
$sth->execute()
or die "Can't execute SQL statement: $DBI::errstrn";
$sth->finish()
or die "Error finish the SQL statement: $DBI::errstrn";
# Disconnect database
$dbh->disconnect()
or warn "Error disconnecting: $DBI::errstrn";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBSthEx01.pl
Results:-
<no displayed result>
Danairat T.
Database Manipulation
173
• Retrieve database records
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
# 1. Connect to the database
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
my $sth = $dbh->prepare( "SELECT * FROM megaliths" )
or die "Can't prepare SQL statement: $DBI::errstrn";
# 2. Execute the statement in the database
$sth->execute() or die "Can't execute SQL statement: $DBI::errstrn";
# 3. Retrieve DB records
my @row;
while ( @row = $sth->fetchrow_array() ) {
my ($id, $name, $location, $desc, $siteId, $mapRef) = @row;
print "id=$id, name=$name, location=$location, mapRef=$mapRefn";
}
# 4. Finish the statement
$sth->finish() or die "Error finish the SQL statement: $DBI::errstrn";
# 5. Disconnect database
$dbh->disconnect()
or warn "Error disconnecting: $DBI::errstrn";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBSelectEx01.pl
Results:-
id=1, name=Stonehenge, location=Wiltshire, mapRef=SU 123 422
id=2, name=Avebury, location=Wiltshire, mapRef=SU 103 700
id=3, name=Sunhoney, location=Aberdeenshire, mapRef=NJ 716 058
id=4, name=Lundin, location=Links Fife, mapRef=NO 404 027
id=5, name=Callanish I, location=Western Isles, mapRef=NB 213 330
Danairat T.
Database Manipulation
174
• Add new records
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $newRecord = "6, Stone Big, The Area 51, The most biggest stone, 3, CA 8759 993";
# Connect to the database
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
# Prepare the statement
my $sth = $dbh->prepare( "INSERT INTO megaliths (id, name, location, description, site_type_id,
mapref) VALUES (?,?,?,?,?,?)" )
or die "Can't prepare SQL statement: $DBI::errstrn";
# Extract the input to variable
my ($id, $name, $location, $description, $site_type_id, $mapref) = split (/,/,$newRecord);
# Execute the statement in the database
$sth->execute($id, $name, $location, $description, $site_type_id, $mapref)
or die "Can't execute SQL statement: $DBI::errstrn";
# Finish the statement
$sth->finish() or die "Error finish the SQL statement: $DBI::errstrn";
# Disconnect database
$dbh->disconnect()
or warn "Error disconnecting: $DBI::errstrn";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBAddEx01.pl
Results:-
<please see the db result there is one new record inserted>
Danairat T.
Database Manipulation
175
• Update records from table
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $newRecord = "6, Stone Biggest, The Area 51, The most biggest stone, 3, CA 8759 993";
# Connect to the database
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
# Prepare the statement
my $sth = $dbh->prepare( "UPDATE megaliths SET name=? WHERE (id=?)" )
or die "Can't prepare SQL statement: $DBI::errstrn";
# Extract the input to variable
my ($id, $name, @others) = split (/,/,$newRecord);
# Execute the statement in the database
$sth->execute($name, $id)
or die "Can't execute SQL statement: $DBI::errstrn";
# Finish the statement
$sth->finish() or die "Error finish the SQL statement: $DBI::errstrn";
# Disconnect database
$dbh->disconnect()
or warn "Error disconnecting: $DBI::errstrn";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBUpdateEx01.pl
Results:-
<please see the db result >
Danairat T.
Database Manipulation
176
• Delete records from table
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $newRecord = "6, Stone Biggest, The Area 51, The most biggest stone, 3, CA 8759 993";
# Connect to the database
if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) {
# Prepare the statement
my $sth = $dbh->prepare( "DELETE FROM megaliths WHERE (id=?)" )
or die "Can't prepare SQL statement: $DBI::errstrn";
# Extract the input to variable
my ($id, @others) = split (/,/,$newRecord);
# Execute the statement in the database
$sth->execute($id)
or die "Can't execute SQL statement: $DBI::errstrn";
# Finish the statement
$sth->finish() or die "Error finish the SQL statement: $DBI::errstrn";
# Disconnect database
$dbh->disconnect()
or warn "Error disconnecting: $DBI::errstrn";
} else {
print "Could not connect to DB $DBI::errstrn";
}
exit(0);
DBDeleteEx01.pl
Results:-
<please see the db result >
Danairat T.
Line ID: Danairat
FB: Danairat Thanabodithammachari
+668-1559-1446
Thank you

More Related Content

What's hot (20)

HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성
Young Pyo
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
PoguttuezhiniVP
 
HiveServer2
HiveServer2HiveServer2
HiveServer2
Schubert Zhang
 
Advanced Sqoop
Advanced Sqoop Advanced Sqoop
Advanced Sqoop
Yogesh Kulkarni
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
Vu Hung Nguyen
 
Beginning hive and_apache_pig
Beginning hive and_apache_pigBeginning hive and_apache_pig
Beginning hive and_apache_pig
Mohamed Ali Mahmoud khouder
 
SphinxSE with MySQL
SphinxSE with MySQLSphinxSE with MySQL
SphinxSE with MySQL
Ritesh Puthran
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden Gate
Muhammad Qasim
 
Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14
jijukjoseph
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
Command Prompt., Inc
 
SQL to Hive Cheat Sheet
SQL to Hive Cheat SheetSQL to Hive Cheat Sheet
SQL to Hive Cheat Sheet
Hortonworks
 
Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine
Monowar Mukul
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
Marian Marinov
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
Antonios Giannopoulos
 
Friends of Solr - Nutch & HDFS
Friends of Solr - Nutch & HDFSFriends of Solr - Nutch & HDFS
Friends of Solr - Nutch & HDFS
Saumitra Srivastav
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
Web scraping with nutch solr
Web scraping with nutch solrWeb scraping with nutch solr
Web scraping with nutch solr
Mike Frampton
 
Hadoop
HadoopHadoop
Hadoop
Mukesh kumar
 
Hadoop HDFS Concepts
Hadoop HDFS ConceptsHadoop HDFS Concepts
Hadoop HDFS Concepts
ProTechSkills Training
 
Hadoop operations basic
Hadoop operations basicHadoop operations basic
Hadoop operations basic
Hafizur Rahman
 
HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성HADOOP 실제 구성 사례, Multi-Node 구성
HADOOP 실제 구성 사례, Multi-Node 구성
Young Pyo
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
Vu Hung Nguyen
 
Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14Hadoop single node installation on ubuntu 14
Hadoop single node installation on ubuntu 14
jijukjoseph
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
Command Prompt., Inc
 
SQL to Hive Cheat Sheet
SQL to Hive Cheat SheetSQL to Hive Cheat Sheet
SQL to Hive Cheat Sheet
Hortonworks
 
Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine
Monowar Mukul
 
Percona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorialPercona Live 2017 ­- Sharded cluster tutorial
Percona Live 2017 ­- Sharded cluster tutorial
Antonios Giannopoulos
 
Friends of Solr - Nutch & HDFS
Friends of Solr - Nutch & HDFSFriends of Solr - Nutch & HDFS
Friends of Solr - Nutch & HDFS
Saumitra Srivastav
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
Wim Godden
 
Web scraping with nutch solr
Web scraping with nutch solrWeb scraping with nutch solr
Web scraping with nutch solr
Mike Frampton
 
Hadoop operations basic
Hadoop operations basicHadoop operations basic
Hadoop operations basic
Hafizur Rahman
 

Viewers also liked (16)

JEE Programming - 03 Model View Controller
JEE Programming - 03 Model View ControllerJEE Programming - 03 Model View Controller
JEE Programming - 03 Model View Controller
Danairat Thanabodithammachari
 
Setting up Hadoop YARN Clustering
Setting up Hadoop YARN ClusteringSetting up Hadoop YARN Clustering
Setting up Hadoop YARN Clustering
Danairat Thanabodithammachari
 
Big data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guideBig data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guide
Danairat Thanabodithammachari
 
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by DanairatDigital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Danairat Thanabodithammachari
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
Danairat Thanabodithammachari
 
Perl Programming - 01 Basic Perl
Perl Programming - 01 Basic PerlPerl Programming - 01 Basic Perl
Perl Programming - 01 Basic Perl
Danairat Thanabodithammachari
 
The Business value of agile development
The Business value of agile developmentThe Business value of agile development
The Business value of agile development
Phavadol Srisarnsakul
 
IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Cognos Analytics: Empowering business by infusing intelligence across the...IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Analytics
 
JEE Programming - 02 The Containers
JEE Programming - 02 The ContainersJEE Programming - 02 The Containers
JEE Programming - 02 The Containers
Danairat Thanabodithammachari
 
JEE Programming - 05 JSP
JEE Programming - 05 JSPJEE Programming - 05 JSP
JEE Programming - 05 JSP
Danairat Thanabodithammachari
 
JEE Programming - 06 Web Application Deployment
JEE Programming - 06 Web Application DeploymentJEE Programming - 06 Web Application Deployment
JEE Programming - 06 Web Application Deployment
Danairat Thanabodithammachari
 
JEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application DeploymentJEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application Deployment
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE IntroductionGlassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE Introduction
Danairat Thanabodithammachari
 
JEE Programming - 01 Introduction
JEE Programming - 01 IntroductionJEE Programming - 01 Introduction
JEE Programming - 01 Introduction
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - The Enterprise Server
Glassfish JEE Server Administration - The Enterprise ServerGlassfish JEE Server Administration - The Enterprise Server
Glassfish JEE Server Administration - The Enterprise Server
Danairat Thanabodithammachari
 
A Guide to IT Consulting- Business.com
A Guide to IT Consulting- Business.comA Guide to IT Consulting- Business.com
A Guide to IT Consulting- Business.com
Business.com
 
Big data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guideBig data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guide
Danairat Thanabodithammachari
 
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by DanairatDigital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Danairat Thanabodithammachari
 
The Business value of agile development
The Business value of agile developmentThe Business value of agile development
The Business value of agile development
Phavadol Srisarnsakul
 
IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Cognos Analytics: Empowering business by infusing intelligence across the...IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Cognos Analytics: Empowering business by infusing intelligence across the...
IBM Analytics
 
JEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application DeploymentJEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application Deployment
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE IntroductionGlassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE Introduction
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - The Enterprise Server
Glassfish JEE Server Administration - The Enterprise ServerGlassfish JEE Server Administration - The Enterprise Server
Glassfish JEE Server Administration - The Enterprise Server
Danairat Thanabodithammachari
 
A Guide to IT Consulting- Business.com
A Guide to IT Consulting- Business.comA Guide to IT Consulting- Business.com
A Guide to IT Consulting- Business.com
Business.com
 
Ad

Similar to Perl Programming - 04 Programming Database (20)

OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf
Mustafa Keskin
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
PostgreSQL Experts, Inc.
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
Command Prompt., Inc
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
Hello World with EDB Postgres
Hello World with EDB PostgresHello World with EDB Postgres
Hello World with EDB Postgres
EDB
 
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Whats wrong with postgres | PGConf EU 2019 | Craig KerstiensWhats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Citus Data
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
Oddbjørn Steffensen
 
Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.
Vijay Kumar N
 
Bn 1016 demo postgre sql-online-training
Bn 1016 demo  postgre sql-online-trainingBn 1016 demo  postgre sql-online-training
Bn 1016 demo postgre sql-online-training
conline training
 
Postgresql quick guide
Postgresql quick guidePostgresql quick guide
Postgresql quick guide
Ashoka Vanjare
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the Trunk
Harold Giménez
 
Everything You Wanted to Know About Databases (Keith).pdf
Everything You Wanted to Know About Databases (Keith).pdfEverything You Wanted to Know About Databases (Keith).pdf
Everything You Wanted to Know About Databases (Keith).pdf
All Things Open
 
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico CaldaraTrivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis
 
Beyond Postgres: Interesting Projects, Tools and forks
Beyond Postgres: Interesting Projects, Tools and forksBeyond Postgres: Interesting Projects, Tools and forks
Beyond Postgres: Interesting Projects, Tools and forks
Sameer Kumar
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
Jacques Kostic
 
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
chinkshady
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
Emiliano Fusaglia
 
TechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best Practices
Trivadis
 
ConfigurationFererererereeerereeiles.pptx
ConfigurationFererererereeerereeiles.pptxConfigurationFererererereeerereeiles.pptx
ConfigurationFererererereeerereeiles.pptx
anand90rm
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf0292-introduction-postgresql.pdf
0292-introduction-postgresql.pdf
Mustafa Keskin
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
Command Prompt., Inc
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
Hello World with EDB Postgres
Hello World with EDB PostgresHello World with EDB Postgres
Hello World with EDB Postgres
EDB
 
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Whats wrong with postgres | PGConf EU 2019 | Craig KerstiensWhats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Citus Data
 
Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.Postgres 12 Cluster Database operations.
Postgres 12 Cluster Database operations.
Vijay Kumar N
 
Bn 1016 demo postgre sql-online-training
Bn 1016 demo  postgre sql-online-trainingBn 1016 demo  postgre sql-online-training
Bn 1016 demo postgre sql-online-training
conline training
 
Postgresql quick guide
Postgresql quick guidePostgresql quick guide
Postgresql quick guide
Ashoka Vanjare
 
Grabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the TrunkGrabbing the PostgreSQL Elephant by the Trunk
Grabbing the PostgreSQL Elephant by the Trunk
Harold Giménez
 
Everything You Wanted to Know About Databases (Keith).pdf
Everything You Wanted to Know About Databases (Keith).pdfEverything You Wanted to Know About Databases (Keith).pdf
Everything You Wanted to Know About Databases (Keith).pdf
All Things Open
 
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico CaldaraTrivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis
 
Beyond Postgres: Interesting Projects, Tools and forks
Beyond Postgres: Interesting Projects, Tools and forksBeyond Postgres: Interesting Projects, Tools and forks
Beyond Postgres: Interesting Projects, Tools and forks
Sameer Kumar
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
Jacques Kostic
 
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
chinkshady
 
TechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best Practices
Trivadis
 
ConfigurationFererererereeerereeiles.pptx
ConfigurationFererererereeerereeiles.pptxConfigurationFererererereeerereeiles.pptx
ConfigurationFererererereeerereeiles.pptx
anand90rm
 
Ad

More from Danairat Thanabodithammachari (15)

Thailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AMThailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AM
Danairat Thanabodithammachari
 
Agile Management
Agile ManagementAgile Management
Agile Management
Danairat Thanabodithammachari
 
Agile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 DanairatAgile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 Danairat
Danairat Thanabodithammachari
 
Blockchain for Management
Blockchain for ManagementBlockchain for Management
Blockchain for Management
Danairat Thanabodithammachari
 
Enterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 DanairatEnterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 Danairat
Danairat Thanabodithammachari
 
Agile Enterprise Architecture - Danairat
Agile Enterprise Architecture - DanairatAgile Enterprise Architecture - Danairat
Agile Enterprise Architecture - Danairat
Danairat Thanabodithammachari
 
Big data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guideBig data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guide
Danairat Thanabodithammachari
 
JEE Programming - 04 Java Servlets
JEE Programming - 04 Java ServletsJEE Programming - 04 Java Servlets
JEE Programming - 04 Java Servlets
Danairat Thanabodithammachari
 
JEE Programming - 07 EJB Programming
JEE Programming - 07 EJB ProgrammingJEE Programming - 07 EJB Programming
JEE Programming - 07 EJB Programming
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - Clustering
Glassfish JEE Server Administration - ClusteringGlassfish JEE Server Administration - Clustering
Glassfish JEE Server Administration - Clustering
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - Module 4 Load Balancer
Glassfish JEE Server Administration - Module 4 Load BalancerGlassfish JEE Server Administration - Module 4 Load Balancer
Glassfish JEE Server Administration - Module 4 Load Balancer
Danairat Thanabodithammachari
 
Java Programming - 07 java networking
Java Programming - 07 java networkingJava Programming - 07 java networking
Java Programming - 07 java networking
Danairat Thanabodithammachari
 
Java Programming - 08 java threading
Java Programming - 08 java threadingJava Programming - 08 java threading
Java Programming - 08 java threading
Danairat Thanabodithammachari
 
Java Programming - 06 java file io
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file io
Danairat Thanabodithammachari
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
Danairat Thanabodithammachari
 
Thailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AMThailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AM
Danairat Thanabodithammachari
 
Agile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 DanairatAgile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 Danairat
Danairat Thanabodithammachari
 
Enterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 DanairatEnterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 Danairat
Danairat Thanabodithammachari
 
Big data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guideBig data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guide
Danairat Thanabodithammachari
 
Glassfish JEE Server Administration - Module 4 Load Balancer
Glassfish JEE Server Administration - Module 4 Load BalancerGlassfish JEE Server Administration - Module 4 Load Balancer
Glassfish JEE Server Administration - Module 4 Load Balancer
Danairat Thanabodithammachari
 

Recently uploaded (20)

Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 WebinarPorting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
wAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptxwAIred_RabobankIgniteSession_12062025.pptx
wAIred_RabobankIgniteSession_12062025.pptx
SimonedeGijt
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 WebinarPorting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 

Perl Programming - 04 Programming Database

  • 1. 04 - Perl Programming Database 156 Danairat T. Line ID: Danairat FB: Danairat Thanabodithammachari +668-1559-1446
  • 2. Danairat T. Perl at the client Side Perl and Database • Perl uses the DBI (Database Interface) for DB integration purpose. The DBI is database-independent, which means that it can work with vendor specific DBD (Database Driver) for any of database, such as Postgres, mySQL, Oracle, Sybase, Informix, Access, ODBC, etc. 157 Perl Program DBI DBD::Pg DBD::Oracle Postgres Oracle
  • 3. Danairat T. Perl and Database - Topics • Perl Modules for Database • Prepare Database Environment (Postgres) • Database Handler • Database Statement • Database Manipulation – Select – Add – Update – Delete 158
  • 4. Danairat T. Perl Modules for Database 159 • Query your existing modules using command line:- • perl -MFile::Find=find -MFile::Spec::Functions -lwe 'find { wanted => sub { print canonpath $_ if /.pmz/ }, no_chdir => 1 }, • The DBI is normally located at /usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/ • The DBDs are normally located at /usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/DBD/
  • 5. Danairat T. Perl Modules for Database 160 • Install the Perl DBI:- 1. Download DBI module “DBI-1.58.tar.gz” from www.cpan.org 2. Unzip as a directory and cd to the directory gzip -cd DBI-1.58.tar.gz | tar xf - 3. Run standard perl module installation i. perl Makefile.PL ii. make iii. make test iv. make install 4. Finished.
  • 6. Danairat T. Perl Modules for Database 161 • Install the Perl DBD for Postgres Database:- 1. Download DBD module “DBD-Pg-2.15.1.tar.gz” from www.cpan.org 2. Unzip as a directory and cd to the directory gzip -cd DBD-Pg-2.15.1.tar.gz | tar xf - 3. Run standard perl module installation i. perl Makefile.PL ii. make iii. make test iv. make install 4. Finished.
  • 7. Danairat T. Prepare Database Environment (Postgres) 162 1. Verify the system has the Postgres using pkginfo • bash-3.00# pkginfo -i SUNWpostgr-server • system SUNWpostgr-server The programs needed to create and run a PostgreSQL 8.1.1 7 server • bash-3.00# pkginfo -i SUNWpostgr • system SUNWpostgr PostgreSQL 8.1.17 client programs and libraries • bash-3.00# pkginfo -i SUNWpostgr-libs • system SUNWpostgr-libs The shared libraries required for any PostgreSQL 8.1.17 clients • bash-3.00# pkginfo -i SUNWpostgr-server-data • system SUNWpostgr-server-data The data directories needed to create and run a PostgreSQ L 8.1.8 server • bash-3.00# pkginfo -i SUNWpostgr-contrib • system SUNWpostgr-contrib Contributed source and binaries distributed with PostgreSQL 8.1.17 • bash-3.00# pkginfo -i SUNWpostgr-devel • system SUNWpostgr-devel PostgreSQL 8.1.17 development header files and libraries • bash-3.00# pkginfo -i SUNWpostgr-docs • system SUNWpostgr-docs Extra documentation for PostgreSQL 8.1.8
  • 8. Danairat T. Prepare Database Environment (Postgres) 163 2. Create OS user for Postgres and Initialize the database:- • #useradd -c 'PostgreSQL user' -d /export/home/postgres -m -s /bin/bash postgres • #chown -R postgres:postgres /var/lib/pgsql • #su - postgres • bash-3.00$ initdb -D /var/lib/pgsql/data/mydata • The files belonging to this database system will be owned by user "postgres". • This user must also own the server process. • The database cluster will be initialized with locale C. • creating directory /var/lib/pgsql/data/mydata ... ok • creating directory /var/lib/pgsql/data/mydata/global ... ok • creating directory /var/lib/pgsql/data/mydata/pg_xlog ... ok • creating directory /var/lib/pgsql/data/mydata/pg_xlog/archive_status ... ok • creating directory /var/lib/pgsql/data/mydata/pg_clog ... ok • creating directory /var/lib/pgsql/data/mydata/pg_subtrans ... ok
  • 9. Danairat T. Prepare Database Environment (Postgres) 164 • Create OS user for Postgres and Initialize the database (continue):- • creating directory /var/lib/pgsql/data/mydata/pg_twophase ... ok • creating directory /var/lib/pgsql/data/mydata/pg_multixact/members ... ok • creating directory /var/lib/pgsql/data/mydata/pg_multixact/offsets ... ok • creating directory /var/lib/pgsql/data/mydata/base ... ok • creating directory /var/lib/pgsql/data/mydata/base/1 ... ok • creating directory /var/lib/pgsql/data/mydata/pg_tblspc ... ok • selecting default max_connections ... 100 • selecting default shared_buffers ... 1000 • creating configuration files ... ok • creating template1 database in /var/lib/pgsql/data/mydata/base/1 ... ok • initializing pg_authid ... ok • enabling unlimited row size for system tables ... ok • initializing dependencies ... ok • creating system views ... ok • loading pg_description ... ok • creating conversions ... ok • setting privileges on built-in objects ... ok
  • 10. Danairat T. Prepare Database Environment (Postgres) 165 • Create OS user for Postgres and Initialize the database (continue):- • creating information schema ... ok • vacuuming database template1 ... ok • copying template1 to template0 ... ok • copying template1 to postgres ... ok • WARNING: enabling "trust" authentication for local connections • You can change this by editing pg_hba.conf or using the -A option the • next time you run initdb. • Success. You can now start the database server using: • postmaster -D /var/lib/pgsql/data/mydata • or • pg_ctl -D /var/lib/pgsql/data/mydata -l logfile start
  • 11. Danairat T. Prepare Database Environment (Postgres) 166 3. Start the Postgres database using:- bash-3.00$ pg_ctl -D /var/lib/pgsql/data/mydata -l /tmp/postgres.log start postmaster starting bash-3.00$ 4. See the Postgres Process ID bash-3.00$ ps -ef |grep postgres postgres 1281 1 0 12:02:58 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata postgres 1283 1281 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata postgres 1263 1134 0 11:59:13 pts/4 0:00 -bash postgres 1327 1263 0 12:14:46 pts/4 0:00 ps -ef postgres 1284 1281 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata postgres 1285 1284 0 12:02:59 pts/4 0:00 /usr/bin/postmaster -D /var/lib/pgsql/data/mydata
  • 12. Danairat T. Prepare Database Environment (Postgres) 167 5. Access the database:- -bash-3.00$ psql postgres Welcome to psql 8.1.17, the PostgreSQL interactive terminal. 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 postgres=# Postgres Command Line UI Postgres Graphical UI
  • 13. Danairat T. Prepare Database Environment (Postgres) 168 6(a). Select the database:- postgres=# select * from megaliths; id | name | location | description | site_type_id | mapref ----+-------------+---------------+--------------------------+--------------+------------ 1 | Stonehenge | Wiltshire | "Stone Circle and Henge" | 1 | SU 123 422 2 | Avebury | Wiltshire | "Stone Circle and Henge" | 2 | SU 103 700 3 | Sunhoney | Aberdeenshire | "Recumbent Stone Circle" | 2 | NJ 716 058 4 | Lundin | Links Fife | "Four Poster" | 3 | NO 404 027 5 | Callanish I | Western Isles | "Stone Circle and Rows" | 3 | NB 213 330 (5 rows) Postgres Command Line UI
  • 14. Danairat T. Prepare Database Environment (Postgres) 169 6(b). Select the database:- Postgres Graphical UI
  • 15. Danairat T. Prepare Database Environment (Postgres) 170 7. Shutdown the Postgres database:- bash-3.00$ pg_ctl -D /var/lib/pgsql/data/mydata stop waiting for postmaster to shut down.... done postmaster stopped
  • 16. Danairat T. Database Handler 171 • Using the DBI to connect to Postgress and return to the DB handler #!/usr/bin/perl use strict; use warnings; use DBI; # db name is postgres, user is postgres and password is none if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { print "Connected.n"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBHandlerEx01.pl Results:- Connected.
  • 17. Danairat T. Database Statement 172 #!/usr/bin/perl use strict; use warnings; use DBI; # Connect to the database if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { # Statement from DB handler my $sth = $dbh->prepare( "SELECT * FROM megaliths" ) or die "Can't prepare SQL statement: $DBI::errstrn"; # Execute the statement in the database $sth->execute() or die "Can't execute SQL statement: $DBI::errstrn"; $sth->finish() or die "Error finish the SQL statement: $DBI::errstrn"; # Disconnect database $dbh->disconnect() or warn "Error disconnecting: $DBI::errstrn"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBSthEx01.pl Results:- <no displayed result>
  • 18. Danairat T. Database Manipulation 173 • Retrieve database records #!/usr/bin/perl use strict; use warnings; use DBI; # 1. Connect to the database if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { my $sth = $dbh->prepare( "SELECT * FROM megaliths" ) or die "Can't prepare SQL statement: $DBI::errstrn"; # 2. Execute the statement in the database $sth->execute() or die "Can't execute SQL statement: $DBI::errstrn"; # 3. Retrieve DB records my @row; while ( @row = $sth->fetchrow_array() ) { my ($id, $name, $location, $desc, $siteId, $mapRef) = @row; print "id=$id, name=$name, location=$location, mapRef=$mapRefn"; } # 4. Finish the statement $sth->finish() or die "Error finish the SQL statement: $DBI::errstrn"; # 5. Disconnect database $dbh->disconnect() or warn "Error disconnecting: $DBI::errstrn"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBSelectEx01.pl Results:- id=1, name=Stonehenge, location=Wiltshire, mapRef=SU 123 422 id=2, name=Avebury, location=Wiltshire, mapRef=SU 103 700 id=3, name=Sunhoney, location=Aberdeenshire, mapRef=NJ 716 058 id=4, name=Lundin, location=Links Fife, mapRef=NO 404 027 id=5, name=Callanish I, location=Western Isles, mapRef=NB 213 330
  • 19. Danairat T. Database Manipulation 174 • Add new records #!/usr/bin/perl use strict; use warnings; use DBI; my $newRecord = "6, Stone Big, The Area 51, The most biggest stone, 3, CA 8759 993"; # Connect to the database if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { # Prepare the statement my $sth = $dbh->prepare( "INSERT INTO megaliths (id, name, location, description, site_type_id, mapref) VALUES (?,?,?,?,?,?)" ) or die "Can't prepare SQL statement: $DBI::errstrn"; # Extract the input to variable my ($id, $name, $location, $description, $site_type_id, $mapref) = split (/,/,$newRecord); # Execute the statement in the database $sth->execute($id, $name, $location, $description, $site_type_id, $mapref) or die "Can't execute SQL statement: $DBI::errstrn"; # Finish the statement $sth->finish() or die "Error finish the SQL statement: $DBI::errstrn"; # Disconnect database $dbh->disconnect() or warn "Error disconnecting: $DBI::errstrn"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBAddEx01.pl Results:- <please see the db result there is one new record inserted>
  • 20. Danairat T. Database Manipulation 175 • Update records from table #!/usr/bin/perl use strict; use warnings; use DBI; my $newRecord = "6, Stone Biggest, The Area 51, The most biggest stone, 3, CA 8759 993"; # Connect to the database if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { # Prepare the statement my $sth = $dbh->prepare( "UPDATE megaliths SET name=? WHERE (id=?)" ) or die "Can't prepare SQL statement: $DBI::errstrn"; # Extract the input to variable my ($id, $name, @others) = split (/,/,$newRecord); # Execute the statement in the database $sth->execute($name, $id) or die "Can't execute SQL statement: $DBI::errstrn"; # Finish the statement $sth->finish() or die "Error finish the SQL statement: $DBI::errstrn"; # Disconnect database $dbh->disconnect() or warn "Error disconnecting: $DBI::errstrn"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBUpdateEx01.pl Results:- <please see the db result >
  • 21. Danairat T. Database Manipulation 176 • Delete records from table #!/usr/bin/perl use strict; use warnings; use DBI; my $newRecord = "6, Stone Biggest, The Area 51, The most biggest stone, 3, CA 8759 993"; # Connect to the database if (my $dbh = DBI->connect("dbi:Pg:dbname=postgres", "postgres", "")) { # Prepare the statement my $sth = $dbh->prepare( "DELETE FROM megaliths WHERE (id=?)" ) or die "Can't prepare SQL statement: $DBI::errstrn"; # Extract the input to variable my ($id, @others) = split (/,/,$newRecord); # Execute the statement in the database $sth->execute($id) or die "Can't execute SQL statement: $DBI::errstrn"; # Finish the statement $sth->finish() or die "Error finish the SQL statement: $DBI::errstrn"; # Disconnect database $dbh->disconnect() or warn "Error disconnecting: $DBI::errstrn"; } else { print "Could not connect to DB $DBI::errstrn"; } exit(0); DBDeleteEx01.pl Results:- <please see the db result >
  • 22. Danairat T. Line ID: Danairat FB: Danairat Thanabodithammachari +668-1559-1446 Thank you