Postgre sql best_practices

BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA
HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH
PostgreSQL Best Practices
Overview from the initial setup to an OLTP performance benchmark
against Oracle.
Emiliano Fusaglia Principal Consultant
Jacques Kostic Principal Consultant
2018 © Trivadis
Exadata X7-2 POC with OVM
2
TechEvent September 2018
Specialties:
• Database Cloud computing (DBaaS)
• Oracle RAC
• Grid Infrastructure (CRS, ASM)
• Data Guard
• Instance and SQL Performance & Tuning
• Linux & Virtualization
Certifications:
• Oracle Certified Professional 9i, 10g, 11g & 12c
• Oracle Exadata Administrator X3 –X4 Certified Expert
Teaching Courses at Trivadis:
• Oracle 11g & 12c Grid Infrastructure & RAC
• Oracle 11g & 12c Data Guard
• Oracle Exadata
• Oracle 12c New Features
About me…
@EFusaglia
PostgreSQL Best Practices3 14/09/2018
Experience:
• Initially C/C++ developer
• In touch with Oracle since 1990 from version 4 on SCO Unix!
• High Availability and Backup & Recovery Architect
• SQL and Instance Performance & Tuning
• License Audit and Consolidation
Certifications:
• Oracle Certified Master 11g & 12c
• Oracle 11g Performance Tuning Certified Expert
• Oracle RAC 11g and Grid Infrastructure Administration
• Oracle Exadata Administrator Certified Expert
• Oracle Certified SQL Expert 11g
Teaching Courses at Trivadis:
• Oracle 11g & 12c Grid Infrastructure & RAC
• Oracle 11g & 12c Data Guard
• Oracle 11g & 12c Performance & Tuning
• Oracle 11g & 12c Administration
• SQL & PL-SQL
• OEM – 12 & 13
About me…
@JKOFR
Agenda
PostgreSQL Best Practices9/14/2018
1. PostgreSQL
Introduction & Architecture
OS Requirements
Installation Options
Securing PostgreSQL ClusterDB
Main parameters to configure
Backup and Recovery
2. OLTP performance benchmark PostgreSQL vs Oracle
Configuration
Results
3. Conclusion
Takeaway
4
PostgreSQL Best Practices9/14/2018
PostgreSQL Introduction &
Architecture
5
Introduction to PostgreSQL
PostgreSQL is an opensource and independent Object-RDBMS developed and
maintained by the PostgreSQL Global Development Group.
The first version was released in 1996 as INGRES development, and it included support
for Object orientation and SQL.
Main Characteristics:
ACID (Atomicity, Consistency, Isolation, Durability)
Multiversion concurrency control (MVCC)
Foreign keys, Indexes, Views, Trigger, Functions, Procedural Languages (PL), etc..
Streaming Replication (as of 9.0)
Hot Standby (as of 9.0)
PostgreSQL Best Practices9/14/20186
PostgreSQL Architecture
PostgreSQL Best Practices9/14/20187
pg_crl start
Source PostgreSQL documentation
Database Cluster
PostgreSQL Best Practices9/14/20188
Source PostgreSQL documentation
A cluster is an instance of postgreSQL containing one or many databases
– Conceptually similar to MySQL, SQL Server and Oracle Pluggable Databases
Server
Cluster pgclu01 (port 5438) Cluster pgclu02 (port 5439)
postgres template0 template1 postgres template0 template1
ecom01 erp01 sales01 dwh01 hr01 supp01
Database Cluster
PostgreSQL Best Practices9/14/20189
postgres
template0
template1
System or Master database, it contains system tables, views, procedures,
metadata, user and role definitions.
Template0 it is a read-only empty database used as seed database.
Template1 it is a read-write database, which allows customizations before
to be used as default seed database.
App
Application Database it contains application objects like tables, indexes,
views, procedures, constraints etc..
Before Image and Vacuum Process
PostgreSQL has no rollback segments, and it guarantees read consistency in the
following way:
Writing new image in a new location
Marking the initial image as OLD, keeping intact the data.
Adding a pointer to the OLD image pointing the new one.
PostgreSQL Best Practices9/14/201810
Before Image and Vacuum Process
PostgreSQL Best Practices9/14/201811
Page x
Case 1 The new image remains on the
same page.
1,’blue’
2,’green’
0,’red’
Case 2 The new image migrates
on a new page.
1,’white’ NEW
OLD
UPDATE app_tab SET col2=‘white’ WHERE col0=1;
Page x Page y
1,’bb’,test4
OLD
NEW
1,’blue’
2,’green’
0,’red’
1,’white’
UPDATE app_tab SET col2=‘white’ WHERE col0=1;
Before Image and Vacuum Process
PostgreSQL Best Practices9/14/201812
VACUUM Process
Reclaims space occupied by old tuple images
Updates data statistics used by the query planner
Updates the visibility map
Resets the transaction ID of old blocks to prevent wraparound
The standard VACUUM is executed regularly by default
Manual VACUUMing is possible
PostgreSQL Best Practices9/14/2018
Hands on set up
13
OS Optimization 1/2
PostgreSQL14 14/09/2018
Kernel optimization
– /etc/sysctl.d/90-postgres-sysctl.conf
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.sem = 250 32768 1000 128
kernel.shmall = 1073741824
kernel.shmmni = 4096
kernel.shmmax = 4398046511104
#Huge Pages 80GB
vm.nr_hugepages= 40960
vm.min_free_kbytes=524288
OS Optimization 2/2
PostgreSQL15 14/09/2018
– /etc/security/limits.d/postgres-limits.conf
postgres soft nofile 16384
postgres hard nofile 16384
postgres soft memlock 83886080
postgres hard memlock 83886080
Storage
– Binaries, ClusterDB, External Tablespaces and WAL files on T1 Storage
– Backups on T2 Storage
Installation Options
List of Supported Platforms: Linux (all recent distributions), Windows (Win2000 SP4
and later), FreeBSD, OpenBSD, NetBSD, Mac OS X, AIX, HP/UX, IRIX, Solaris, Tru64
Unix, and UnixWare.
P.S.: this presentation focuses on Linux 64-bit
PostgreSQL can be installed using one of the following method :
Source Code
Binary Package
Binaries Archive without installer (Advanced users) TVD Recommended Option
PostgreSQL Best Practices9/14/201816
Securing PostgreSQL ClusterDB
After the installation one of the first tasks to perform is securing the local and remote
database connections, defining the open ports and the authentication methods.
Those settings can be defined in two different configuration files:
postgresql.conf section CONNECTIONS AND AUTHENTICATION
pg_hba.conf
PostgreSQL Best Practices9/14/201817
Securing PostgreSQL ClusterDB - postgresql.conf 1/2
PostgreSQL Best Practices9/14/201818
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '192.168.1.129,localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5544 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directories = '/tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
unix_socket_permissions = 0770 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - Security and Authentication -
#authentication_timeout = 1min # 1s-600s
#ssl = off
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_dh_params_file = ''
#ssl_cert_file = 'server.crt'
...
Securing PostgreSQL ClusterDB - postgresql.conf 2/2
PostgreSQL Best Practices9/14/201819
# - Security and Authentication -
#authentication_timeout = 1min # 1s-600s
#ssl = off
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_dh_params_file = ''
#ssl_cert_file = 'server.crt'
#ssl_key_file = 'server.key'
#ssl_ca_file = ''
#ssl_crl_file = ‚‘
password_encryption = scram-sha-256 # md5 or scram-sha-256
#db_user_namespace = off
#row_security = on
# GSSAPI using Kerberos
#krb_server_keyfile = ''
#krb_caseins_users = off
# - TCP Keepalives -
# see "man 7 tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
# 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
...
Securing PostgreSQL ClusterDB - pg_hba.conf
PostgreSQL Best Practices9/14/201820
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
# host all all 127.0.0.1/32 trust
host all all 192.168.1.1/24 trust
# IPv6 local connections:
# host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# local replication all trust
# host replication all 127.0.0.1/32 trust
# host replication all ::1/128 trust
Main parameters to configure - 1/2
PostgreSQL Best Practices9/14/201821
postgres=# select name,setting from pg_file_settings;
name settings
------------------------------------------------------------------------------------------------
external_pid_file | extra_pid.info
listen_addresses | 192.168.1.129,localhost
port | 5544
max_connections | 100
unix_socket_permissions | 0770
password_encryption | scram-sha-256
shared_buffers | 4096MB
huge_pages | on
max_stack_depth | 6MB
dynamic_shared_memory_type | posix
effective_io_concurrency | 80
max_worker_processes | 150
max_parallel_workers | 24
wal_level | replica
wal_compression | on
archive_mode | on
archive_command | test ! -f /home/postgres01/backup_dir/clusterTEST/archives/%f && cp %p
/home/postgres01/backup_dir/clusterTEST/archives/%f
archive_timeout | 14400
log_destination | stderr,syslog
logging_collector | on
log_directory | /home/postgres01/clusterTEST/logs
Main parameters to configure - 2/2
PostgreSQL Best Practices9/14/201822
name settings
------------------------------------------------------------------------------------------------
log_filename | alert_cluster_test-%Y-%m-%d_%H%M%S.log
log_file_mode | 0600
log_rotation_age | 30d
log_rotation_size | 100MB
syslog_facility | LOCAL0
syslog_ident | postgres_cluster_test
log_lock_waits | on
log_timezone | Europe/Vaduz
cluster_name | cluster_test
log_autovacuum_min_duration | 0
default_tablespace | TS_data01
datestyle | iso, mdy
timezone | Europe/Vaduz
extra_float_digits | 3
lc_messages | en_US.UTF-8
lc_monetary | en_US.UTF-8
lc_numeric | en_US.UTF-8
lc_time | en_US.UTF-8
default_text_search_config | pg_catalog.english
(40 rows)
postgres=#
Backup and Recovery
PostgreSQL provides the following options regarding the backup/recovery strategy:
Logical Backup
– Single database dump pg_dump
– Cluster database dump pg_dumpall
Physical Backup
– File System Level Backup
– Continuous Archiving and Point-in-Time Recovery (PITR)
PostgreSQL Best Practices9/14/201823
Backup and Recovery - Logical Backup
PostgreSQL provides the following options regarding the backup/recovery strategy:
Logical Backup
pg_dump create a TEXT file that can be restored by psql
Restore Dump File on database dbtest01_restore
PostgreSQL Best Practices9/14/201824
$ pg_dump dbtest01 > /backup_dir/dbtest01_dump_20180716.dmp
$ psql --set ON_ERROR_STOP=on dbtest01_restore <
/backup_dir/dbtest01_dump_20180716.dmp
Backup and Recovery - Physical Backup
PostgreSQL provides the following options regarding the backup/recovery strategy:
Physical Backup
Continuous Archiving and Point-in-Time Recovery (PITR)
PostgreSQL Best Practices9/14/201825
#!/bin/bash
db_cluster_base="/u01/PosgreSQL"
db_cluster_dir="/u01/PosgreSQL/clusterTEST"
bckup_start=$(date +"%Y%m%d%H%M")
logfile="/u01/PosgreSQL/backup_dir/logs/clusterTEST_backup_$bckup_start.log"
backup_dir="/u01/PosgreSQL/backup_dir/clusterTEST"
bck_label="Start_Backup_$bckup_start“
...
Backup and Recovery - Physical Backup
PostgreSQL Best Practices9/14/201826
...
psql postgres -L $logfile << EOF
SELECT pg_start_backup('$bck_label', false, false);
! tar zcvf $backup_dir/backup_$bckup_start.tar.gz --warning=no-file-changed
--warning=no-file-removed -C /u01/PosgreSQL clusterTEST --exclude='pg_wal/*‘
--exclude='postmaster*' --exclude='pg_replslot/*'
SELECT * FROM pg_stop_backup(false, true);
q
EOF
9/14/2018
OLTP Performance Benchmark
PostgreSQL vs Oracle
Oracle DBaaS27
OLTP Test: PostGreSQL vs Oracle
PostgreSQL Best Practices9/14/201828
Goal
Use the same type of machine
Test the same OLTP workload on both databases
Test different CPU allocation
Compare the results
OLTP Test: PostGreSQL vs Oracle: Configuration
PostgreSQL Best Practices9/14/201829
Server details
Main host:
• 2 * 8 cores CPU E5-2680 0 @ 2.70GHz
• OEL 7.2
• 192 GB
• Flash Storage volumes on PCIe cards (no NVMe)
VMs:
• 8 vCPU
• 8 GB RAM
Concurrent sessions:
• 100
OLTP Test: PostGreSQL vs Oracle : Configuration
PostgreSQL Best Practices9/14/201830
Hammerdbcli PostGreSQL Test Setup
dbset db pg
diset tpcc pg_defaultdbase hammerdb
loadscript
vudestroy
vuset delay 5
vuset repeat 5
vuset showoutput 1
vuset timestamps 1
vuset logtotemp 1
vuset vu 100
vucreate
vurun
OLTP Test: PostGreSQL vs Oracle : Configuration
PostgreSQL Best Practices9/14/201831
Hammerdbcli Oracle Test Setup
dbset db ora
diset connection instance jko
loadscript
vudestroy
vuset delay 5
vuset repeat 5
vuset showoutput 1
vuset timestamps 1
vuset logtotemp 1
vuset vu 100
vucreate
vurun
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201832
PostGreSQL
Time to complete the full test  4.23 mn
Average CPU Usage  88 %
Transaction per minutes max  156’222
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201833
Oracle
Time to complete the full test  Time 4.12 mn
Average CPU Usage  74 %
Transaction per minutes max  172’268
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201834
select sum(value) from v$sysstat where name = 'user commits' or name = 'user rollbacks'
select sum(xact_commit + xact_rollback) from pg_stat_database
OLTP Test: PostGreSQL vs Oracle : Configuration
PostgreSQL Best Practices9/14/201835
Lets Scale!
Main host:
• 2 * 8 cores CPU E5-2680 0 @ 2.70GHz
• OEL 7.2
• 192 GB
• Flash Storage volumes on PCIe cards (no NVMe)
VMs:
• 16 vCPU
• 8 GB RAM
Concurrent sessions:
• 100
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201836
PostGreSQL
Time to complete the full test  Time 3.27 mn
Average CPU Usage  65 %
Transaction per minutes max  194’904
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201837
Oracle
Time to complete the full test  Time 3.16 mn
Average CPU Usage  57 %
Transaction per minutes max  251’292
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201838
select sum(value) from v$sysstat where name = 'user commits' or name = 'user rollbacks'
select sum(xact_commit + xact_rollback) from pg_stat_database
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201839
8 vCPU
2.6% Faster 16% Less CPU 9.3% More TPM
OLTP Test: PostGreSQL vs Oracle : Results
PostgreSQL Best Practices9/14/201840
16 vCPU
3.4% Faster 12.3% Less CPU 22.43% More TPM
41 9/14/2018
Conclusion
Oracle DBaaS
Conclusions
PostgreSQL Best Practices9/14/201842
 PostgreSQL is a mature, enterprise RDBMS
 PostgreSQL offers good performances
 PostgreSQL offers High Availability solution
