postgres-toolkit

A collection of scripts and utilities to manage PostgreSQL servers.

Allows DBA to perform complicated tasks with single commands.

Focusing on frequent tasks for PostgreSQL DBA to improve their productivity and quality of operations.

Distributed under the open source license (GPLv2).

Supported OS

For a list of Operating System supported.

Red Hat Enterprise Linux 6 / CentOS 6

Red Hat Enterprise Linux 7 / CentOS 7

Ubuntu 14.04 LTS

Make sure you have Python2.6 or Python2.7 is installed.

PostgreSQL Version

For a list of PostgreSQL supported.

PostgreSQL 9.0

PostgreSQL 9.1

PostgreSQL 9.2

PostgreSQL 9.3

PostgreSQL 9.4

OS:Red Hat Enterprise Linux Server release 6.6 (Santiago)

Monitored PG9.4.5:

host:Node1:192.168.0.113:PG 9.4.5:role:master

host:Node2:192.168.0.114:PG 9.4.5:role:standby

Replication mode:synchronous

Use following command, you can install the toolkit via the Internet

install the toolkit via the Internet.

curl -L http://dl.uptimeforce.com/postgres-toolkit/install.sh | sh
or

wget
http://dl.uptimeforce.com/postgres-toolkit/install.sh

sh install.sh
When the installs are done, copying related files under /opt/uptime/postgres-toolkit-<VERSION>.

following install on the master node

[root@node1 soft_bak]# curl -L http://dl.uptimeforce.com/postgres-toolkit/install.sh | sh

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Dload  Upload   Total   Spent    Left  Speed

105   630  105   630    0     0    554      0  0:00:01  0:00:01 --:--:--  9264

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

Dload  Upload   Total   Spent    Left  Speed

100  276k  100  276k    0     0   292k      0 --:--:-- --:--:-- --:--:--  318k

opt/uptime/postgres-toolkit-0.2.2/

opt/uptime/postgres-toolkit-0.2.2/bin/

opt/uptime/postgres-toolkit-0.2.2/bin/pt-config

opt/uptime/postgres-toolkit-0.2.2/bin/pt-snap-statements

opt/uptime/postgres-toolkit-0.2.2/bin/pt-proc-stat

opt/uptime/postgres-toolkit-0.2.2/bin/pt-session-profiler

opt/uptime/postgres-toolkit-0.2.2/bin/pt-table-usage

opt/uptime/postgres-toolkit-0.2.2/bin/pt-tablespace-usage

opt/uptime/postgres-toolkit-0.2.2/bin/pt-set-tablespace

opt/uptime/postgres-toolkit-0.2.2/bin/pt-replication-stat

opt/uptime/postgres-toolkit-0.2.2/bin/pt-stat-snapshot

opt/uptime/postgres-toolkit-0.2.2/bin/verifychecksum.bin

opt/uptime/postgres-toolkit-0.2.2/bin/pt-kill

opt/uptime/postgres-toolkit-0.2.2/bin/pt-xact-stat

opt/uptime/postgres-toolkit-0.2.2/bin/pt-verify-checksum

opt/uptime/postgres-toolkit-0.2.2/bin/pt-index-usage

opt/uptime/postgres-toolkit-0.2.2/share/

opt/uptime/postgres-toolkit-0.2.2/share/pgperf_snapshot_install92.sql

opt/uptime/postgres-toolkit-0.2.2/share/pgperf_snapshot_install91.sql

opt/uptime/postgres-toolkit-0.2.2/share/pgperf_snapshot_install94.sql

opt/uptime/postgres-toolkit-0.2.2/share/pgperf_snapshot_install90.sql

opt/uptime/postgres-toolkit-0.2.2/share/pgperf_snapshot_install93.sql

opt/uptime/postgres-toolkit-0.2.2/docs/

opt/uptime/postgres-toolkit-0.2.2/docs/ja/

opt/uptime/postgres-toolkit-0.2.2/docs/ja/.buildinfo

