From: Marko Kreen Date: Mon, 3 Dec 2012 16:03:55 +0000 (+0200) Subject: Show backend_pid in SHOW CLIENTS/SERVERS. X-Git-Tag: pgbouncer_1_6_rc1~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7b91b78a83ea9222cb6cdd1be52daf760cb8d20;p=pgbouncer Show backend_pid in SHOW CLIENTS/SERVERS. It should help to track connections over unix socket. --- diff --git a/doc/usage.txt b/doc/usage.txt index 556f9e6..f96171e 100644 --- a/doc/usage.txt +++ b/doc/usage.txt @@ -231,6 +231,10 @@ ptr:: link:: Address of client connection the server is paired with. +backend_pid:: + Pid of backend server process. In case the server is another PgBouncer, + it will be a random number associated with this connection. + ==== SHOW CLIENTS; ==== type:: @@ -271,6 +275,10 @@ ptr:: link:: Address of server connection the client is paired with. +backend_pid:: + Random number sent to client as "backend process pid". + Usually unique, but not quaranteed. + ==== SHOW POOLS; ==== A new pool entry is made for each couple of (database, user). @@ -367,12 +375,16 @@ pool_size:: ==== SHOW FDS; ==== -Shows list of fds in use. When the connected user has username -"pgbouncer", connects through Unix socket and has same UID as running -process, the actual fds are passed over the connection. This mechanism is -used to do an online restart. +Internal command - shows list of fds in use with internal state attached to them. + +When the connected user has username "pgbouncer", connects through Unix socket +and has same UID as running process, the actual fds are passed over the connection. +This mechanism is used to do an online restart. Note: This does not work on Windows machines. +This command also blocks internal event loop, so it should not be used +while PgBouncer is in use. + fd:: File descriptor numeric value. diff --git a/src/admin.c b/src/admin.c index 7bf9e80..4a09529 100644 --- a/src/admin.c +++ b/src/admin.c @@ -24,6 +24,7 @@ #include #include +#include /* regex elements */ #define WS0 "[ \t\n\r]*" @@ -500,8 +501,8 @@ static bool admin_show_users(PgSocket *admin, const char *arg) return true; } -#define SKF_STD "sssssisiTTss" -#define SKF_DBG "sssssisiTTssiiiiiii" +#define SKF_STD "sssssisiTTssi" +#define SKF_DBG "sssssisiTTssiiiiiiii" static void socket_header(PktBuf *buf, bool debug) { @@ -509,7 +510,7 @@ static void socket_header(PktBuf *buf, bool debug) "type", "user", "database", "state", "addr", "port", "local_addr", "local_port", "connect_time", "request_time", - "ptr", "link", + "ptr", "link", "backend_pid", "recv_pos", "pkt_pos", "pkt_remain", "send_pos", "send_remain", "pkt_avail", "send_avail"); @@ -523,6 +524,7 @@ static void adr2txt(const PgAddr *adr, char *dst, unsigned dstlen) static void socket_row(PktBuf *buf, PgSocket *sk, const char *state, bool debug) { int pkt_avail = 0, send_avail = 0; + int backend_pid; char ptrbuf[128], linkbuf[128]; char l_addr[PGADDR_BUF], r_addr[PGADDR_BUF]; IOBuf *io = sk->sbuf.io; @@ -541,6 +543,8 @@ static void socket_row(PktBuf *buf, PgSocket *sk, const char *state, bool debug) else linkbuf[0] = 0; + backend_pid = be32dec(sk->cancel_key); + pktbuf_write_DataRow(buf, debug ? SKF_DBG : SKF_STD, is_server_socket(sk) ? "S" :"C", sk->auth_user ? sk->auth_user->name : "(nouser)", @@ -549,7 +553,7 @@ static void socket_row(PktBuf *buf, PgSocket *sk, const char *state, bool debug) l_addr, pga_port(&sk->local_addr), sk->connect_time, sk->request_time, - ptrbuf, linkbuf, + ptrbuf, linkbuf, backend_pid, io ? io->recv_pos : 0, io ? io->parse_pos : 0, sk->sbuf.pkt_remain,