Emilian Fusaglia, Principal Consultant
Tel. +41-79-909 7213 Emiliano.Fusaglia@trivadis.com
Jacques Kostic, Principal Consultant
Tel. +41-79-909 7263 Jacques.Kostic@trivadis.com
9/14/201843 TechEvent September 2018
Session Feedback – now
TechEvent September 201844 14.09.2018
Please use the Trivadis Events mobile app to give feedback on each session
Use "My schedule" if you have registered for a session
Otherwise use "Agenda" and the search function
If the mobile app does not work (or if you have a Windows smartphone), use your
smartphone browser
– URL: http://trivadis.quickmobileplatform.eu/
– User name: <your_loginname> (such as "svv")
– Password: sent by e-mail...
1 of 44

Recommended

MAA Best Practices for Oracle Database 19c by
MAA Best Practices for Oracle Database 19cMAA Best Practices for Oracle Database 19c
MAA Best Practices for Oracle Database 19cMarkus Michalewicz
3.7K views50 slides
Analysis of Database Issues using AHF and Machine Learning v2 - SOUG by
Analysis of Database Issues using AHF and Machine Learning v2 -  SOUGAnalysis of Database Issues using AHF and Machine Learning v2 -  SOUG
Analysis of Database Issues using AHF and Machine Learning v2 - SOUGSandesh Rao
293 views64 slides
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법 by
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법Open Source Consulting
3.6K views35 slides
Prometheus + Grafana = Awesome Monitoring by
Prometheus + Grafana = Awesome MonitoringPrometheus + Grafana = Awesome Monitoring
Prometheus + Grafana = Awesome MonitoringHenrique Galafassi Dalssaso
1.4K views14 slides
Keep Calm And Serilog Elasticsearch Kibana on .NET Core by
Keep Calm And Serilog Elasticsearch Kibana on .NET CoreKeep Calm And Serilog Elasticsearch Kibana on .NET Core
Keep Calm And Serilog Elasticsearch Kibana on .NET CoreMaciej Szymczyk
358 views40 slides
One PDB to go, please! by
One PDB to go, please!One PDB to go, please!
One PDB to go, please!Christian Gohmann
309 views36 slides