opt/uptime/postgres-toolkit-0.2.2/docs/ja/index.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/releasenote.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-index-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/install.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-xact-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-set-tablespace.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/searchindex.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-verify-checksum.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-proc-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/minus.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/down-pressed.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/pygments.css

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/file.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/up-pressed.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/basic.css

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/doctools.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/ajax-loader.gif

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/searchtools.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/default.css

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/comment.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/comment-close.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/plus.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/sidebar.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/comment-bright.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/jquery.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/underscore.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/down.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/up.png

opt/uptime/postgres-toolkit-0.2.2/docs/ja/_static/websupport.js

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pgperf_functions.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-replication-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-snap-statements.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-kill.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-table-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/search.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pgperf_overview.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pgperf_tables.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-session-profiler.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-tablespace-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pgperf_intro.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-stat-snapshot.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/genindex.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/pt-config.html

opt/uptime/postgres-toolkit-0.2.2/docs/ja/objects.inv

opt/uptime/postgres-toolkit-0.2.2/docs/en/

opt/uptime/postgres-toolkit-0.2.2/docs/en/.buildinfo

opt/uptime/postgres-toolkit-0.2.2/docs/en/index.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/releasenote.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-index-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/install.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-xact-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-set-tablespace.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/searchindex.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-verify-checksum.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-proc-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/minus.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/down-pressed.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/pygments.css

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/file.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/up-pressed.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/basic.css

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/doctools.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/ajax-loader.gif

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/searchtools.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/default.css

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/comment.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/comment-close.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/plus.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/sidebar.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/comment-bright.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/jquery.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/underscore.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/down.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/up.png

opt/uptime/postgres-toolkit-0.2.2/docs/en/_static/websupport.js

opt/uptime/postgres-toolkit-0.2.2/docs/en/pgperf_functions.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-replication-stat.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-snap-statements.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-kill.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-table-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/search.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pgperf_overview.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pgperf_tables.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-session-profiler.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-tablespace-usage.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pgperf_intro.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-stat-snapshot.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/genindex.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/pt-config.html

opt/uptime/postgres-toolkit-0.2.2/docs/en/objects.inv

opt/uptime/postgres-toolkit-0.2.2/src/

opt/uptime/postgres-toolkit-0.2.2/src/verifychecksum.c

opt/uptime/postgres-toolkit-0.2.2/lib/

opt/uptime/postgres-toolkit-0.2.2/lib/PsqlWrapper.py

opt/uptime/postgres-toolkit-0.2.2/lib/log.pyc

opt/uptime/postgres-toolkit-0.2.2/lib/PsqlWrapper.pyc

opt/uptime/postgres-toolkit-0.2.2/lib/TcpdumpWrapper.pyc

opt/uptime/postgres-toolkit-0.2.2/lib/DirectoryTree.py

opt/uptime/postgres-toolkit-0.2.2/lib/log.py

opt/uptime/postgres-toolkit-0.2.2/lib/DirectoryTree.pyc

opt/uptime/postgres-toolkit-0.2.2/lib/TcpdumpWrapper.py

opt/uptime/postgres-toolkit-0.2.2/LICENSE

Succeeded to install Postgres Toolkit!

Subscribe now to stay informed of the latest Postgres Toolkit news.

- http://postgres-toolkit.launchrock.com/

The official manual is available online.

- https://postgres-toolkit.readthedocs.org/

- https://postgres-toolkit-ja.readthedocs.org/

Thanks for choosing Postgres Toolkit! Enjoy!

When the installs are done, copying related files under /opt/uptime/postgres-toolkit-<VERSION>.

After installing

[postgres@node1 uptime]$ cd postgres-toolkit-0.2.2/
[postgres@node1 postgres-toolkit-0.2.2]$ ls
bin docs lib LICENSE share src

[root@node1 data]# cd /opt/uptime/postgres-toolkit-0.2.2/bin

[root@node1 bin]# ls

pt-config       pt-kill       pt-replication-stat  pt-set-tablespace   pt-stat-snapshot     pt-table-usage      pt-xact-stat

pt-index-usage  pt-proc-stat  pt-session-profiler  pt-snap-statements  pt-tablespace-usage  pt-verify-checksum  verifychecksum.bin

