PostgreSQL For Oracle DBAs - An Introduction - Blog Dbi Services PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Infrastructure
at your Service

PostgreSQL for Oracle DBAs an introduction


By Pierre Sicot

August 4, 2014

Database management

No Comments

Having worked for several years as an Oracle DBA, I decided to have a look at the PostgreSQL database
and see how it functions in comparison to the Oracle Database.

The Enterprise DB graphical installation of PostgreSQL 9.3 is quite easy and rather fast. Under Linux
you run the graphical installer, dialog boxes lead you through the installation process. You enter the
specific information of your system and at the end of the PostgreSQL installation, the Stack Builder
package is invoked if you need to install applications, drivers, agents or utilities.

You can download the Enterprise DB utility using the following URL:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

http://www.enterprisedb.com/downloads/postgres-postgresql-downloads

I have installed PostgreSQL 9.3 using Enterprise DB as described below:

Choose Next.

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Specify the installation directory where PostgreSQL 9.3 will be installed.

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Select the directory that will store the data.

Provide a password to the PostgreSQL database user.

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Select a port number.

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Choose the locale for the new database cluster.

PostgreSQL is now ready to be installed.

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

You can choose to launch or not the Stack Builder if not, the installation process will begin.

If you encounter any problem during the installation phase, the log files are generated in /tmp.

Under Linux, a shell script named uninstall-postgresql is created in the PostgreSQL home directory to deinstall the software.

The installation phase is very quick, your PostgreSQL cluster database is ready to use. Furthermore, the
Enterprise DB installation creates the automatic startup file in /etc/init.d/postgresql-9.3 to start
PostgreSQL in case of a server reboot.

Once the Enterprise DB installation is processed, a database storage area is initializedon disk (a database
cluster). After the installation, this database cluster will contain a database named postgres and will be
used by utilities or users:

postgres=# list List of databases Name | Owner | Encoding | Collate |


Ctype | Access privileges-----------+----------+----------+------------+------------+-------------postgres |
postgres | UTF8 | en_US.utf8 | en_US.utf8 |template0 | postgres | UTF8 | en_US.utf8 |
en_US.utf8 | =c/postgres+ | | | | |

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

postgres=CTc/postgrestemplate1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 |


postgres=CTc/postgres+ | | | | | =c/postgres
By default, a new database is created by cloning the system standard base named template1. The template0
allows you to create a database containing only pre-defined standard objects.

The sqlplus oracle equivalent command in PostgreSQL is psql. As you will see in the document, the
PostgreSQL commands begin with the sign. The ? command lists every possibility.

For example, the following commands connects to the psi database:

-bash-3.2$ psql -d psi


Password:psql.bin (9.3.4)
Type "help" for help.No entry for terminal type "xterm";
using dumb terminal settings.
psi=# q
If you do not want the system to ask for a password, you simply have to create a .pgpass file in the
postgres home directory with the 0600 rights and the following syntax:

-bash-3.2$ more .pgpass


localhost:5432:PSI:postgres:password

-bash-3.2$ su - postgres
Password:
-bash-3.2$ psql -d psi
psql.bin (9.3.4)
Type "help" for help.
No entry for terminal type "xterm";
using dumb terminal settings.
psi=#
psi-# q
At first you probably need to create a database. As an Oracle DBA, I was wondering about some typical
problems such as character set or default tablespace. With PostgreSQL, it is quite easy to create a
database.

As the locale en_US.utf8 has been chosen during the installation phase to be used by the cluster database,
every database you will create will use it.

When you create a database you can specify a default tablespace and an owner. At first we create a

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

tablespace:

postgres=# create tablespace psi location '/u01/postgres/data/psi';


CREATE TABLESPACE
The tablespace data is located in /u01/postgres/data/psi:

-bash-3.2$ ls
PG_9.3_201306121
-bash-3.2$ ls PG_9.3_201306121/
16526
-bash-3.2$ ls PG_9.3_201306121/16526/
12547 12587_vm 12624 12663 12728 12773
12547_fsm 12589 12625 12664 12728_fsm 12774
12664_vm 12730 12774_vm 12627 12666 12731 12776