More Related Content

What's hot

Troubleshooting PostgreSQL Streaming Replication by
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationAlexey Lesovsky
9.6K views47 slides
Christo kutrovsky oracle, memory & linux by
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linuxKyle Hailey
12.6K views89 slides
Ash and awr deep dive hotsos by
Ash and awr deep dive hotsosAsh and awr deep dive hotsos
Ash and awr deep dive hotsosKellyn Pot'Vin-Gorman
2.9K views79 slides
Patroni - HA PostgreSQL made easy by
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyAlexander Kukushkin
2.3K views35 slides
Postgresql database administration volume 1 by
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1Federico Campoli
33.3K views124 slides
Securing Hadoop with Apache Ranger by
Securing Hadoop with Apache RangerSecuring Hadoop with Apache Ranger
Securing Hadoop with Apache RangerDataWorks Summit
20.6K views37 slides

What's hot(20)

Troubleshooting PostgreSQL Streaming Replication by Alexey Lesovsky
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
Alexey Lesovsky9.6K views
Christo kutrovsky oracle, memory & linux by Kyle Hailey
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
Kyle Hailey12.6K views
Postgresql database administration volume 1 by Federico Campoli
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli33.3K views
Securing Hadoop with Apache Ranger by DataWorks Summit
Securing Hadoop with Apache RangerSecuring Hadoop with Apache Ranger
Securing Hadoop with Apache Ranger
DataWorks Summit20.6K views
Linux Systems Performance 2016 by Brendan Gregg
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
Brendan Gregg504.5K views
Kafka at Peak Performance by Todd Palino
Kafka at Peak PerformanceKafka at Peak Performance
Kafka at Peak Performance
Todd Palino3.9K views
Oracle GoldenGate 18c - REST API Examples by Bobby Curtis
Oracle GoldenGate 18c - REST API ExamplesOracle GoldenGate 18c - REST API Examples
Oracle GoldenGate 18c - REST API Examples
Bobby Curtis4.1K views
OSMC 2022 | VictoriaMetrics: scaling to 100 million metrics per second by Ali... by NETWAYS
OSMC 2022 | VictoriaMetrics: scaling to 100 million metrics per second by Ali...OSMC 2022 | VictoriaMetrics: scaling to 100 million metrics per second by Ali...
OSMC 2022 | VictoriaMetrics: scaling to 100 million metrics per second by Ali...
NETWAYS516 views
Deep Dive on the Amazon Aurora PostgreSQL-compatible Edition - DAT402 - re:In... by Amazon Web Services
Deep Dive on the Amazon Aurora PostgreSQL-compatible Edition - DAT402 - re:In...Deep Dive on the Amazon Aurora PostgreSQL-compatible Edition - DAT402 - re:In...
Deep Dive on the Amazon Aurora PostgreSQL-compatible Edition - DAT402 - re:In...
Amazon Web Services3.6K views
Velocity 2015 linux perf tools by Brendan Gregg
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
Brendan Gregg1.1M views
Introduction to DataFusion An Embeddable Query Engine Written in Rust by Andrew Lamb
Introduction to DataFusion  An Embeddable Query Engine Written in RustIntroduction to DataFusion  An Embeddable Query Engine Written in Rust
Introduction to DataFusion An Embeddable Query Engine Written in Rust
Andrew Lamb409 views
Monitoring IO performance with iostat and pt-diskstats by Ben Mildren
Monitoring IO performance with iostat and pt-diskstatsMonitoring IO performance with iostat and pt-diskstats
Monitoring IO performance with iostat and pt-diskstats
Ben Mildren9.9K views
MySQL/MariaDB Proxy Software Test by I Goo Lee
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
I Goo Lee2K views

