Percona Toolkit er et kraftfuldt, gratis og open source-produkt udviklet af Percona. Det er en samling af kommandolinjeværktøjer, der giver dig mulighed for at udføre forskellige MySQL-, MongoDB-, PostgreSQL- og systemopgaver, som generelt er for komplekse til at udføre manuelt. Den understøtter Percona Server til MySQL, MySQL, MariaDB, PostgreSQL, Percona Server til MongoDB og MongoDB.
I denne blog vil vi vise dig, hvordan du installerer Percona Toolkit, og hvordan du bruger et nyt værktøj, der er tilføjet for nylig i Percona Toolkit-pakken kaldet pt-pg-summary.
Installation af Percona Toolkits
Først, lad os se, hvordan man installerer Percona Toolkits for at kunne bruge pt-pg-summary. I dette tilfælde vil vi bruge CentOS 7 og PostgreSQL 12.
Installer Percona Repository:
$ yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
Når lageret er installeret, skulle du være i stand til at installere percona-toolkit-pakken:
$ yum install percona-toolkit
Nu skal du bare køre det med de korrekte parametre.
$ pt-pg-summary --help
usage: pt-pg-summary [<flags>]
Percona Toolkit - PostgreSQL Summary
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--version Show application version.
--databases=DATABASES ... Summarize this comma-separated list of databases. All if not specified
-h, --host=HOST Host to connect to
-W, --password=PASSWORD Password to use when connecting
-p, --port=PORT Port number to use for connection
--sleep=10 Seconds to sleep when gathering status counters
-U, --username=USERNAME User for login if not current user
--disable-ssl Diable SSL for the connection
--verbose Show verbose log
--debug Show debug information in the logs
Kører Percona Toolkits
Når du kører dette værktøj, vil du se et output grupperet efter følgende kategorier:
- Databaseport og Data_Directory
- Liste over Tablespaces
- Slave og forsinkelsen med Master
- Klyngeoplysninger
- Databaser
- Indekscache-hitforhold
- Tabelcache-hitforhold
- Liste over Wait_events for hele klyngen - alle databaser
- Liste over brugere og client_addr eller client_hostname forbundet til --all-databases
- Tællere afviger efter 10 sekunder
- Tabeladgang pr. database
- Forekomstindstillinger
- Behandler startkommando
Så lad os køre det på en PostgreSQL-instans for at se et eksempel:
$ pt-pg-summary -hlocalhost -p5432 -Uadmindb
Den første handling er at indsamle oplysningerne fra din PostgreSQL-server:
INFO[0000] Connecting to the database server using: host=localhost port=5432 user=admindb sslmode=disable dbname=postgres
INFO[0000] Connection OK
INFO[0000] Detected PostgreSQL version: 12.0.5
INFO[0000] Getting global information
INFO[0000] Collecting global counters (1st pass)
INFO[0000] Collecting Cluster information
INFO[0000] Waiting 10 seconds to read counters
INFO[0000] Collecting Connected Clients information
INFO[0000] Collecting Database Wait Events information
INFO[0000] Collecting Global Wait Events information
...
Derefter vil den vise alle de indsamlede oplysninger på denne måde:
##### --- Database Port and Data_Directory --- ####
+----------------------+----------------------------------------------------+
| Name | Setting |
+----------------------+----------------------------------------------------+
| data_directory | /var/lib/pgsql/12/data |
+----------------------+----------------------------------------------------+
##### --- List of Tablespaces ---- ######
+----------------------+----------------------+-----------------------------+
| Name | Owner | Location |
+----------------------+----------------------+-----------------------------+
| pg_default | postgres | |
| pg_global | postgres | |
+----------------------+----------------------+-----------------------------+
##### --- Slave and the lag with Master --- ####
+----------------------+----------------------+------------------+----------+
| Application Name | Client Address | State | Lag |
+----------------------+----------------------+------------------+----------+
| pgsql_14_node_0 | 10.10.10.127 | streaming | 0.00 |
+----------------------+----------------------+------------------+----------+
##### --- Cluster Information --- ####
+---------------------------------------------------------------------------+
Usename : admindb
Time : 2020-11-12 17:27:18.200552 +0000 UTC
Client Address : ::1
Client Hostname:
Version : PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8....
Started : 2020-11-12 17:07:07.185407 +0000 UTC
Is Slave : false
+---------------------------------------------------------------------------+
##### --- Databases --- ####
+----------------------+------------+
| Dat Name | Size |
+----------------------+------------+
| postgres | 8193 kB |
| template1 | 8193 kB |
| template0 | 8049 kB |
+----------------------+------------+
##### --- Index Cache Hit Ratios --- ####
Database: postgres
+----------------------+------------+
| Index Name | Ratio |
+----------------------+------------+
| index hit rate | 0.00 |
+----------------------+------------+
##### --- Table Cache Hit Ratios --- ####
Database: postgres
+----------------------+------------+
| Index Name | Ratio |
+----------------------+------------+
| cache hit rate | 0.00 |
+----------------------+------------+
##### --- List of Wait_events for the entire Cluster - all-databases --- ####
+----------------------+----------------------+---------+
| Wait Event Type | Event | Count |
+----------------------+----------------------+---------+
| Activity | BgWriterHibernate | 1 |
| Activity | WalWriterMain | 1 |
| Activity | LogicalLauncherMain | 1 |
| Activity | WalSenderMain | 1 |
| Client | ClientRead | 2 |
| Activity | CheckpointerMain | 1 |
| Activity | AutoVacuumMain | 1 |
+----------------------+----------------------+---------+
##### --- List of users and client_addr or client_hostname connected to --all-databases --- ####
+----------------------+------------+---------+----------------------+--------+
| Wait Event Type | Client | State | Count |
+----------------------+------------+---------+----------------------+--------+
| admindb | 10.10.10.121/32 | idle | 2 |
| cmon_replication | 10.10.10.127/32 | active | 1 |
| admindb | ::1/128 | active | 1 |
+----------------------+------------+---------+----------------------+--------+
##### --- Counters diff after 10 seconds --- ####
+----------------------+-------------+------------+--------------+-------------+------------+-------------+------------+-------------+------------+------------+-----------+-----------+-----------+------------+
| Database | Numbackends | XactCommit | XactRollback | BlksRead | BlksHit | TupReturned | TupFetched | TupInserted | TupUpdated | TupDeleted | Conflicts | TempFiles | TempBytes | Deadlocks |
+----------------------+-------------+------------+--------------+-------------+------------+-------------+------------+-------------+------------+------------+-----------+-----------+-----------+------------+
| | 0 | 0 | 0 | 0 | 119 | 77 | 31 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| postgres | 0 | 39 | 0 | 0 | 1541 | 1641 | 816 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
...
##### --- Table access per database --- ####
Database: postgres
+----------------------------------------------------+------+--------------------------------+---------+
| Relname | Kind | Datname | Count |
+----------------------------------------------------+------+--------------------------------+---------+
| pg_database_datname_index | i | | 1 |
| pg_class | r | postgres | 1 |
| pg_database | r | | 1 |
...
##### --- Instance settings --- ####
Setting Value
allow_system_table_mods : off
application_name :
archive_cleanup_command :
archive_command : (disabled)
archive_mode : off
archive_timeout : 0
array_nulls : on
authentication_timeout : 60
autovacuum : on
autovacuum_analyze_scale_factor : 0.1
…
##### --- Processes start up command --- ####
PID : Command line
5158 : /usr/pgsql-12/bin/postgres -p 5432
Nu har du alle disse oplysninger, du kan bruge dem til forskellige formål som fejlfinding, ydelsesovervågning eller endda for at få et overblik over din aktuelle konfiguration. Du kan også supplere dette med et andet Percona Toolkit som "pt-summary" for at få mere information om systemet, hvor det kører.
Konklusion
Percona Toolkit er et kraftfuldt værktøj til at hjælpe dig med databasestyringsopgaver. Nu med pt-pg-summary, vil du være i stand til at have information om din PostgreSQL-instans, og du kan integrere denne i et overvågningssystem eller endda kombinere dette værktøj med en anden Percona Toolkit-komponent for at indsamle endnu mere information fra dine systemer.