Then we create the database:

postgres=# create database psi owner postgres tablespace psi;


CREATE DATABASE
We can list all databases with the list command:

postgres=# list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+------------postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
psi | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | postgres=CTc/postgres+ |
| | | | =c/postgres
Now, we can connect to the psi database and create objects, the syntax is quite similar to Oracle:

postgres=# c psi
You are now connected to database "psi" as user "postgres".
We create a table and an index:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

psi=# create table employe (name varchar);


CREATE TABLE
psi=# create index employe_ix on employe (name);
CREATE INDEX
We insert values in it:

psi=# insert into employe values ('bill');


INSERT 0 1
We reconnect to the psi database:

-bash-3.2$ psql -d psi


Password:
psql.bin (9.3.4)
Type "help" for help.
No entry for terminal type "xterm";
using dumb terminal settings.
The following command lists the tables:

psi=# dt[+]
List of relations
Schema | Name | Type | Owner | Size | Description
--------+---------+-------+----------+-------+------------public | employe | table | postgres | 16 kB |
(1 row)
psi=# select * from employe;
name
-----bill
(1 row)
The d+ postgreSQL command is the equivalent of the Oracle desc command:

psi=# d+ employe
Table "public.employe"
Column | Type | Modifiers | Storage | Stats target | Description
--------+-------------------+-----------+----------+--------------+------------name | character varying | | extended | |
Indexes:
"employe_ix" btree (name)

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Has OIDs: no
Obviously we also have the possibility to create a schema and create objects in this schema.

Lets create a schema:

psi=# create schema psi;


CREATE SCHEMA
Lets create a table, insert objects in it and create a view:

psi=# create table psi.salary (val integer);


CREATE TABLE
psi=# insert into psi.salary values (10000);
INSERT 0 1
psi=# select * from psi.salary;
val
------10000
psi=# create view psi.v_employe as select * from psi.salary;
CREATE VIEW
If we list the tables we can only see the public objects:

psi=# d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+---------public | employe | table | postgres
(1 row)
If we modify the search path, all schemas are visible:

psi=# set search_path to psi,public;


SET
psi=# d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+---------psi | salary | table | postgres
public | employe | table | postgres
Oracle DBAs are familiar with sql commands e. g. to get the table list of a schema by typing select

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

table_name, owner from user_tables, etc.

What is the equivalent query in postgreSQL?

PostgreSQL uses a schema named information_schema available in every database. The owner of this
schema is the initial database user in the cluster. You can drop this schema, but the space saving is
negligible.

You can easily query the tables of this schema to get precious informations about your database objects:

Here is a list of the schemas tables:

psi=# select table_name, table_schema from information_schema.tables where table_schema in


('public','psi');
table_name | table_schema
------------+-------------employe | public
salary | psi
We can display the database character set:

psi=# select character_set_name from information_schema.character_sets;


character_set_name
-------------------UTF8
We can display schema views:

psi=# select table_name from information_schema.views where table_schema='psi';


table_name
-----------v_employe
Using the information_schema schema helps us to display information about a lot of different database
objects (tables, constraints, sequences, triggers, table_privileges )

Like in Oracle you can run a query from the SQL or the UNIX prompt. For example, if you want to know
the index name of the table employe, you shoud use the index.sql script:

select
t.relname as table_name,
i.relname as index_name,
a.attname as column_name

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

from
pg_class t,pg_class i,
pg_index ix,pg_attribute a
wheret.oid = ix.indrelid
and i.oid = ix.indexrelid
and a.attrelid = t.oid
and a.attnum = ANY(ix.indkey)
and t.relkind = 'r'
and t.relname = 'employe'
order byt.relname,i.relname;
If you want to display the employee index from the SQL prompt, you run:

psi=# i index.sql
table_name | index_name | column_name
------------+------------+------------employe | employe_ix | name

If you want to run the same query from the UNIX prompt:

-bash-3.2$ psql -d psi -a -f index.sql


Password:
table_name | index_name | column_name
------------+------------+------------employe | employe_ix | name
However, typing an SQL request might be interesting, but as many Oracle DBA I like using an
administration console because I think it increases efficiency.