Similar to Postgre sql best_practices

TechEvent PostgreSQL Best Practices by
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best PracticesTrivadis
142 views44 slides
Operating PostgreSQL at Scale with Kubernetes by
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with KubernetesJonathan Katz
2.7K views28 slides
What's New in Postgres 9.4 by
What's New in Postgres 9.4What's New in Postgres 9.4
What's New in Postgres 9.4EDB
1.8K views21 slides
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database by
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseParesh Patel
306 views24 slides
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options by
PostgresOpen 2013 A Comparison of PostgreSQL Encryption OptionsPostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption OptionsFaisal Akber
38.3K views30 slides
20181116 Massive Log Processing using I/O optimized PostgreSQL by
20181116 Massive Log Processing using I/O optimized PostgreSQL20181116 Massive Log Processing using I/O optimized PostgreSQL
20181116 Massive Log Processing using I/O optimized PostgreSQLKohei KaiGai
439 views37 slides

Similar to Postgre sql best_practices(20)

TechEvent PostgreSQL Best Practices by Trivadis
TechEvent PostgreSQL Best PracticesTechEvent PostgreSQL Best Practices
TechEvent PostgreSQL Best Practices
Trivadis142 views
Operating PostgreSQL at Scale with Kubernetes by Jonathan Katz
Operating PostgreSQL at Scale with KubernetesOperating PostgreSQL at Scale with Kubernetes
Operating PostgreSQL at Scale with Kubernetes
Jonathan Katz2.7K views
What's New in Postgres 9.4 by EDB
What's New in Postgres 9.4What's New in Postgres 9.4
What's New in Postgres 9.4
EDB1.8K views
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database by Paresh Patel
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
Paresh Patel306 views
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options by Faisal Akber
PostgresOpen 2013 A Comparison of PostgreSQL Encryption OptionsPostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
Faisal Akber38.3K views
20181116 Massive Log Processing using I/O optimized PostgreSQL by Kohei KaiGai
20181116 Massive Log Processing using I/O optimized PostgreSQL20181116 Massive Log Processing using I/O optimized PostgreSQL
20181116 Massive Log Processing using I/O optimized PostgreSQL
Kohei KaiGai439 views
20160407_GTC2016_PgSQL_In_Place by Kohei KaiGai
20160407_GTC2016_PgSQL_In_Place20160407_GTC2016_PgSQL_In_Place
20160407_GTC2016_PgSQL_In_Place
Kohei KaiGai4.4K views
GPU/SSD Accelerates PostgreSQL - challenge towards query processing throughpu... by Kohei KaiGai
GPU/SSD Accelerates PostgreSQL - challenge towards query processing throughpu...GPU/SSD Accelerates PostgreSQL - challenge towards query processing throughpu...
GPU/SSD Accelerates PostgreSQL - challenge towards query processing throughpu...
Kohei KaiGai3.6K views
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds by PGConf APAC
PGConf APAC 2018 - PostgreSQL performance comparison in various cloudsPGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC354 views
Srimanta_Maji_Oracle_DBA by SRIMANTA MAJI
Srimanta_Maji_Oracle_DBASrimanta_Maji_Oracle_DBA
Srimanta_Maji_Oracle_DBA
SRIMANTA MAJI100 views
MySQL Utilities -- PyTexas 2015 by Dave Stokes
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
Dave Stokes698 views
Testing Persistent Storage Performance in Kubernetes with Sherlock by ScyllaDB
Testing Persistent Storage Performance in Kubernetes with SherlockTesting Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with Sherlock
ScyllaDB278 views
GPS Insight on Using Presto with Scylla for Data Analytics and Data Archival by ScyllaDB
GPS Insight on Using Presto with Scylla for Data Analytics and Data ArchivalGPS Insight on Using Presto with Scylla for Data Analytics and Data Archival
GPS Insight on Using Presto with Scylla for Data Analytics and Data Archival
ScyllaDB1.2K views
Autoscaling Your Kubernetes Workloads (Sponsored by Datadog) - AWS Summit Sydney by Amazon Web Services
Autoscaling Your Kubernetes Workloads (Sponsored by Datadog) - AWS Summit SydneyAutoscaling Your Kubernetes Workloads (Sponsored by Datadog) - AWS Summit Sydney
Autoscaling Your Kubernetes Workloads (Sponsored by Datadog) - AWS Summit Sydney
Database As A Service: OEM + ODA (OOW 15 Presentation) by Bobby Curtis
Database As A Service: OEM + ODA (OOW 15 Presentation)Database As A Service: OEM + ODA (OOW 15 Presentation)
Database As A Service: OEM + ODA (OOW 15 Presentation)
Bobby Curtis1.9K views
Automatically scaling your Kubernetes workloads - SVC201-S - Chicago AWS Summit by Amazon Web Services
Automatically scaling your Kubernetes workloads - SVC201-S - Chicago AWS SummitAutomatically scaling your Kubernetes workloads - SVC201-S - Chicago AWS Summit
Automatically scaling your Kubernetes workloads - SVC201-S - Chicago AWS Summit
PL/CUDA - Fusion of HPC Grade Power with In-Database Analytics by Kohei KaiGai
PL/CUDA - Fusion of HPC Grade Power with In-Database AnalyticsPL/CUDA - Fusion of HPC Grade Power with In-Database Analytics
PL/CUDA - Fusion of HPC Grade Power with In-Database Analytics
Kohei KaiGai1.8K views