[postgres@node1 bin]$ ./pt-config --help

Usage: pt-config [option...] [command] [param [value]]

Commands:
get [PARAM] Get a current value of a parameter.
set [PARAM] [VALUE] Set a new value for a parameter.
disable [PARAM] Comment a parameter out.

Options:
-D, --pgdata=PGDATA Specify a PostgreSQL database cluster.
--apply Apply change(s).

--help Print this help.

[postgres@node1 bin]$ ./pt-config -D /usr/local/pg945/data/ get shared_buffers
[2016-01-19 09:46:42] INFO: Reading: /usr/local/pg945/data//postgresql.conf
128MB

[postgres@node1 bin]$ ./pt-config -D /usr/local/pg945/data/ set shared_buffers 512MB
[2016-01-19 09:47:18] INFO: Reading: /usr/local/pg945/data//postgresql.conf
[2016-01-19 09:47:18] INFO: Dry-run mode:
[2016-01-19 09:47:18] INFO: Old: shared_buffers = 128MB # min 128kB
[2016-01-19 09:47:18] INFO: New: shared_buffers = 512MB # min 128kB

[postgres@node1 bin]$ ./pt-config -D /usr/local/pg945/data/ --apply disable shared_buffers
[2016-01-19 09:48:44] INFO: Reading: /usr/local/pg945/data//postgresql.conf
[2016-01-19 09:48:44] INFO: Applying:
[2016-01-19 09:48:44] INFO: Old: shared_buffers = 128MB # min 128kB
[2016-01-19 09:48:44] INFO: New: #shared_buffers = 128MB # min 128kB
[2016-01-19 09:48:44] INFO: Updated: /usr/local/pg945/data//postgresql.conf

[postgres@node1 bin]$ ./pt-index-usage --help

Usage: pt-index-usage [option...]

Options:
-h, --host=HOSTNAME Host name of the postgres server
-p, --port=PORT Port number of the postgres server
-U, --username=USERNAME User name to connect
-d, --dbname=DBNAME Database name to connect

-o, --owner=STRING Owner name
-n, --schema=STRING Schema name
-t, --table=STRING Table name
-i, --index=STRING Index name

--help Print this help.

[postgres@node1 bin]$ ./pt-index-usage /usr/local/pg945/bin/psql -h localhost -p 5432 -U postgres -n public -d postgres
+-------+----------+--------+------------------+-----------------------+-------+--------+--------+--------+--------+--------+--------+------------+
| OID | OWNER | SCHEMA | TABLE | INDEX | BLKS | SCAN | T_READ | T_FTCH | B_READ | B_HIT | STATUS | TABLESPACE |
+-------+----------+--------+------------------+-----------------------+-------+--------+--------+--------+--------+--------+--------+------------+
| 16414 | postgres | public | pgbench_accounts | pgbench_accounts_pkey | 27422 | 149972 | 210520 | 149972 | 74399 | 557402 | | pg_default |
| 16410 | postgres | public | pgbench_branches | pgbench_branches_pkey | 2 | 0 | 0 | 0 | 38 | 112 | | pg_default |
| 16412 | postgres | public | pgbench_tellers | pgbench_tellers_pkey | 7 | 74986 | 75292 | 74986 | 10 | 151488 | | pg_default |
+-------+----------+--------+------------------+-----------------------+-------+--------+--------+--------+--------+--------+--------+------------+

[postgres@node1 bin]$ ./pt-replication-stat --help

Usage: pt-replication-stat [option...] [delay [count]]

Options:
-h, --host=HOSTNAME Host name of the postgres server
-p, --port=PORT Port number of the postgres server
-U, --username=USERNAME User name to connect
-d, --dbname=DBNAME Database name to connect

--help Print this help.

