Professional Documents
Culture Documents
Digoal.zhou
Monday, October 14, 2013
2013 PostgreSQL China Conference
SKYMOBI, Hangzhou, Zhejiang
Agenda
systemtap
PostgreSQL
PostgreSQL
PostgreSQL
PostgreSQLLinux
stap5:
2. ,,,,
3. C
/root/.systemtap/cache/e8/stap_e878009262b7836eb07f0b5a0bf0705e_970.c
4. Linux
/root/.systemtap/cache/e8/stap_e878009262b7836eb07f0b5a0bf0705e_970.ko
5. , . stap
. staprun ko, stap.
stapPostgreSQL, , ().
http://blog.163.com/digoal@126/blog/static/163877040201391434530674/
systemtap
, (64bit), ,
(64bit)
(+,-,!,~,++,--) (,,,,,)
, a ? b : c: ab, c
. ()
-> field
/* */ , # , //
systemtap
try/catch
delete
EXP (expression)
for
foreach
if
next
; (null statement)
return
{ } (statement block)
while
systemtap
function:ret_type (par1:type1,)
Embbed C
%{
#include <linux/in.h>
#include <linux/ip.h>
CATCH_DEREF_FAULT();
function is_tcp_packet:long(iphdr) {
systemtap
()
(@var(varname), $varname )
global var1
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__done") {
lv=$1
var1=@2
println($$locals)
exit()
context var: B
systemtap
MAXNESTING - The maximum number of recursive function call levels. The default is 10.
MAXSTRINGLEN - The maximum length of strings. The default is 256 bytes for 32 bit machines and 512 bytes for all other
machines.
MAXTRYLOCK - The maximum number of iterations to wait for locks on global variables before declaring possible deadlock
and skipping the probe. The default is 1000.
MAXACTION - The maximum number of statements to execute during any single probe hit. The default is 1000.
MAXMAPENTRIES - The maximum number of rows in an array if the array size is not specified explicitly when declared.
The default is 2048.
MAXERRORS - The maximum number of soft errors before an exit is triggered. The default is 0.
MAXSKIPPED - The maximum number of skipped reentrant probes before an exit is triggered. The default is 100.
MINSTACKSPACE - The minimum number of free kernel stack bytes required in order to run a probe handler. This number
should be large enough for the probe handler's own needs, plus a safety margin. The default is 1024.
stap -D
systemtap
stap.
@define foo %( x %)
@foo = @add(2,2)
@define foo %(
%( CONFIG_UTRACE == "y" %? process.syscall %: **ERROR** %)
%)
%( CONDITION %? TRUE-TOKENS %)
%( 1!=1
%?
%:
%)
false
This divides the event namespace into parts, analogous to the style of the Domain Name
System. .,dns.
kernel.function("foo")
kernel.function("foo").return
Module("ext3).function("ext3_*")
kernel.function("no_such_function") ?
syscall.*
end
timer.ms(5000)
DWARF(debuginfo)
kernel.function(PATTERN)
kernel.function(PATTERN).call
kernel.function(PATTERN).return
kernel.function(PATTERN).return.maxactive(VALUE)
kernel.function(PATTERN).inline
kernel.function(PATTERN).label(LPATTERN)
module(MPATTERN).function(PATTERN)
module(MPATTERN).function(PATTERN).call
module(MPATTERN).function(PATTERN).return.maxactive(VALUE)
module(MPATTERN).function(PATTERN).inline
kernel.statement(PATTERN)
kernel.statement(ADDRESS).absolute
module(MPATTERN).statement(PATTERN)
DWARF-LESS(debuginfo, kprobe)
In the absence of debugging information, you can still use the kprobe family of probes to examine the entry
and exit points of kernel and module functions. You cannot look up the arguments or local variables of a
function using these probes.
asmlinkage ssize_t sys_read (unsigned int fd, char __user * buf, size_t count)
You can obtain the values of fd, buf, and count, respectively, as uint_arg(1), pointer_arg(2),
and ulong_arg(3). In this case, your probe code must first call asmlinkage(), because on some architectures
the asmlinkage attribute affects how the function's arguments are passed.
[root@db- ~]# stap -e 'probe kprobe.function("tcp_v4_connect") {asmlinkage(); printf("%s, %d, %d, 0x%x,
0x%x, %d\n", pp(), pid(), cpu(), pointer_arg(1), pointer_arg(2), uint_arg(3));}'
userspace probe
process("PATH").begin PATH$PATH
. .
process(PID).begin IDPID
, .
process.thread.begin
process("PATH").thread.begin
process(PID).thread.begin
.end . .
process.end
process("PATH").end
process(PID).end
process.thread.end
process("PATH").thread.end
process(PID).thread.end
userspace probe
.(debuginfo)
process("PATH").function("NAME")
process("PATH").statement("*@FILE.c:123")
process("PATH").function("*").return
process("PATH").function("myfun").label("foo")
Full symbolic source-level probes in userspace programs and shared libraries are supported.
These are exactly analogous to the symbolic DWARF-based kernel or module probes described previously
and expose similar contextual $-variables.
}' \
-c 'ls -l'
To run, this script requires debugging information for the named program and utrace support in the kernel.
If you see a "pass 4a-time" build failure, check that your kernel supports utrace.
userspace probe
process.syscall
process("PATH").syscall
process(PID).syscall
process.syscall.return
process("PATH").syscall.return
process(PID).syscall.return
.return$arg, $return.
.return @entry() , . :
gettimeofday_ns() - @entry(gettimeofday_ns())
Target process mode (invoked with stap -c CMD or -x PID) implicitly restricts all process.* probes to the
given child process.
pg94
process.*, .
[root@db-172-16-3-39 ~]# stap -x 15967 -e 'probe process.syscall {printf("%s, %s, %d\n", pp(), execname(),
$syscall); }'
process.syscall, postgres, 23
-x. stapio
[root@db-172-16-3-39 ~]# stap -x 15967 -e 'probe syscall.* {printf("%s, %s\n", pp(), execname()); exit();}'
kernel.function("sys_fcntl@fs/fcntl.c:357").call?, stapio
15967
1 0 Sep29 ?
00:00:00 /home/pg94/pgsql9.4devel/bin/postgres
(process(PATH)PATH)
[root@db-172-16-3-39 lib]# stap --download-debuginfo=yes -e 'probe process("/usr/local/lib/libevent1.4.so.2.2.0").function("*") { printf ("%s, %s\n", pp(), execname()); } probe timer.s(1) {exit();}'
process("/usr/local/lib/libevent-1.4.so.2.2.0").function("evsignal_process@/opt/soft_bak/libevent-1.4.14bstable/signal.c:314"), rpc.idmapd
process("/usr/local/lib/libevent-1.4.so.2.2.0").function("timeout_process@/opt/soft_bak/libevent-1.4.14bstable/event.c:927"), rpc.idmapd
[root@db-172-16-3-39 lib]# stap -e 'probe process("/usr/sbin/rpc.idmapd").library("/usr/local/lib/libevent1.4.so.2.2.0").function("*") { printf ("%s, %s, %s\n", pp(), execname(), $$vars); } probe timer.s(1) {exit();}'
userspace probe - |
process("PATH").insn
process(PID).insn
process("PATH").insn.block
process(PID).insn.block
0.9.5
-c /bin/ls
This feature can slow down execution of a process somewhat.
userspace probe -
process("PATH").mark("LABEL")
, , 1-12. :
STAP_PROBE[1-12](handle,LABEL[,arg1-12])
DTRACE_PROBE[1-12](handle,LABEL[,arg1-12])
, $varname@var("varname@src.c")
/usr/include/sys/sdt.h
http://blog.163.com/digoal@126/blog/static/163877040201383044341926/
(systemtap), :
http://blog.163.com/digoal@126/blog/static/163877040201396882559/
http://blog.163.com/digoal@126/blog/static/1638770402013971009843/
http://blog.163.com/digoal@126/blog/static/16387704020139710289441/
http://blog.163.com/digoal@126/blog/static/163877040201397112435514/
http://blog.163.com/digoal@126/blog/static/16387704020139752612312/
http://blog.163.com/digoal@126/blog/static/1638770402013978959440/
userspace probe -
1. /usr/include/sys/sdt.h
#define DTRACE_PROBE(provider,probe)
STAP_PROBE(provider,probe)
#define DTRACE_PROBE1(provider,probe,parm1)
STAP_PROBE1(provider,probe,parm1)
#define DTRACE_PROBE2(provider,probe,parm1,parm2)
STAP_PROBE2(provider,probe,parm1,parm2)
...
#define
DTRACE_PROBE12(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,
parm11,parm12) \
STAP_PROBE12(provider,probe,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10,par
m11,parm12)
userspace probe -
#include <sys/sdt.h>
#else
#endif
#define TRACE_POSTGRESQL_TRANSACTION_START(arg1) \
DTRACE_PROBE1(postgresql,transaction__start,arg1)
TRACE_POSTGRESQL_TRANSACTION_START(arg1)PostgreSQL, mark.
userspace probe -
3. PostgreSQL - src/include/pg_trace.h
#include "utils/probes.h"
src/backend/access/transam/xact.c
#include "pg_trace.h"
...
static void
StartTransaction(void)
TransactionState s;
VirtualTransactionId vxid;
/* pgrminclude ignore */
...
Assert(MyProc->backendId == vxid.backendId);
MyProc->lxid = vxid.localTransactionId;
TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
...
userspace probe -
transaction__start :
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__start")
, :
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__start") {
println($$locals$$)
println($arg1)
}'
2 239116
239116
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
Name
transaction-start
transaction-commit
transaction-abort
Parameters
Description
(LocalTransactionId)
(LocalTransactionId)
(LocalTransactionId)
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP : , , :
RETURNS void
LANGUAGE plpgsql
STRICT
AS $function$
declare
begin
end if;
return;
return;
end;
$function$;
digoal=# create table test(id int primary key, info text, crt_time timestamp);
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP : , , :
vi test.sql
\setrandom id 1 5000000
select f_test(:id);
stap -e '
global var1
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__start") {
var1["START"]++
}
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__commit") {
var1["COMMIT"]++
}
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__abort") {
var1["ABORT"]++
}
probe timer.s(1) {
printf("START/s:%d, COMMIT/s:%d, ABORT/s:%d\n", var1["START"], var1["COMMIT"], var1["ABORT"])
var1["START"]=0
var1["COMMIT"]=0
var1["ABORT"]=0
}'
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP : , , :
scaling factor: 1
number of clients: 8
number of threads: 1
duration: 10 s
0.001609
\setrandom id 1 5000000
0.451537
select f_test(:id);
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP : , , :
stap :
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP2 : ,
stap -e '
probe begin {
var4=gettimeofday_ms()
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__start") {
var1[pid(),$arg1] = gettimeofday_ms()
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__commit") {
if (var1[pid(),$arg1] != 0)
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("transaction__abort") {
if (var1[pid(),$arg1] != 0)
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP2 : , commit/s,
probe timer.s($1) {
now=gettimeofday_ms()
if (@count(var2) != 0) {
println(@hist_log(var2))
delete var2
if (@count(var3) != 0) {
println(@hist_log(var3))
delete var3
var4=now
}' 3
commit/s,
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201391684012713/
EXP2 : , commit/s,
COMMIT/s:16364
0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39936
1 |@@@@@@@@@@@
2|
20
4|
8|
9137
COMMIT/s:16427
0 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39927
1 |@@@@@@@@@@@
2|
10
4|
8|
... ,
9346
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
query-start
(const char *) Probe that fires when the processing of a query is started. arg0 is the query string.
query-done
(const char *) Probe that fires when the processing of a query is complete. arg0 is the query string.
query-parse-start
(const char *) Probe that fires when the parsing of a query is started. arg0 is the query string.
query-parse-done
(const char *) Probe that fires when the parsing of a query is complete. arg0 is the query string.
query-rewrite-start (const char *) Probe that fires when the rewriting of a query is started. arg0 is the query string.
query-rewritedone
(const char *) Probe that fires when the rewriting of a query is complete. arg0 is the query string.
query-plan-start
()
query-plan-done
()
()
()
query-executestart
query-executedone
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
EXP : simpleextended
vi test.sql
select clock_timestamp();
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
stap -e '
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start") {
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start") {
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__rewrite__start") {
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start") {
println(pn(), pid())
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start") {
println(pn(), pid())
}'
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
simple
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__rewrite__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__rewrite__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__rewrite__start")select clock_timestamp();14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14146
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14146
...
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
extended
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14140
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14140
...
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916101117367/
prepare
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__parse__start")select clock_timestamp();14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__plan__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__execute__start")14143
PostgreSQL
checkpoint
http://blog.163.com/digoal@126/blog/static/163877040201391622459221/
checkpoint-start
(int)
Probe that fires when a checkpoint is started. arg0 holds the bitwise flags used to
distinguish different checkpoint types, such as shutdown, immediate or force.
Probe that fires when a checkpoint is complete. (The probes listed next fire in
(int, int, int, sequence during checkpoint processing.) arg0 is the number of buffers written. arg1
checkpoint-done
int, int)
is the total number of buffers. arg2, arg3 and arg4 contain the number of xlog file(s)
added, removed and recycled respectively.
Probe that fires when the CLOG portion of a checkpoint is started. arg0 is true for
clog-checkpoint-start (bool)
normal checkpoint, false for shutdown checkpoint.
Probe that fires when the CLOG portion of a checkpoint is complete. arg0 has the
clog-checkpoint-done (bool)
same meaning as for clog-checkpoint-start.
subtrans-checkpointProbe that fires when the SUBTRANS portion of a checkpoint is started. arg0 is true
(bool)
start
for normal checkpoint, false for shutdown checkpoint.
subtrans-checkpointProbe that fires when the SUBTRANS portion of a checkpoint is complete. arg0 has
(bool)
done
the same meaning as for subtrans-checkpoint-start.
multixact-checkpointProbe that fires when the MultiXact portion of a checkpoint is started. arg0 is true for
(bool)
start
normal checkpoint, false for shutdown checkpoint.
multixact-checkpoint(bool)
done
Probe that fires when the MultiXact portion of a checkpoint is complete. arg0 has the
same meaning as for multixact-checkpoint-start.
PostgreSQL
checkpoint
http://blog.163.com/digoal@126/blog/static/163877040201391622459221/
buffer-checkpoint-start
(int)
buffer-sync-start
(int,
int)
buffer-sync-written
(int)
buffer-sync-done
(int,
int,
int)
buffer-checkpoint-sync-start
()
buffer-checkpoint-done
twophase-checkpoint-start
twophase-checkpoint-done
()
()
()
Probe that fires when the buffer-writing portion of a checkpoint is started. arg0 holds
the bitwise flags used to distinguish different checkpoint types, such as shutdown,
immediate or force.
Probe that fires when we begin to write dirty buffers during checkpoint (after
identifying which buffers must be written). arg0 is the total number of buffers. arg1 is
the number that are currently dirty and need to be written.
Probe that fires after each buffer is written during checkpoint. arg0 is the ID number
of the buffer.
Probe that fires when all dirty buffers have been written. arg0 is the total number of
buffers. arg1 is the number of buffers actually written by the checkpoint process. arg2
is the number that were expected to be written (arg1 of buffer-sync-start); any
difference reflects other processes flushing buffers during the checkpoint.
Probe that fires after dirty buffers have been written to the kernel, and before starting
to issue fsync requests.
Probe that fires when syncing of buffers to disk is complete.
Probe that fires when the two-phase portion of a checkpoint is started.
Probe that fires when the two-phase portion of a checkpoint is complete.
PostgreSQL
checkpoint
http://blog.163.com/digoal@126/blog/static/163877040201391622459221/
EXP : checkpoint__done
262144
EXP : checkpointvfs.write ,
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
bufferread-start
(ForkNumber,
BlockNumber,
Oid, Oid, Oid,
int, bool)
(ForkNumber,
bufferBlockNumber,
read-done Oid, Oid, Oid,
int, bool, bool)
(ForkNumber,
bufferBlockNumber,
flush-start
Oid, Oid, Oid)
(ForkNumber,
bufferBlockNumber,
flush-done
Oid, Oid, Oid)
Probe that fires when a buffer read is started. arg0 and arg1 contain the fork and block
numbers of the page (but arg1 will be -1 if this is a relation extension request). arg2, arg3,
and arg4 contain the tablespace, database, and relation OIDs identifying the relation. arg5 is
the ID of the backend which created the temporary relation for a local buffer, or
InvalidBackendId (-1) for a shared buffer. arg6 is true for a relation extension request, false
for normal read.
Probe that fires when a buffer read is complete. arg0 and arg1 contain the fork and block
numbers of the page (if this is a relation extension request, arg1 now contains the block
number of the newly added block). arg2, arg3, and arg4 contain the tablespace, database, and
relation OIDs identifying the relation. arg5 is the ID of the backend which created the
temporary relation for a local buffer, or InvalidBackendId (-1) for a shared buffer. arg6 is true
for a relation extension request, false for normal read. arg7 is true if the buffer was found in
the pool, false if not.
Probe that fires before issuing any write request for a shared buffer. arg0 and arg1 contain the
fork and block numbers of the page. arg2, arg3, and arg4 contain the tablespace, database,
and relation OIDs identifying the relation.
Probe that fires when a write request is complete. (Note that this just reflects the time to pass
the data to the kernel; it's typically not actually been written to disk yet.) The arguments are
the same as for buffer-flush-start.
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
Probe that fires when a server process begins to write a dirty buffer. (If this happens
(ForkNumber,
buffer-writeoften, it implies that shared_buffers is too small or the bgwriter control parameters need
BlockNumber, Oid,
dirty-start
adjustment.) arg0 and arg1 contain the fork and block numbers of the page. arg2, arg3,
Oid, Oid)
and arg4 contain the tablespace, database, and relation OIDs identifying the relation.
(ForkNumber,
buffer-writeProbe that fires when a dirty-buffer write is complete. The arguments are the same as
BlockNumber, Oid,
dirty-done
for buffer-write-dirty-start.
Oid, Oid)
wal-bufferProbe that fires when a server process begins to write a dirty WAL buffer because no
write-dirty- ()
more WAL buffer space is available. (If this happens often, it implies that wal_buffers is
start
too small.)
wal-bufferwrite-dirty- ()
Probe that fires when a dirty WAL buffer write is complete.
done
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
1. buffer, ;
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
buffer, ?
flush.
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
1. ForkNumber
, , , fsmvm, init(nologging).
(nologging init
http://blog.163.com/digoal@126/blog/static/163877040201382341433512/ )
src/include/storage/relfilenode.h
InvalidForkNumber = -1,
MAIN_FORKNUM = 0,
FSM_FORKNUM,
VISIBILITYMAP_FORKNUM,
INIT_FORKNUM
} ForkNumber;
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
2. BlockNumber
block id.
src/include/storage/block.h
/*
* each data file (heap or index) is divided into postgres disk blocks
* sequentially, 0 to 0xFFFFFFFE.
*/
3. , , relation oid.
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
buffer?
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
stap -e '
global var;
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start") {
var[pid(),0]=0
var[pid(),1]=0
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("buffer__read__done") {
if ($arg8)
var[pid(),1]++
if (! $arg8)
var[pid(),0]++
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__done") {
}'
PostgreSQL
buffer
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
Probe that fires when beginning to read a block from a relation. arg0 and arg1
(ForkNumber,
contain the fork and block numbers of the page. arg2, arg3, and arg4 contain the
BlockNumber,
smgr-md-read-start
tablespace, database, and relation OIDs identifying the relation. arg5 is the ID of the
Oid, Oid, Oid,
backend which created the temporary relation for a local buffer, or
int)
InvalidBackendId (-1) for a shared buffer.
Probe that fires when a block read is complete. arg0 and arg1 contain the fork and
(ForkNumber, block numbers of the page. arg2, arg3, and arg4 contain the tablespace, database,
BlockNumber, and relation OIDs identifying the relation. arg5 is the ID of the backend which
smgr-md-read-done
Oid, Oid, Oid, created the temporary relation for a local buffer, or InvalidBackendId (-1) for a
int, int, int)
shared buffer. arg6 is the number of bytes actually read, while arg7 is the number
requested (if these are different it indicates trouble).
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
smgr-md-write-start
smgr-md-write-done
(ForkNumber,
BlockNumber,
Oid, Oid, Oid,
int)
Probe that fires when beginning to write a block to a relation. arg0 and arg1
contain the fork and block numbers of the page. arg2, arg3, and arg4 contain
the tablespace, database, and relation OIDs identifying the relation. arg5 is the
ID of the backend which created the temporary relation for a local buffer, or
InvalidBackendId (-1) for a shared buffer.
(ForkNumber,
BlockNumber,
Oid, Oid, Oid,
int, int, int)
Probe that fires when a block write is complete. arg0 and arg1 contain the
fork and block numbers of the page. arg2, arg3, and arg4 contain the
tablespace, database, and relation OIDs identifying the relation. arg5 is the ID
of the backend which created the temporary relation for a local buffer, or
InvalidBackendId (-1) for a shared buffer. arg6 is the number of bytes actually
written, while arg7 is the number requested (if these are different it indicates
trouble).
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
1. relation: forkNum, blocknum, tbs_oid, db_oid, pg_class.relfilenode, (read to local or shared buffer)
buffer, , :
http://blog.163.com/digoal@126/blog/static/1638770402013916488761/
2. relation: 2, relation.
.
3. relation: relation.
4. relation: 2, relation.
.
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
stap -e '
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__read__done") {
printdln("***", pn(), $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done") {
printdln("***", pn(), $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8)
}'
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Output: count(*)
(7 rows)
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
CREATE TABLE
INSERT 0 100000
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__read__done")***1***2***1663***1638
4***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__read__done")***1***0***1663***1638
4***24726***-1***8192***8192
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Output: count(*)
-> Seq Scan on public.t1 (cost=0.00..19.00 rows=1000 width=0) (actual time=0.010..0.164 rows=1000
loops=1)
(7 rows)
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
digoal=# checkpoint;
CHECKPOINT
, checkpoint.
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***0***1663***163
84***12658***-1***8192***8192
...
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***8***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***7***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***6***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***5***1663***163
84***24726***-1***8192***8192
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
digoal=# checkpoint;
CHECKPOINT
, checkpoint.
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***4***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***3***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***2***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***1***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***0***1663***163
84***24726***-1***8192***8192
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("smgr__md__write__done")***0***16***1663***16
384***12649***-1***8192***8192
...
PostgreSQL
read|write relation
http://blog.163.com/digoal@126/blog/static/163877040201391653616103/
EXP : relation, 1.
oid |
------+---------------------------
2840 | pg_toast_2619
2679 | pg_index_indexrelid_index
2610 | pg_index
(3 rows)
t19flush, stap.
relfilenode
-------------
24726
(1 row)
relname
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
lwlock-acquire
(LWLockId,
Probe that fires when an LWLock has been acquired. arg0 is the LWLock's ID. arg1 is the
LWLockMode) requested lock mode, either exclusive or shared.
lwlock-release
(LWLockId)
lwlock-wait-start
Probe that fires when an LWLock was not immediately available and a server process has begun
(LWLockId,
to wait for the lock to become available. arg0 is the LWLock's ID. arg1 is the requested lock
LWLockMode)
mode, either exclusive or shared.
lwlock-waitdone
Probe that fires when a server process has been released from its wait for an LWLock (it does
(LWLockId,
not actually have the lock yet). arg0 is the LWLock's ID. arg1 is the requested lock mode, either
LWLockMode)
exclusive or shared.
lwlockcondacquire
(LWLockId,
Probe that fires when an LWLock was successfully acquired when the caller specified no
LWLockMode) waiting. arg0 is the LWLock's ID. arg1 is the requested lock mode, either exclusive or shared.
Probe that fires when an LWLock has been released (but note that any released waiters have not
yet been awakened). arg0 is the LWLock's ID.
lwlock(LWLockId,
Probe that fires when an LWLock was not successfully acquired when the caller specified no
condacquire-fail LWLockMode) waiting. arg0 is the LWLock's ID. arg1 is the requested lock mode, either exclusive or shared.
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
lock-wait-start
lock-wait-done
deadlock-found
()
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
probe lwlock__release(LWLockId); .
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
probe lock__wait__start(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
LOCKMODE);
, 5LOCKTAG5field
probe lock__wait__done(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
LOCKMODE);
.
:
probe deadlock__found();
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
BufFreelistLock,
ShmemIndexLock,
OidGenLock,
XidGenLock,
ProcArrayLock,
SInvalReadLock,
SInvalWriteLock,
WALInsertLock,
WALWriteLock,
ControlFileLock,
CheckpointLock,
CLogControlLock,
SubtransControlLock,
MultiXactGenLock,
MultiXactOffsetControlLock,
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
MultiXactMemberControlLock,
RelCacheInitLock,
CheckpointerCommLock,
TwoPhaseStateLock,
TablespaceCreateLock,
BtreeVacuumLock,
AddinShmemInitLock,
AutovacuumLock,
AutovacuumScheduleLock,
SyncScanLock,
RelationMappingLock,
AsyncCtlLock,
AsyncQueueLock,
SerializableXactHashLock,
SerializableFinishedListLock,
SerializablePredicateLockListLock,
OldSerXidLock,
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
SyncRepLock,
FirstBufMappingLock,
MaxDynamicLWLock = 1000000000
} LWLockId;
LW_EXCLUSIVE,
LW_SHARED,
LW_WAIT_UNTIL_FREE
} LWLockMode;
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
LOCKTAG_RELATION,
LOCKTAG_RELATION_EXTEND,
LOCKTAG_PAGE,
LOCKTAG_TUPLE,
LOCKTAG_TRANSACTION,
LOCKTAG_OBJECT,
/* whole relation */
/* the right to extend a relation */
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
LOCKTAG_USERLOCK,
LOCKTAG_ADVISORY
} LockTagType;
uint32
uint32
uint32
uint16
uint8
uint8
} LOCKTAG;
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
/* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */
#define NoLock
#define AccessShareLock
/* SELECT */
#define RowShareLock
#define RowExclusiveLock
#define ShareUpdateExclusiveLock 4
* INDEX CONCURRENTLY */
#define ShareLock
#define ShareRowExclusiveLock 6
* SHARE */
#define ExclusiveLock
* UPDATE */
#define AccessExclusiveLock
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
EXP 1. .
stap -e '
global var1
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("lwlock__wait__done") {
var1[$arg1, $arg2]++
probe timer.s($1) {
println("*******************")
foreach(v=[x,y] in var1+)
PostgreSQL
lock
http://blog.163.com/digoal@126/blog/static/163877040201391674922879/
EXP 1. , , .
delete var2
}' 5
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
1. , pg_stat_activity.status, , SQL.
3. xlog2, xlog.
4. , (heap,index,datum), , , work_mem
kbytes, .
5. , ( ), blocks or kbytes.
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
statement-status
(const char *)
Probe that fires anytime the server process updates its pg_stat_activity.status. arg0 is
the new status string.
xlog-insert
Probe that fires when a WAL record is inserted. arg0 is the resource
manager (rmid) for the record. arg1 contains the info flags.
xlog-switch
()
sort-start
sort-done
Probe that fires when a sort operation is started. arg0 indicates heap, index or
datum sort. arg1 is true for unique-value enforcement. arg2 is the number of key
columns. arg3 is the number of kilobytes of work memory allowed. arg4 is true if
random access to the sort result is required.
(bool, long)
Probe that fires when a sort is complete. arg0 is true for external sort, false for
internal sort. arg1 is the number of disk blocks used for an external sort, or
kilobytes of memory used for an internal sort.
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
statement :
src/backend/postmaster/pgstat.c
void
TimestampTz start_timestamp;
TimestampTz current_timestamp;
int
TRACE_POSTGRESQL_STATEMENT_STATUS(cmd_str);
len = 0;
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
EXP :(pg_stat_activity.status), .
}'
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("statement__status")**begin;
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("statement__status")**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("statement__status")**end;
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("statement__status")**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("statement__status")**0
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("xlog__insert") {
}'
INSERT 0 1
OUTPUT :
rmid:10, info:0
rmid:1, info:96
rmid=10heap_redo, info=0heap_redoINSERT.
rmid=1xact_redo, info=96xact_redoXLOG_XACT_COMMIT_COMPACT
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("xlog__switch") {
println(pn())
}'
SQL :
----------------
3/45000728
----------------
3/5EE76270
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("xlog__switch")
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("xlog__switch")
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
EXP :
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__start") {
if ($arg1 == 0) st="HEAP_SORT"
if ($arg1 == 1) st="INDEX_SORT"
if ($arg1 == 2) st="DATUM_SORT"
if ($arg1 == 3) st="CLUSTER_SORT"
printdln("**",pn(),st,$arg2,$arg3,$arg4,$arg5)
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__done") {
if ($arg1) st="EXTERNAL_SORT"
if (! $arg1) st="MEM_SORT"
printdln("**",pn(),st,$arg2)
}'
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
EXP :
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
(9 rows)
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
# , 14837, stap.
?column?
----------
118696
(1 row)
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__start")**HEAP_SORT**0**1**1024**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__done")**EXTERNAL_SORT**14837
14837, analyze.
PostgreSQL
http://blog.163.com/digoal@126/blog/static/1638770402013916221518/
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__start")**HEAP_SORT**0**2**1024**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__done")**EXTERNAL_SORT**14838
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__start")**HEAP_SORT**0**2**1048576**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__done")**MEM_SORT**476753
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__start")**HEAP_SORT**0**2**1048576**0
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("sort__done")**MEM_SORT**931
1. ,
2. probes.d, ()
3. probes.d,
4. probes.h
5.
6. pg_trace.h
7. PostgreSQL
8.
9.
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
1.
src/backend/libpq/auth.c
2. probes.d, ,
vi src/backend/utils/probes.d
// add by digoal,
// 2, sendAuthRequestrecv_password_packet
provider postgresql {
// add by digoal
probe test1(salt);
probe test2(pwd);
3. probes.h
cd src/backend/utils
gmake
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
5.
6. pg_trace.h
7. PostgreSQL
vi src/backend/libpq/auth.c
// add by digoal
#include "pg_trace.h"
...
/*
*/
static void
StringInfoData buf;
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
pq_beginmessage(&buf, 'R');
if (areq == AUTH_REQ_MD5) {
TRACE_POSTGRESQL_TEST1(port->md5Salt);
...
static char *
recv_password_packet(Port *port)
StringInfoData buf;
if (PG_PROTOCOL_MAJOR(port->proto) >= 3)
int
mtype;
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
mtype = pq_getbyte();
if (mtype != 'p')
...
/*
*/
// add by digoal
TRACE_POSTGRESQL_TEST2(buf.data);
return buf.data;
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
mtype = pq_getbyte();
if (mtype != 'p')
...
/*
*/
// add by digoal
TRACE_POSTGRESQL_TEST2(buf.data);
return buf.data;
cd ../../..
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
8.
9.
probe
process("/home/pg93/pgsql9.3.1/bin/postgres").mark("test1"), process("/hompg93/pgsql9.3.1/bin/postgres").
mark("test2") {
}'
Password:
digoal=# \q
Password:
digoal=# \q
MD5 Server -> send salt, Client -> encrypted md5+salt, Server -> receive enc(salted
md5) .
salt, md5.
, , .
vi src/backend/utils/probes.d
provider postgresql {
// add by digoal
probe client_conn();
probe client_close();
gmake
less probes.h
// pg_trace.h,
// add by digoal
#include "pg_trace.h"
....
, , .
pq_initTRACE_POSTGRESQL_CLIENT_CONN();
void
pq_init(void)
// add by digoal
TRACE_POSTGRESQL_CLIENT_CONN();
....
pq_closeTRACE_POSTGRESQL_CLIENT_CLOSE();
static void
// add by digoal
TRACE_POSTGRESQL_CLIENT_CLOSE();
, , .
vi test.stp
probe begin {
if ($1<1 || $2<1) {
exit()
}
}
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("client_conn") {
var1 <<< 1
var11 <<< 1
var2[pid()]=gettimeofday_ms()
, , .
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("client_close") {
# client_conn, , client_conn
.
if (var2[pid()] != 0) {
delete var2[pid()]
var4 <<< 1
var44 <<< 1
probe timer.s($1) {
printf("conn per sec: %d, close per sec: %d\n", @count(var1)/$1, @count(var4)/$1)
delete var1
, , .
delete var4
probe timer.s($2) {
printf("end conn per sec: %d, end close per sec: %d\n", @count(var1)/$2, @count(var4)/$2)
println("hist_linear : ms")
println(@hist_linear(var3,0,5000,50))
delete var11
delete var44
delete var3
delete var1
delete var2
delete var4
exit()
, , .
, , .
hist_linear : ms
0 |@@@@@
50 |@@@
100 |@@
150 |@@
200 |
250 |@@
300 |@@
350 |@
400 |
450 |
500 |@@@@
550 |
600 |@
650 |@@@
700 |@@
5
3
4
0
1
3
2
, , .
750 |
800 |@
850 |@@
900 |@@
950 |@@
1000 |@@
1050 |@@@
1100 |@
1150 |@@@
1200 |@@
1250 |
1300 |@@@
1350 |
1400 |@
1450 |@
1500 |
1550 |@
0
1
3
1
3
2
0
3
0
0
1
, , .
1600 |@
1650 |
1700 |@
1750 |@@@
1800 |@@@
1850 |@
1900 |@
1950 |
2000 |@
2050 |@
2100 |@
2150 |@@@@
2200 |@@
2250 |
2300 |@
2350 |@@
2400 |
1
0
1
4
2
0
1
2
0
, , .
2450 |@
2500 |
2550 |@@@
2600 |
2650 |@@@@
2700 |
2750 |@
2800 |@
2850 |@
2900 |@@@
2950 |@@@@
3000 |
3050 |
1
0
3
0
4
0
3
4
PostgreSQL
http://blog.163.com/digoal@126/blog/static/16387704020139152191581/
SQLvfs.read vfs.write: ,,
OS cache, .
PostgreSQLvfs.read vfs.write.
stpblog.
PostgreSQL
QUERY PLAN
Aggregate (cost=21846.00..21846.01 rows=1 width=0) (actual time=467.932..467.932 rows=1 loops=1)
Output: count(*)
PostgreSQL
QUERY PLAN
Aggregate (cost=16928.08..16928.09 rows=1 width=0) (actual time=8.509..8.509 rows=1 loops=1)
Output: count(*)
-> Index Only Scan using idx_t_1 on public.t (cost=0.42..16094.75 rows=333333 width=0) (actual time=0.146..6.010
rows=9999 loops=1)
Output: id
QUERY PLAN
Aggregate (cost=12.50..12.51 rows=1 width=0) (actual time=918.138..918.138 rows=1 loops=1)
Output: count(*)
Output: generate_series
PostgreSQL
cache
cache
cache
cache
cache
cache
cache
cache
PostgreSQL
cache
cache
cache
cache
cache
cache
^C----------END----------
cache
cache
PostgreSQL
http://blog.163.com/digoal@126/blog/static/16387704020139153195701/
SQL, . PostgreSQL.
stpblog.
PostgreSQL
172.16.3.150
[root@db-172-16-3-39 ~]#
digoal=# \dt+
List of relations
--------+------+-------+----------+-------+-------------
PostgreSQL
stap :
PostgreSQL
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized
view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f'
THEN 'foreign table' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner",
pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "Size",
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_na
PostgreSQL
PostgreSQL
^C----------END----------
PostgreSQL
PostgreSQL.
, /dev/null, :
433MB/s
PostgreSQL
http://blog.163.com/digoal@126/blog/static/16387704020139153455311/
SQL.
pg_backend_pid
----------------
31531
PostgreSQL
stap -e '
probe process("/home/pg93/pgsql9.3.1/bin/postgres").insn {
var1[pid()]++
var2[pid()]++
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__start") {
delete var1[pid()]
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("query__done") {
delete var1[pid()]
probe end {
foreach(x in var2-)
delete var1
delete var2
' -x 31531
PostgreSQL
PostgreSQL
http://blog.163.com/digoal@126/blog/static/163877040201392641033482/
COPY 0 610000
pgbench,
pg93@db-172-16-3-150-> vi test.sql
8, 4.
PostgreSQL
unlogged table :
106MB 25.8.
copy waiting.
21551 pg93
waiting
20 0 2271m 1.9g 1.9g S 24.1 2.0 0:12.54 postgres: postgres digoal [local] COPY
21553 pg93
20 0 2271m 1.9g 1.9g S 24.1 2.0 0:12.51 postgres: postgres digoal [local] COPY waiting
PostgreSQL
pg_locks, .
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid |
virtualtransaction | pid
mode
| granted | fastpath
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+-------------------+-----
--+---------------+---------+----------
6 | ExclusiveLock | f
9 | ExclusiveLock | f
| 6/30
| 2159
| 9/30
| 2159
| 8/30
| 2159
|f
|f
PostgreSQL
stap, .
copy61.
47.5.
PostgreSQL
stap -e '
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("lock__wait__start") {
arr1[pid(),$arg1,$arg2,$arg3,$arg4,$arg5,$arg6] = gettimeofday_us()
probe process("/home/pg93/pgsql9.3.1/bin/postgres").mark("lock__wait__done") {
t = gettimeofday_us()
pid = pid()
lv = arr1[pid,$arg1,$arg2,$arg3,$arg4,$arg5,$arg6]
if ( lv )
arr2[pid,$arg1,$arg2,$arg3,$arg4,$arg5,$arg6] <<< t - lv
probe timer.s(1) {
println("-----")
foreach([a,b,c,d,e,f,g] in arr1)
printf("pid: %d; obj: %d, %d, %d, %d; objtype:%d, locktype: %d, waitcnt:%d, waitus:%d\n", a, b, c, d, e, f,
g, @count(arr2[a,b,c,d,e,f,g]), @sum(arr2[a,b,c,d,e,f,g]))
}'
PostgreSQL
PostgreSQL
?column?
----------
265
(1 row)
PostgreSQL
?column?
----------
16GB
(1 row)
max
--------------
(2168900,16)
(1 row)
PostgreSQL
INFO: "t": found 39039999 removable, 1 nonremovable row versions in 2168901 out of 2168901 pages
PostgreSQL
digoal=# checkpoint;
CHECKPOINT
digoal=# \dt+ t
List of relations
Schema | Name | Type | Owner | Size | Description
----------+------+-------+----------+-------+-------------
(1 row)
188MB 45.77.
PostgreSQL
blocksizeextend lock.
32,
http://blog.163.com/digoal@126/blog/static/163877040201392641033482/
https://sourceware.org/systemtap/examples/
https://sourceware.org/systemtap/tapsets/
https://sourceware.org/systemtap/langref/
https://sourceware.org/systemtap/man/stap.1.html
https://sourceware.org/systemtap/man/index.html
http://blog.163.com/digoal@126/blog/ Systemtap
https://sourceware.org/systemtap/SystemTap_Beginners_Guide/
https://wiki.postgresql.org/wiki/Performance_Analysis_Tools
https://sourceware.org/systemtap/SystemTap_Beginners_Guide/useful-systemtap-scripts.html
About ME
name : digoal.zhou
Corp. : SKYMOBI
QQ : 276732431
BLOG : http://blog.163.com/digoal@126
EMAIL : digoal@126.com