More from Jacques Kostic

Poc exadata 2018 by
Poc exadata 2018Poc exadata 2018
Poc exadata 2018Jacques Kostic
142 views34 slides
High availability microsoftvsoracle by
High availability microsoftvsoracleHigh availability microsoftvsoracle
High availability microsoftvsoracleJacques Kostic
72 views41 slides
High availability Microsoft vs Oracle by
High availability Microsoft vs OracleHigh availability Microsoft vs Oracle
High availability Microsoft vs OracleJacques Kostic
853 views41 slides
Multiple awr reports_parser by
Multiple awr reports_parserMultiple awr reports_parser
Multiple awr reports_parserJacques Kostic
432 views25 slides
Oracle 12c ilm_customer_experience by
Oracle 12c ilm_customer_experienceOracle 12c ilm_customer_experience
Oracle 12c ilm_customer_experienceJacques Kostic
208 views15 slides
In memorybtree by
In memorybtreeIn memorybtree
In memorybtreeJacques Kostic
77 views30 slides

More from Jacques Kostic(11)

Recently uploaded

How Leaders See Data? (Level 1) by
How Leaders See Data? (Level 1)How Leaders See Data? (Level 1)
How Leaders See Data? (Level 1)Narendra Narendra
13 views76 slides
ColonyOS by
ColonyOSColonyOS
ColonyOSJohanKristiansson6
9 views17 slides
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf by
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfVikas 500 BIG DATA TECHNOLOGIES LAB.pdf
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfvikas12611618
8 views30 slides
Introduction to Microsoft Fabric.pdf by
Introduction to Microsoft Fabric.pdfIntroduction to Microsoft Fabric.pdf
Introduction to Microsoft Fabric.pdfishaniuudeshika
29 views16 slides
Building Real-Time Travel Alerts by
Building Real-Time Travel AlertsBuilding Real-Time Travel Alerts
Building Real-Time Travel AlertsTimothy Spann
111 views48 slides
CRIJ4385_Death Penalty_F23.pptx by
CRIJ4385_Death Penalty_F23.pptxCRIJ4385_Death Penalty_F23.pptx
CRIJ4385_Death Penalty_F23.pptxyvettemm100
6 views24 slides

