Skip to main content

Welcome to DBA Master – Database Tips, Tricks, and Tutorials

Welcome to DBA Master ! This blog is dedicated to all things related to database administration , SQL optimization , and performance tuning . Whether you're a beginner or a seasoned DBA, you'll find practical guides, troubleshooting tips, and real-world tutorials to help you work smarter with data. What to Expect: SQL performance tuning tips Indexing strategies Backup and recovery best practices High availability and replication techniques Database creation, configuration, and setup Monitoring queries and scripts for proactive performance management Migration guides across different database platforms Security essentials and best practices Recommended tools for DBAs Real-world error fixes and how to solve them Stay tuned — exciting content is coming soon. Feel free to bookmark and share: www.dbamaster.com ! Thanks for visiting!

Pg_pool-II Installation and Configuration

Pgpool-II is a proxy software that sits between PostgreSQL servers and a PostgreSQL database client.

 It provides the following features:

1.Connection Pooling:

    Pgpool-II maintains established connections to the PostgreSQL servers, and reuses them whenever a new connection with the same properties (i.e. user name, database, protocol version, and other connection parameters if any) comes in. It reduces the connection overhead, and improves system's overall throughput.

2.Load Balancing:

    If a database is replicated (because running in either replication mode or master/slave mode), performing a SELECT query on any server will return the same result. Pgpool-II takes advantage of the replication feature in order to reduce the load on each PostgreSQL server. 

It does that by distributing SELECT queries among available servers, improving the system's overall throughput. In an ideal scenario, read performance could improve proportionally to the number of PostgreSQL servers. Load balancing works best in a scenario where there are a lot of users executing many read-only queries at the same time. 

3.Replication:

    Pgpool-II can manage multiple PostgreSQL servers. Using the replication function enables creating a realtime backup on 2 or more physical disks, so that the service can continue without stopping servers in case of a disk failure.

4.Limiting Exceeding Connections:

    There is a limit on the maximum number of concurrent connections with PostgreSQL, and connections are rejected after this many connections.

5.Watchdog:

    Watchdog can coordinate multiple Pgpool-II, create a robust cluster system and avoid the single point of failure or split brain. Watchdog can perform lifecheck against other pgpool-II nodes, to detect a fault of Pgpoll-II. If active Pgpool-II goes down, standby Pgpool-II can be promoted to active, and take over Virtual IP.

Prerequisite:

  • Allready streaming Replication for mater and slave
  • Allready Configuration for Repmgr 

How to Install Pgpool-II?

yum install pgpool-II-11.x86_64

Bin Path:

/usr/bin/pgpool

Configuration Path:

/etc/pgpool-II-11

Configuration Files:

hba-file:

pool_hba.conf.sample to change pool_hba.conf

config-file:

pgpool.conf.sample-replication to change pgpool.conf

pcp-file:

pcp.conf.sample to change pcp.conf

key-file:

.pgpoolkey  //create file and chown postgres and chmod 600

Edit hba-file:

vi pool_hba.conf

================

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only

local   all         all                               trust

# IPv4 local connections:

host all all 192.168.1.201/32 trust

host all all 192.168.1.202/32 trust

host all all 192.168.1.203/32 trust

host all all 192.168.1.3/32 trust

host    all         all         127.0.0.1/32          trust

host    all         all         ::1/128               trust

=============================================================

Edit config-file:

vi pgpool.conf

==============

listen_addresses = '*'

port = 9999

pcp_listen_addresses = '*'

pcp_port = 9898

backend_hostname0 = '192.168.1.201'

backend_port0 = 5432

backend_weight0 = 1

backend_data_directory0 = '/var/lib/pgsql/11/data'

backend_flag0 = 'ALLOW_TO_FAILOVER'

backend_hostname1 = '192.168.1.202'

backend_port1 = 5432

backend_weight1 = 1

backend_data_directory1 = '/var/lib/pgsql/11/data'

backend_flag1 = 'ALLOW_TO_FAILOVER'

enable_pool_hba = on

log_connections = on

log_hostname = on

log_statement = on

log_per_node_statement = on

pid_file_name = '/var/run/pgpool-II-11/pgpool.pid'

logdir = '/tmp'