I have discovered pgAdmin, an administration tool designed for Unix or Windows systems. pgAdmin is
easy to install on a PostgreSQL environment and enables many operations for the administration of a
cluster database.

pgAdmin3 is installed in the home directory of the user postgre in my case in /opt/postgres/9.3.

To successfully enable pgAdmin3, it is necessary to correctly initialize the LD_LIBRARY_PATH


variable:

export LD_LIBRARY_PATH=/opt/PostgreSQL/9.3/lib:/opt/PostgreSQL/9.3/pgAdmin3/lib
The pgadmin3 console:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

As you can see, you can administer every database object (tables, functions, sequences, triggers, views).

You can visualize the table creation scripts:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

You can edit / change / modify the privileges of an object:

You also have the possibility to create scripst for the database creation:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Or even to backup the database:

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

This tool seems to be very powerful, even if for the moment, I did not find any performance tool available
like in Cloud Control 12c.

Conclusion
Discovering PostgreSQL as an Oracle DBA, I realized how close the two products are. The PostgreSQL
database has a lot of advantages such as the easy installation, the general usage and the price (because its
free!).

For the processing of huge amounts of data, Oracle certainly has advantages, nevertheless the choice of a
RDBMS always depends on what your application business needs are.

Leave a Reply

Name *

Email *

Website

seven

=0

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Submit Comment

Post view(s) : 44

Search...

CATEGORIES
Application integration & Middleware
Business Intelligence
Database Administration & Monitoring
Database management
Development & Performance
Entreprise content management
Hardware & Storage
Operation systems

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

Search

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Technology Survey

RECENT ARTICLES
SQL Server: switch partition and metadata inconsistency issue
BeeCon Day 2 Activiti, SDK/SPK, Migration and Zombies
APEX Connect 2016 Day 3 APEX
Testing Oracle on exoscale.ch
BeeCon Day 1 The place to be for Alfresco

TAG CLOUD
Alfresco

DBA

Analysis Services

AlwaysOn

Documentum

Linux/UNIX

Exadata

Grid

Microsoft

Oracle

Availability Groups

Oracle 10g To 8i

PostgreSQL
SQL Server 2008
Troubleshooting

PowerShell

High Availability

Middleware

Migration

Oracle 11g

Oracle Enterprise Manager Cloud 12c

Cloud

SQL Server 2012

Security

Cluster

In-Memory

Installation

Monitoring

Multitenant Database

Oracle 12c

Oracle OpenWorld

Reporting Services

Cloud Computing

Oracle WebLogic
SQL

SQL Server 2014

Florian Haas' blog


Dirk Nachbar's blog on Oracle Fusion Middleware & Application Server

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

Optimizer

Oracle Enterprise Manager

Performance

SQL Server 2016

BLOG ROLL

Martin Bach's blog

Integration Services

SQL Server

UKOUG

Oracle Scratchpad - Jonathan Lewis' blog

Database

Storage

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

Striving for optimal performance - Chris Antognini's blog


The Tom Kyte Blog ( Ask Tom)
Blog of Adar-Consult
Alex Gorbachev's blog
Marcus Mnnig's Oracle & Mumbai Blog

Pierre Sicot
Senior Consultant

Name
Company
E-Mail
Phone Number

Send
http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

PostgreSQL for Oracle DBAs - an introduction - Blog dbi services

EXPERTISE IN

TRAININGS IN

DATABASE &

DATABASE &

MIDDLEWARE

MIDDLEWARE

Oracle database expertise (12c, 11g, 10g)

Microsoft

SQL Server expertise (2014, 2012, 2008)

Oracle

SharePoint expertise (2013, 2010, 2007)

Open Source DB

EMC Documentum expertise

Operating system

Linux expertise (Oracle Linux, Red Hat)

USEFUL INFORMATION
News & Events
Jobs openings
Offices
Blog of dbi services
Imprint

2015 dbi services sa

http://blog.dbi-services.com/postgresql-for-oracle-dbas-an-introduction/[03/05/2016 13:07:49]

You might also like