[postgres@node1 bin]$ ./pt-replication-stat -h localhost -p 5432 -U postgres 5 2
Tue Jan 19 09:53:58 CST 2016
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+
| PID | NAME | HOST | PORT | STATE | SENT | WRITTTEN | FLUSHED | REPLAYED | PRI | MODE |
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+
| | | | | local | 0/DA000350 | 0/DA000350 | | | | master |
| 1353 | node2 | 192.168.0.114 | 41205 | streaming | 0/DA000350 | 0/DA000350 | 0/DA000350 | 0/DA000350 | 1 | sync |
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+

Tue Jan 19 09:54:03 CST 2016
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+
| PID | NAME | HOST | PORT | STATE | SENT | WRITTTEN | FLUSHED | REPLAYED | PRI | MODE |
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+
| | | | | local | 0/DA000350 | 0/DA000350 | | | | master |
| 1353 | node2 | 192.168.0.114 | 41205 | streaming | 0/DA000350 | 0/DA000350 | 0/DA000350 | 0/DA000350 | 1 | sync |
+------+-------+---------------+-------+-----------+------------+------------+------------+------------+-----+--------+

[postgres@node1 bin]$ ./pt-proc-stat -D /usr/local/pg945/data/ 10 5
Tue Jan 19 09:57:49 CST 2016
PROCESS NAME[ PID] STAT USR SYS VSZ RSS READ WRITE READ2 WRITE2
postgres[ 1344] S 0 1 256 12 2200 304 6004 -40
logger[ 1345] S 0 0 113 0 0 4 0 -4
checkpointer[ 1347] S 0 0 256 2 0 60 0 -12
writer[ 1348] S 1 2 256 2 0 0 0 0
wal writer[ 1349] S 0 1 256 5 0 32 0 0
autovacuum launcher[ 1350] S 0 0 256 1 0 0 98 0
archiver[ 1351] S 0 0 115 0 0 0 0 0
stats collector[ 1352] S 0 2 115 1 0 876 19 -391
DA000350[ 1353] S 0 1 257 2 0 0 16393 0

Tue Jan 19 09:57:59 CST 2016
PROCESS NAME[ PID] STAT USR SYS VSZ RSS READ WRITE READ2 WRITE2
postgres[ 1344] S 0 0 256 12 0 0 0 0
logger[ 1345] S 0 0 113 0 0 0 0 0
checkpointer[ 1347] S 0 0 256 2 0 0 0 0
writer[ 1348] S 0 0 256 2 0 0 0 0
wal writer[ 1349] S 0 0 256 5 0 0 0 0
autovacuum launcher[ 1350] S 0 0 256 1 0 0 0 0
archiver[ 1351] S 0 0 115 0 0 0 0 0
stats collector[ 1352] S 0 0 115 1 0 0 0 0
DA000350[ 1353] S 0 0 257 2 0 0 0 0

Tue Jan 19 09:58:09 CST 2016
PROCESS NAME[ PID] STAT USR SYS VSZ RSS READ WRITE READ2 WRITE2
postgres[ 1344] S 0 0 256 12 0 0 143 0
logger[ 1345] S 0 0 113 0 0 0 0 0
checkpointer[ 1347] S 0 0 256 2 0 0 0 0
writer[ 1348] S 0 0 256 2 0 0 0 0
wal writer[ 1349] S 0 0 256 5 0 0 0 0
autovacuum launcher[ 1350] S 0 0 256 1 0 0 2 0
archiver[ 1351] S 0 0 115 0 0 0 0 0
stats collector[ 1352] S 0 0 115 1 0 24 0 -10
DA000350[ 1353] S 0 0 257 2 0 0 0 0

Tue Jan 19 09:58:19 CST 2016
PROCESS NAME[ PID] STAT USR SYS VSZ RSS READ WRITE READ2 WRITE2
postgres[ 1344] S 0 0 256 12 0 0 0 0
logger[ 1345] S 0 0 113 0 0 0 0 0
checkpointer[ 1347] S 0 0 256 2 0 0 0 0
writer[ 1348] S 0 0 256 2 0 0 0 0
wal writer[ 1349] S 0 0 256 5 0 0 0 0
autovacuum launcher[ 1350] S 0 0 256 1 0 0 0 0
archiver[ 1351] S 0 0 115 0 0 0 0 0
stats collector[ 1352] S 0 0 115 1 0 0 0 0
DA000350[ 1353] S 0 0 257 2 0 0 0 0