replication_mode = on

load_balance_mode = on

master_slave_mode = on

master_slave_sub_mode = 'stream'

sr_check_period = 1

sr_check_user = 'postgres'

sr_check_password = 'post'

sr_check_database = 'postgres'

health_check_period = 1

health_check_timeout = 20

health_check_user = 'postgres'

health_check_password = 'post'

health_check_database = 'postgres'

=====================================================================

Edit pcp-file:

vi pcp.conf

===========

postgres:42b90196b487c54069097a68fe98ab6f //encrypt password

==========================================

how to encrypt password:

[root@server3 pgpool-II-11]# pg_md5 -u postgres -p

password: 

42b90196b487c54069097a68fe98ab6f

Edit key-file:

vi .pgpoolkey

192.168.1.201:5432:postgres:post

192.168.1.202:5432:postgres:post

Run Pgpool-II Tool:

[root@server3 ~]# pgpool -n -D -d

2020-08-02 18:31:02: pid 12518: DEBUG:  initializing pool configuration

2020-08-02 18:31:02: pid 12518: DETAIL:  num_backends: 2 total_weight: 2.000000

2020-08-02 18:31:02: pid 12518: DEBUG:  initializing pool configuration

[root@server3 tools]# pcp_attach_node -U postgres -h 192.168.1.203 -n 0

Password: 

pcp_attach_node -- Command Successful

[root@server3 tools]# pcp_attach_node -U postgres -h 192.168.1.203 -n 1

Password: 

pcp_attach_node -- Command Successful

[root@server3 tools]# pcp_node_count -U postgres

Password: 

2


Comments

Popular posts from this blog

Oracle Database 19C Performance Tunning - PART 1

Advantages: 1. Improved Query Performance •    Optimized SQL execution plans lead to faster query response times. •    Reduces unnecessary full table scans and improves indexing strategies. •    Parallel execution tuning speeds up large data processing tasks. 2. Better Resource Utilization •    Efficient use of CPU, memory, disk I/O, and network resources. •    Reduces contention on Redo Logs, Undo Tablespaces, and Buffer Cache. •    Helps in load balancing across multiple instances in RAC (Real Application Clusters). 3. Increased System Scalability •    Ensures that the database can handle a growing number of users and transactions. •    Proper tuning allows scaling without degrading performance. •    Optimized parallel processing ensures better performance on multi-core servers. 4. Lower Infrastructure Costs •    Reduces the need for add...

Oracle RMAN Backup And Restore

RMAN: (Oracle 8) RMAN (Recovery Manager) is a utility provided by Oracle Database to perform backup, restore, and recovery operations. It is a command line tool. Features of RMAN in Oracle 19c Comprehensive Backup Capabilities: Full and incremental backups. Block-level backups for efficient data storage. Archived redo log backups. Fast Recovery Area (FRA) integration for centralized backup storage. Efficient Recovery Options: Point-in-time recovery (PITR). Complete and incomplete recovery. Flashback database capabilities for quick undo of changes. Multitenant Database Support: RMAN fully supports container databases (CDBs) and pluggable databases (PDBs). Provides flexibility to back up and recover individual PDBs or entire CDBs. Automatic Space Management: Manages disk space in the FRA. Automatically deletes obsolete backups and archived logs. Data Deduplication and Compression: Backup optimization through block-level deduplication. Built-in compression algorithms to reduce storage req...

Oracle 19c Database Software Installation in OEL8

 Pre-requisites for OS level:            Set the static IP Address     Disable the Firewall (systemctl stop firewalld & systemctl disable firewalld)     set SELINUX=permissive on /etc/selinux/config  ##Need to restart the server use init 6 Oracle Installation Pre-requisites Methods     Automatic Setup     Manual Setup      Automatic requisites Setup: (avoid step 1 to step 5): dnf install -y oracle-database-preinstall-19c Install the dependencies: curl -o oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/getPackage/oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm dnf -y localinstall oracle-database-preinstall-19c-1.0-2.el8.x86_64.rpm Manual Setup: step 1: Add the karenl parameters and values vi /etc/sysctl.conf     fs.file-max = 6815744 kernel.sem = 250 32000 100 128 kernel....