Recently uploaded(20)

Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf by vikas12611618
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdfVikas 500 BIG DATA TECHNOLOGIES LAB.pdf
Vikas 500 BIG DATA TECHNOLOGIES LAB.pdf
vikas126116188 views
Introduction to Microsoft Fabric.pdf by ishaniuudeshika
Introduction to Microsoft Fabric.pdfIntroduction to Microsoft Fabric.pdf
Introduction to Microsoft Fabric.pdf
ishaniuudeshika29 views
Building Real-Time Travel Alerts by Timothy Spann
Building Real-Time Travel AlertsBuilding Real-Time Travel Alerts
Building Real-Time Travel Alerts
Timothy Spann111 views
CRIJ4385_Death Penalty_F23.pptx by yvettemm100
CRIJ4385_Death Penalty_F23.pptxCRIJ4385_Death Penalty_F23.pptx
CRIJ4385_Death Penalty_F23.pptx
yvettemm1006 views
[DSC Europe 23] Spela Poklukar & Tea Brasanac - Retrieval Augmented Generation by DataScienceConferenc1
[DSC Europe 23] Spela Poklukar & Tea Brasanac - Retrieval Augmented Generation[DSC Europe 23] Spela Poklukar & Tea Brasanac - Retrieval Augmented Generation
[DSC Europe 23] Spela Poklukar & Tea Brasanac - Retrieval Augmented Generation
UNEP FI CRS Climate Risk Results.pptx by pekka28
UNEP FI CRS Climate Risk Results.pptxUNEP FI CRS Climate Risk Results.pptx
UNEP FI CRS Climate Risk Results.pptx
pekka2811 views
Advanced_Recommendation_Systems_Presentation.pptx by neeharikasingh29
Advanced_Recommendation_Systems_Presentation.pptxAdvanced_Recommendation_Systems_Presentation.pptx
Advanced_Recommendation_Systems_Presentation.pptx
[DSC Europe 23] Zsolt Feleki - Machine Translation should we trust it.pptx by DataScienceConferenc1
[DSC Europe 23] Zsolt Feleki - Machine Translation should we trust it.pptx[DSC Europe 23] Zsolt Feleki - Machine Translation should we trust it.pptx
[DSC Europe 23] Zsolt Feleki - Machine Translation should we trust it.pptx
RuleBookForTheFairDataEconomy.pptx by noraelstela1
RuleBookForTheFairDataEconomy.pptxRuleBookForTheFairDataEconomy.pptx
RuleBookForTheFairDataEconomy.pptx
noraelstela167 views
Survey on Factuality in LLM's.pptx by NeethaSherra1
Survey on Factuality in LLM's.pptxSurvey on Factuality in LLM's.pptx
Survey on Factuality in LLM's.pptx
NeethaSherra15 views
Understanding Hallucinations in LLMs - 2023 09 29.pptx by Greg Makowski
Understanding Hallucinations in LLMs - 2023 09 29.pptxUnderstanding Hallucinations in LLMs - 2023 09 29.pptx
Understanding Hallucinations in LLMs - 2023 09 29.pptx
Greg Makowski17 views
Data structure and algorithm. by Abdul salam
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
Abdul salam 19 views
Short Story Assignment by Kelly Nguyen by kellynguyen01
Short Story Assignment by Kelly NguyenShort Story Assignment by Kelly Nguyen
Short Story Assignment by Kelly Nguyen
kellynguyen0119 views
3196 The Case of The East River by ErickANDRADE90
3196 The Case of The East River3196 The Case of The East River
3196 The Case of The East River
ErickANDRADE9011 views
Chapter 3b- Process Communication (1) (1)(1) (1).pptx by ayeshabaig2004
Chapter 3b- Process Communication (1) (1)(1) (1).pptxChapter 3b- Process Communication (1) (1)(1) (1).pptx
Chapter 3b- Process Communication (1) (1)(1) (1).pptx
ayeshabaig20045 views
Cross-network in Google Analytics 4.pdf by GA4 Tutorials
Cross-network in Google Analytics 4.pdfCross-network in Google Analytics 4.pdf
Cross-network in Google Analytics 4.pdf
GA4 Tutorials6 views