Tue Jan 19 09:58:29 CST 2016
PROCESS NAME[ PID] STAT USR SYS VSZ RSS READ WRITE READ2 WRITE2
postgres[ 1344] S 0 0 256 12 0 0 0 0
logger[ 1345] S 0 0 113 0 0 0 0 0
checkpointer[ 1347] S 0 0 256 2 0 0 0 0
writer[ 1348] S 0 0 256 2 0 0 0 0
wal writer[ 1349] S 0 0 256 5 0 0 0 0
autovacuum launcher[ 1350] S 0 0 256 1 0 0 0 0
archiver[ 1351] S 0 0 115 0 0 0 0 0
stats collector[ 1352] S 0 0 115 1 0 0 0 0
DA000350[ 1353] S 0 0 257 2 0 0 0 0

[postgres@node1 bin]$ ./pt-table-usage -d postgres
+-------+----------+--------+------------------+--------+-------+----------+----------+-------+-------+--------+--------+---------------------+---------------------+------------+
| OID | OWNER | SCHEMA | TABLE | BLKS | SCAN | T_READ | T_INS | T_UPD | T_DEL | B_READ | B_HIT | VACUUMED | ANALYZED | TABLESPACE |
+-------+----------+--------+------------------+--------+-------+----------+----------+-------+-------+--------+--------+---------------------+---------------------+------------+
| 16403 | postgres | public | pgbench_accounts | 164936 | 1 | 10000000 | 10000000 | 74986 | 0 | 597553 | 557725 | 2016-01-18 15:27:08 | 2016-01-18 15:27:08 | pg_default |
| 16406 | postgres | public | pgbench_branches | 2 | 79234 | 7498700 | 100 | 74984 | 0 | 127 | 237473 | 2016-01-18 16:03:26 | 2016-01-18 16:03:26 | pg_default |
| 16397 | postgres | public | pgbench_history | 374 | 0 | 0 | 74983 | 0 | 0 | 3732 | 76579 | 2016-01-18 15:27:10 | 2016-01-18 16:03:23 | pg_default |
| 16400 | postgres | public | pgbench_tellers | 16 | 1 | 1000 | 1000 | 74986 | 0 | 129 | 155327 | 2016-01-18 16:03:25 | 2016-01-18 16:03:25 | pg_default |
+-------+----------+--------+------------------+--------+-------+----------+----------+-------+-------+--------+--------+---------------------+---------------------+------------+

[postgres@node1 bin]$ ./pt-tablespace-usage -d postgres
+------------+-----------+-----------+
| TABLESPACE | DBNAME | SIZE (MB) |
+------------+-----------+-----------+
| pg_default | postgres | 1512 |
| pg_default | template1 | 6 |
| pg_global | | 1 |
+------------+-----------+-----------+

pt-snap-statements:requirement

postgresql.conf

shared_preload_libraries = 'pg_stat_statements'

pg_stat_statements.max = 10000
pg_stat_statements.track = all

track_io_timing = on