Postgre sql best_practices

  • 1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH PostgreSQL Best Practices Overview from the initial setup to an OLTP performance benchmark against Oracle. Emiliano Fusaglia Principal Consultant Jacques Kostic Principal Consultant
  • 2. 2018 © Trivadis Exadata X7-2 POC with OVM 2 TechEvent September 2018 Specialties: • Database Cloud computing (DBaaS) • Oracle RAC • Grid Infrastructure (CRS, ASM) • Data Guard • Instance and SQL Performance & Tuning • Linux & Virtualization Certifications: • Oracle Certified Professional 9i, 10g, 11g & 12c • Oracle Exadata Administrator X3 –X4 Certified Expert Teaching Courses at Trivadis: • Oracle 11g & 12c Grid Infrastructure & RAC • Oracle 11g & 12c Data Guard • Oracle Exadata • Oracle 12c New Features About me… @EFusaglia
  • 3. PostgreSQL Best Practices3 14/09/2018 Experience: • Initially C/C++ developer • In touch with Oracle since 1990 from version 4 on SCO Unix! • High Availability and Backup & Recovery Architect • SQL and Instance Performance & Tuning • License Audit and Consolidation Certifications: • Oracle Certified Master 11g & 12c • Oracle 11g Performance Tuning Certified Expert • Oracle RAC 11g and Grid Infrastructure Administration • Oracle Exadata Administrator Certified Expert • Oracle Certified SQL Expert 11g Teaching Courses at Trivadis: • Oracle 11g & 12c Grid Infrastructure & RAC • Oracle 11g & 12c Data Guard • Oracle 11g & 12c Performance & Tuning • Oracle 11g & 12c Administration • SQL & PL-SQL • OEM – 12 & 13 About me… @JKOFR
  • 4. Agenda PostgreSQL Best Practices9/14/2018 1. PostgreSQL Introduction & Architecture OS Requirements Installation Options Securing PostgreSQL ClusterDB Main parameters to configure Backup and Recovery 2. OLTP performance benchmark PostgreSQL vs Oracle Configuration Results 3. Conclusion Takeaway 4
  • 5. PostgreSQL Best Practices9/14/2018 PostgreSQL Introduction & Architecture 5
  • 6. Introduction to PostgreSQL PostgreSQL is an opensource and independent Object-RDBMS developed and maintained by the PostgreSQL Global Development Group. The first version was released in 1996 as INGRES development, and it included support for Object orientation and SQL. Main Characteristics: ACID (Atomicity, Consistency, Isolation, Durability) Multiversion concurrency control (MVCC) Foreign keys, Indexes, Views, Trigger, Functions, Procedural Languages (PL), etc.. Streaming Replication (as of 9.0) Hot Standby (as of 9.0) PostgreSQL Best Practices9/14/20186
  • 7. PostgreSQL Architecture PostgreSQL Best Practices9/14/20187 pg_crl start Source PostgreSQL documentation
  • 8. Database Cluster PostgreSQL Best Practices9/14/20188 Source PostgreSQL documentation A cluster is an instance of postgreSQL containing one or many databases – Conceptually similar to MySQL, SQL Server and Oracle Pluggable Databases Server Cluster pgclu01 (port 5438) Cluster pgclu02 (port 5439) postgres template0 template1 postgres template0 template1 ecom01 erp01 sales01 dwh01 hr01 supp01
  • 9. Database Cluster PostgreSQL Best Practices9/14/20189 postgres template0 template1 System or Master database, it contains system tables, views, procedures, metadata, user and role definitions. Template0 it is a read-only empty database used as seed database. Template1 it is a read-write database, which allows customizations before to be used as default seed database. App Application Database it contains application objects like tables, indexes, views, procedures, constraints etc..
  • 10. Before Image and Vacuum Process PostgreSQL has no rollback segments, and it guarantees read consistency in the following way: Writing new image in a new location Marking the initial image as OLD, keeping intact the data. Adding a pointer to the OLD image pointing the new one. PostgreSQL Best Practices9/14/201810
  • 11. Before Image and Vacuum Process PostgreSQL Best Practices9/14/201811 Page x Case 1 The new image remains on the same page. 1,’blue’ 2,’green’ 0,’red’ Case 2 The new image migrates on a new page. 1,’white’ NEW OLD UPDATE app_tab SET col2=‘white’ WHERE col0=1; Page x Page y 1,’bb’,test4 OLD NEW 1,’blue’ 2,’green’ 0,’red’ 1,’white’ UPDATE app_tab SET col2=‘white’ WHERE col0=1;
  • 12. Before Image and Vacuum Process PostgreSQL Best Practices9/14/201812 VACUUM Process Reclaims space occupied by old tuple images Updates data statistics used by the query planner Updates the visibility map Resets the transaction ID of old blocks to prevent wraparound The standard VACUUM is executed regularly by default Manual VACUUMing is possible
  • 14. OS Optimization 1/2 PostgreSQL14 14/09/2018 Kernel optimization – /etc/sysctl.d/90-postgres-sysctl.conf fs.file-max = 6815744 fs.aio-max-nr = 1048576 kernel.sem = 250 32768 1000 128 kernel.shmall = 1073741824 kernel.shmmni = 4096 kernel.shmmax = 4398046511104 #Huge Pages 80GB vm.nr_hugepages= 40960 vm.min_free_kbytes=524288
  • 15. OS Optimization 2/2 PostgreSQL15 14/09/2018 – /etc/security/limits.d/postgres-limits.conf postgres soft nofile 16384 postgres hard nofile 16384 postgres soft memlock 83886080 postgres hard memlock 83886080 Storage – Binaries, ClusterDB, External Tablespaces and WAL files on T1 Storage – Backups on T2 Storage
  • 16. Installation Options List of Supported Platforms: Linux (all recent distributions), Windows (Win2000 SP4 and later), FreeBSD, OpenBSD, NetBSD, Mac OS X, AIX, HP/UX, IRIX, Solaris, Tru64 Unix, and UnixWare. P.S.: this presentation focuses on Linux 64-bit PostgreSQL can be installed using one of the following method : Source Code Binary Package Binaries Archive without installer (Advanced users) TVD Recommended Option PostgreSQL Best Practices9/14/201816
  • 17. Securing PostgreSQL ClusterDB After the installation one of the first tasks to perform is securing the local and remote database connections, defining the open ports and the authentication methods. Those settings can be defined in two different configuration files: postgresql.conf section CONNECTIONS AND AUTHENTICATION pg_hba.conf PostgreSQL Best Practices9/14/201817
  • 18. Securing PostgreSQL ClusterDB - postgresql.conf 1/2 PostgreSQL Best Practices9/14/201818 #------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '192.168.1.129,localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5544 # (change requires restart) max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '/tmp' # comma-separated list of directories # (change requires restart) #unix_socket_group = '' # (change requires restart) unix_socket_permissions = 0770 # begin with 0 to use octal notation # (change requires restart) #bonjour = off # advertise server via Bonjour # (change requires restart) #bonjour_name = '' # defaults to the computer name # (change requires restart) # - Security and Authentication - #authentication_timeout = 1min # 1s-600s #ssl = off #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers #ssl_prefer_server_ciphers = on #ssl_ecdh_curve = 'prime256v1' #ssl_dh_params_file = '' #ssl_cert_file = 'server.crt' ...
  • 19. Securing PostgreSQL ClusterDB - postgresql.conf 2/2 PostgreSQL Best Practices9/14/201819 # - Security and Authentication - #authentication_timeout = 1min # 1s-600s #ssl = off #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers #ssl_prefer_server_ciphers = on #ssl_ecdh_curve = 'prime256v1' #ssl_dh_params_file = '' #ssl_cert_file = 'server.crt' #ssl_key_file = 'server.key' #ssl_ca_file = '' #ssl_crl_file = ‚‘ password_encryption = scram-sha-256 # md5 or scram-sha-256 #db_user_namespace = off #row_security = on # GSSAPI using Kerberos #krb_server_keyfile = '' #krb_caseins_users = off # - TCP Keepalives - # see "man 7 tcp" for details #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; # 0 selects the system default #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; # 0 selects the system default #tcp_keepalives_count = 0 # TCP_KEEPCNT; # 0 selects the system default ...
  • 20. Securing PostgreSQL ClusterDB - pg_hba.conf PostgreSQL Best Practices9/14/201820 # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: # host all all 127.0.0.1/32 trust host all all 192.168.1.1/24 trust # IPv6 local connections: # host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. # local replication all trust # host replication all 127.0.0.1/32 trust # host replication all ::1/128 trust
  • 21. Main parameters to configure - 1/2 PostgreSQL Best Practices9/14/201821 postgres=# select name,setting from pg_file_settings; name settings ------------------------------------------------------------------------------------------------ external_pid_file | extra_pid.info listen_addresses | 192.168.1.129,localhost port | 5544 max_connections | 100 unix_socket_permissions | 0770 password_encryption | scram-sha-256 shared_buffers | 4096MB huge_pages | on max_stack_depth | 6MB dynamic_shared_memory_type | posix effective_io_concurrency | 80 max_worker_processes | 150 max_parallel_workers | 24 wal_level | replica wal_compression | on archive_mode | on archive_command | test ! -f /home/postgres01/backup_dir/clusterTEST/archives/%f && cp %p /home/postgres01/backup_dir/clusterTEST/archives/%f archive_timeout | 14400 log_destination | stderr,syslog logging_collector | on log_directory | /home/postgres01/clusterTEST/logs
  • 22. Main parameters to configure - 2/2 PostgreSQL Best Practices9/14/201822 name settings ------------------------------------------------------------------------------------------------ log_filename | alert_cluster_test-%Y-%m-%d_%H%M%S.log log_file_mode | 0600 log_rotation_age | 30d log_rotation_size | 100MB syslog_facility | LOCAL0 syslog_ident | postgres_cluster_test log_lock_waits | on log_timezone | Europe/Vaduz cluster_name | cluster_test log_autovacuum_min_duration | 0 default_tablespace | TS_data01 datestyle | iso, mdy timezone | Europe/Vaduz extra_float_digits | 3 lc_messages | en_US.UTF-8 lc_monetary | en_US.UTF-8 lc_numeric | en_US.UTF-8 lc_time | en_US.UTF-8 default_text_search_config | pg_catalog.english (40 rows) postgres=#
  • 23. Backup and Recovery PostgreSQL provides the following options regarding the backup/recovery strategy: Logical Backup – Single database dump pg_dump – Cluster database dump pg_dumpall Physical Backup – File System Level Backup – Continuous Archiving and Point-in-Time Recovery (PITR) PostgreSQL Best Practices9/14/201823
  • 24. Backup and Recovery - Logical Backup PostgreSQL provides the following options regarding the backup/recovery strategy: Logical Backup pg_dump create a TEXT file that can be restored by psql Restore Dump File on database dbtest01_restore PostgreSQL Best Practices9/14/201824 $ pg_dump dbtest01 > /backup_dir/dbtest01_dump_20180716.dmp $ psql --set ON_ERROR_STOP=on dbtest01_restore < /backup_dir/dbtest01_dump_20180716.dmp
  • 25. Backup and Recovery - Physical Backup PostgreSQL provides the following options regarding the backup/recovery strategy: Physical Backup Continuous Archiving and Point-in-Time Recovery (PITR) PostgreSQL Best Practices9/14/201825 #!/bin/bash db_cluster_base="/u01/PosgreSQL" db_cluster_dir="/u01/PosgreSQL/clusterTEST" bckup_start=$(date +"%Y%m%d%H%M") logfile="/u01/PosgreSQL/backup_dir/logs/clusterTEST_backup_$bckup_start.log" backup_dir="/u01/PosgreSQL/backup_dir/clusterTEST" bck_label="Start_Backup_$bckup_start“ ...
  • 26. Backup and Recovery - Physical Backup PostgreSQL Best Practices9/14/201826 ... psql postgres -L $logfile << EOF SELECT pg_start_backup('$bck_label', false, false); ! tar zcvf $backup_dir/backup_$bckup_start.tar.gz --warning=no-file-changed --warning=no-file-removed -C /u01/PosgreSQL clusterTEST --exclude='pg_wal/*‘ --exclude='postmaster*' --exclude='pg_replslot/*' SELECT * FROM pg_stop_backup(false, true); q EOF
  • 28. OLTP Test: PostGreSQL vs Oracle PostgreSQL Best Practices9/14/201828 Goal Use the same type of machine Test the same OLTP workload on both databases Test different CPU allocation Compare the results
  • 29. OLTP Test: PostGreSQL vs Oracle: Configuration PostgreSQL Best Practices9/14/201829 Server details Main host: • 2 * 8 cores CPU E5-2680 0 @ 2.70GHz • OEL 7.2 • 192 GB • Flash Storage volumes on PCIe cards (no NVMe) VMs: • 8 vCPU • 8 GB RAM Concurrent sessions: • 100
  • 30. OLTP Test: PostGreSQL vs Oracle : Configuration PostgreSQL Best Practices9/14/201830 Hammerdbcli PostGreSQL Test Setup dbset db pg diset tpcc pg_defaultdbase hammerdb loadscript vudestroy vuset delay 5 vuset repeat 5 vuset showoutput 1 vuset timestamps 1 vuset logtotemp 1 vuset vu 100 vucreate vurun
  • 31. OLTP Test: PostGreSQL vs Oracle : Configuration PostgreSQL Best Practices9/14/201831 Hammerdbcli Oracle Test Setup dbset db ora diset connection instance jko loadscript vudestroy vuset delay 5 vuset repeat 5 vuset showoutput 1 vuset timestamps 1 vuset logtotemp 1 vuset vu 100 vucreate vurun
  • 32. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201832 PostGreSQL Time to complete the full test  4.23 mn Average CPU Usage  88 % Transaction per minutes max  156’222
  • 33. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201833 Oracle Time to complete the full test  Time 4.12 mn Average CPU Usage  74 % Transaction per minutes max  172’268
  • 34. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201834 select sum(value) from v$sysstat where name = 'user commits' or name = 'user rollbacks' select sum(xact_commit + xact_rollback) from pg_stat_database
  • 35. OLTP Test: PostGreSQL vs Oracle : Configuration PostgreSQL Best Practices9/14/201835 Lets Scale! Main host: • 2 * 8 cores CPU E5-2680 0 @ 2.70GHz • OEL 7.2 • 192 GB • Flash Storage volumes on PCIe cards (no NVMe) VMs: • 16 vCPU • 8 GB RAM Concurrent sessions: • 100
  • 36. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201836 PostGreSQL Time to complete the full test  Time 3.27 mn Average CPU Usage  65 % Transaction per minutes max  194’904
  • 37. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201837 Oracle Time to complete the full test  Time 3.16 mn Average CPU Usage  57 % Transaction per minutes max  251’292
  • 38. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201838 select sum(value) from v$sysstat where name = 'user commits' or name = 'user rollbacks' select sum(xact_commit + xact_rollback) from pg_stat_database
  • 39. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201839 8 vCPU 2.6% Faster 16% Less CPU 9.3% More TPM
  • 40. OLTP Test: PostGreSQL vs Oracle : Results PostgreSQL Best Practices9/14/201840 16 vCPU 3.4% Faster 12.3% Less CPU 22.43% More TPM
  • 42. Conclusions PostgreSQL Best Practices9/14/201842  PostgreSQL is a mature, enterprise RDBMS  PostgreSQL offers good performances  PostgreSQL offers High Availability solution
  • 43. Emilian Fusaglia, Principal Consultant Tel. +41-79-909 7213 Emiliano.Fusaglia@trivadis.com Jacques Kostic, Principal Consultant Tel. +41-79-909 7263 Jacques.Kostic@trivadis.com 9/14/201843 TechEvent September 2018
  • 44. Session Feedback – now TechEvent September 201844 14.09.2018 Please use the Trivadis Events mobile app to give feedback on each session Use "My schedule" if you have registered for a session Otherwise use "Agenda" and the search function If the mobile app does not work (or if you have a Windows smartphone), use your smartphone browser – URL: http://trivadis.quickmobileplatform.eu/ – User name: <your_loginname> (such as "svv") – Password: sent by e-mail...