[postgres@node1 bin]$ ./pt-snap-statements -d postgres 5
+----------+----------+----------+--------------------------------+-------+--------+------+-------+--------+--------+--------+---------+--------+
| USER | DBNAME | QUERYID | QUERY | CALLS | T_TIME | ROWS | B_HIT | B_READ | B_DIRT | B_WRTN | R_TIME | W_TIME |
+----------+----------+----------+--------------------------------+-------+--------+------+-------+--------+--------+--------+---------+--------+
| postgres | postgres | d0679a75 | UPDATE pgbench_accounts SET ab | 246 | 19354 | 246 | 1604 | 504 | 392 | 1 | 19324.8 | 0.0 |
| postgres | postgres | 67ecc2d2 | UPDATE pgbench_branches SET bb | 246 | 1202 | 246 | 834 | 3 | 2 | 0 | 0.0 | 0.0 |
| postgres | postgres | d348561c | UPDATE pgbench_tellers SET tba | 246 | 5 | 246 | 985 | 0 | 0 | 0 | 0.0 | 0.0 |
| postgres | postgres | fa9b0052 | SELECT abalance FROM pgbench_a | 246 | 4 | 246 | 1131 | 0 | 0 | 0 | 0.0 | 0.0 |
| postgres | postgres | db71f8b2 | INSERT INTO pgbench_history (t | 246 | 3 | 246 | 246 | 0 | 0 | 0 | 0.0 | 0.0 |
| postgres | postgres | d4e6bf94 | BEGIN; | 250 | 0 | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 |
| postgres | postgres | a81672e | END; | 246 | 0 | 0 | 0 | 0 | 0 | 0 | 0.0 | 0.0 |
+----------+----------+----------+--------------------------------+-------+--------+------+-------+--------+--------+--------+---------+--------+

pt-stat-snapshot

[postgres@node1 bin]$ ./pt-stat-snapshot --help

Usage: pt-stat-snapshot [option...] install
pt-stat-snapshot [option...] create [level]
pt-stat-snapshot [option...] list
pt-stat-snapshot [option...] delete [sid]
pt-stat-snapshot [option...] export [file]
pt-stat-snapshot [option...] import [file]
pt-stat-snapshot [option...] uninstall

Options:
-h, --host=HOSTNAME Host name of the postgres server
-p, --port=PORT Port number of the postgres server
-U, --username=USERNAME User name to connect
-d, --dbname=DBNAME Database name to connect

--help Print this help.

[postgres@node1 bin]$ ./pt-stat-snapshot -h localhost -U postgres -d postgres install
[2016-01-19 10:29:41] INFO: Succeeded to install pgperf snapshot.

[postgres@node1 bin]$ ./pt-stat-snapshot -h localhost -U postgres -d postgres create 4
[2016-01-19 10:35:56] INFO: Succeeded to take a snapshot.

[postgres@node1 bin]$ ./pt-stat-snapshot -h localhost -U postgres -d postgres list
+-----+---------------------+-------+
| SID | TIMESTAMP | LEVEL |
+-----+---------------------+-------+
| 0 | 2016-01-19 10:32:00 | 4 |
+-----+---------------------+-------+

[postgres@node1 bin]$ ./pt-stat-snapshot -h localhost -U postgres -d postgres uninstall
[2016-01-19 10:38:03] INFO: Succeeded to uninstall pgperf snapshot.

pt-xact-stat

[postgres@node1 bin]$ ./pt-xact-stat --host-list 192.168.0.113:5432,192.168.0.114:5432 -d postgres 5 2
Tue Jan 19 10:44:01 CST 2016
+---------------+------+----------+------+---------+-----------+---------+---------+
| HOST | PORT | DBNAME | CONN | COMMITS | ROLLBACKS | B_READ | B_HIT |
+---------------+------+----------+------+---------+-----------+---------+---------+
| 192.168.0.113 | 5432 | postgres | 11 | 102180 | 11 | 1091476 | 2571606 |
| 192.168.0.114 | 5432 | postgres | 1 | 5 | 0 | 81 | 1158 |
+---------------+------+----------+------+---------+-----------+---------+---------+

Tue Jan 19 10:44:06 CST 2016
+---------------+------+----------+------+---------+-----------+---------+---------+
| HOST | PORT | DBNAME | CONN | COMMITS | ROLLBACKS | B_READ | B_HIT |
+---------------+------+----------+------+---------+-----------+---------+---------+
| 192.168.0.113 | 5432 | postgres | 11 | 102955 | 11 | 1093119 | 2586571 |
| 192.168.0.114 | 5432 | postgres | 1 | 7 | 0 | 81 | 1345 |
+---------------+------+----------+------+---------+-----------+---------+---------+

sourcecode :https://github.com/uptimejp/postgres-toolkit

document :http://postgres-toolkit.readthedocs.org/

postgres-toolkit (A Victorinox for PostgreSQL DBA )的更多相关文章

  1. postgresql dba常用sql查询语句

    查看帮助命令 DB=# help --总的帮助 DB=# \h --SQL commands级的帮助 DB=# \? --psql commands级的帮助 \dn[S+] [PATTERN],其中[ ...

  2. 修改PostgreSQL数据库的默认用户postgres的密码

    有时候,忘记了postgresql 安装时默认用户postgres 的密码,怎么办呢? linux shell命令下面输入: sudo -u postgres psql  (这样就可以直接登录进pos ...

  3. 云原生 PostgreSQL 集群 - PGO:来自 Crunchy Data 的 Postgres Operator

    使用 PGO 在 Kubernetes 上运行 Cloud Native PostgreSQL:来自 Crunchy Data 的 Postgres Operator! Cloud Native Po ...

  4. PostgreSQL相关的软件,库,工具和资源集合

    PostgreSQL相关的软件,库,工具和资源集合. 备份 wal-e - Simple Continuous Archiving for Postgres to S3, Azure, or Swif ...

  5. PostgreSQL&PostGIS完全安装

    检查PostGIS.PostgreSQL.GEOS.GDAL.PROJ等各软件的版本依赖关系 http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQ ...

  6. Top PG Clustering HA Solutions for PostgreSQL

    转自:https://severalnines.com/blog/top-pg-clustering-ha-solutions-postgresql If your system relies on  ...

  7. 数据库并发事务控制四:postgresql数据库的锁机制二:表锁 <转>

    在博文<数据库并发事务控制四:postgresql数据库的锁机制 > http://blog.csdn.net/beiigang/article/details/43302947 中后面提 ...

  8. PostgreSQL数据库资料(转)

    PostgreSQL数据库资料 转自:http://blog.csdn.net/postgrechina/article/details/49132791 推荐书籍: 概念书籍: <Postgr ...

  9. PostgreSQL的架构

    是最先进的数据库.他的第一个版本在1989年发布,从那时开始,他得到了很多扩展.根据db-enginers上的排名情况,PostgreSQL目前在数据库领域排名第四. 本篇博客,我们来讨论一下Post ...

随机推荐

  1. LR中的编码问题

    [转载]LoadRunner字符集与检查点的探讨 很多人在loadrunner测试脚本中加入中文检查点的时候会出现检查失败的情况,究竟是为什么呢?其实是被测试系统与loadrunner字符集之间的转换 ...

  2. breadth-first depth-first best-first

    Computer Science An Overview _J. Glenn Brookshear _11th Edition For our example in Figure 11.7, we c ...

  3. Greedy_algorithm

    https://en.wikipedia.org/wiki/Greedy_algorithm

  4. P2409 Y的积木

    luogu月赛 暴力dfs,估计过不了几个点,大概也就得30分左右? #include <bits/stdc++.h> using namespace std; const int max ...

  5. JStack分析cpu消耗过高问题

    Mark一下, 今天确实用这个方法找到了问题 http://www.iteye.com/topic/1114219 1. top找到目标进程,记下pid 2. top –p pid, 并用shift+ ...

  6. uuu

    #include<stdio.h> int map[10][10]={0}; int step[30]={0}; int max=99999; int q; int ans[99]={0} ...

  7. 抓包工具Charles 【转】

      今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/1 ...

  8. 局部变量、结构体和main函数

    在函数中定义的变量称为自动局部变量.因为每次调用该函数时,它们都自动“创建”,并且它们的只对于函数来说是局部的,局部对象的变量都会默认为空.局部变量的值只能在定义该变量的函数中访问,不能从函数之外访问 ...

  9. 修改delphi xe6 FMX Label字体颜色

    delphi fmx的字体等设置默认与皮肤有关,用代码直接修改字体颜色等是无效的,如何才能用代码修改呢?请按以下方法就可以: 1.在Object inspector中取消StlyedSettings中 ...

  10. php--validate错误信息提示样式

    //validate  错误信息提示样式  可以提示错误信息 可以使用jq 自带的属性改变错误的显示的位置,其中element是验证未通过的当前表单元素,error为错误后的提示信息 [注意]:放的位 ...