找回密码
 注册
查看: 1325|回复: 4

pg数据库操作

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2022-1-13 13:36:13 | 显示全部楼层 |阅读模式
[postgres@aqzhxxh-pg-1 log]$ psql
# s: [5 y" q+ U6 I) C: d% spsql (13.3)2 j9 u: v# }/ `2 {  I9 S/ f+ D
Type "help" for help.
6 `, s$ q& U4 k, a# E/ u* Y6 cpostgres=# select * from pg_stat_replication;( N' _! Q7 b- K, s" W
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f
8 z* {( {) [: a: W, H/ X, Elush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time + Y% w6 [; G* P1 f
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--
! V- x6 j' J* V. J$ k7 ^7 X' V& ^0 N7 P---------+------------+-----------+-----------+------------+---------------+------------+------------  u- v- A4 Z; x) Y. @% X" W! }
(0 rows)
4 a6 g7 k1 z/ d8 Tpostgres=# select * from pg_replication_slots ;& l$ ~/ @1 P( q9 e' [; ~
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn | wal_status' x: p2 l) L& L& Q
| safe_wal_size
$ t3 H( S9 f) j1 {/ V  f-----------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------+-----------
' n0 c# C) P( k9 i/ F! P+ _2 u-+---------------
3 x" }  U7 f+ P" V( V, V% A(0 rows)
: L, K, Z4 F2 V: D, Kpostgres=# checkpoint ;
6 j1 y+ w" v3 Z4 D, [9 ?4 X! a  z9 uCHECKPOINT( s( E$ ]/ o$ ~" p0 @
postgres=#
/ w8 F# r' ]8 u0 k4 U

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 14:39:09 | 显示全部楼层
postgres=# show max_wal_size;
) a. [7 c4 b! l( Y  H7 _ max_wal_size
! Q! i: R' K' ~' _7 I, B' A0 k--------------3 s& V9 _% p, a  w, q! \
8GB4 W6 P$ X; R# g5 @
(1 row)
0 ]' \; J" ]. R& T' V! g: G$ r: k& \, H+ {3 w, a% P
postgres=# 7 x0 V. z% {1 h6 O% {# J( {. O
' D$ N7 u, h) Q% B& B

8 F: b  b4 `/ _! n[postgres@aqzhxxh-pg-1 pgdata]$ pg_ctl status
" [* H) E; ^/ d8 x2 i! D: Xpg_ctl: server is running (PID: 11857)  p: T  l# `% g$ z
/home/postgres/FlyingDB13/bin/postgres0 c9 @7 ~* a$ J2 ~
[postgres@aqzhxxh-pg-1 pgdata]$ psql7 ~2 V6 o" r+ `, t
psql (13.3)7 j/ |  j& A# R5 Z1 t# {) m
Type "help" for help.% r! g  Q; f+ U4 q' `+ l2 W
- y' v* a8 h4 X/ k# F& |1 d+ p" U8 R
postgres=# show archive_command ;5 M- x3 F9 k2 n8 q9 c: A' f. K
archive_command
1 x9 V+ I2 q+ p( R! H-----------------9 C! d# L* K, W; ?! Z0 P( b
date
  B' N: g/ P! ?7 C7 M(1 row)  p' s0 ~6 E0 `* b1 A
[postgres@aqzhxxh-pg-1 pgdata]$ psql% B2 Z! u" F8 u6 g/ L0 x! k
psql (13.3)0 Q4 i: @, J3 d1 z+ o  I
Type "help" for help.
3 B$ F! ~6 V- [+ y2 B0 X9 e5 K0 b( @5 P* ^* B8 z" w3 [+ |
postgres=# show archive_command ;4 }' ~8 v: e$ |% j# T7 z; b7 g
archive_command
. m0 b6 D" P7 R& I* q5 M  s. K-----------------% p1 L, V: _# r$ r+ G0 Y
date: J) ?+ k! s7 T
(1 row)' y1 ~) G' G5 W

" u' W/ b: }; z# O) d6 d& t7 g' y' ]; Npostgres=# checkpoint ;
( t6 \6 z2 C! ~6 B$ F) lCHECKPOINT
' C% u* S. p# [+ j; f  v6 I9 wpostgres=# select * from pg_stat_replication ;# W4 S/ h% I/ B- q4 d3 U1 `' j, N5 R
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f# g" j# k+ q& V& {" c* ^
lush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time 1 \% \6 i; x: U" M( d% z- X
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--
2 a+ A  Q- K! a8 [9 h---------+------------+-----------+-----------+------------+---------------+------------+------------
+ K3 u$ n% j8 x1 f' }(0 rows)
! y7 m- e1 n" [* c7 R- z
, ]' X8 |6 u$ K" e$ Q. zpostgres=# select pg_is_in_recovery();
$ L3 D+ h$ j2 D( X( s& s! z pg_is_in_recovery . U& @2 f5 \5 N) D- ^
-------------------
$ |* S7 ^8 d" U f
; h! I2 y6 r0 z+ }& U' w8 o+ a(1 row)
1 f8 z1 }' }" F( ~
$ {2 H# L* [- Z9 Apostgres=#

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 15:41:35 | 显示全部楼层
postgres=# show   primary_conninfo;% I+ {% x4 C% D% a, t* v! p
                                                                                                           primary_conninfo                                 
! \, \; M7 V$ n1 ~7 J                                                                          , ]4 \; M- U0 L* M: t" T
------------------------------------------------------------------------------------------------------------------------------------------------------------
, S$ o9 w. @. ^, s7 Z2 U/ c5 U--------------------------------------------------------------------------
% R% B: h9 @2 \& K+ o$ @ user=replicate passfile='/home/postgres/.pgpass' channel_binding=prefer host=10.101.102.86 port=5432 sslmode=prefer sslcompression=0 ssl_min_protocol_versi7 r! J: j! `* `+ P. N. f
on=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any
! ~. U& v1 r2 x$ w2 r(1 row)0 ]9 }3 s4 D/ }

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 16:04:09 | 显示全部楼层
[postgres@aqzhxxh-pg-2 ~]$ pg_ctl -D /data/pgdata stop
3 G9 T: u# X) l: h: I0 o  J, swaiting for server to shut down......... done
7 ]( E7 r5 `- `- f' A0 Iserver stopped
8 K, X" Y+ ]$ W' J[postgres@aqzhxxh-pg-2 ~]$ mv /data/pgdata/ /data/pgdata_0113- s- Y8 b3 X0 q( e: I
[postgres@aqzhxxh-pg-2 ~]$ pg_basebackup -Ft -v -P -R -D /data/pgdata -U replicate -h 10.101.102.86 -p5432
4 U' j7 t! V; ?7 d) Dpg_basebackup: initiating base backup, waiting for checkpoint to complete9 G' k' k4 O2 R2 }4 J; X
pg_basebackup: checkpoint completed
& y! D# L# `& u) O% R4 e. {+ ~, Gpg_basebackup: write-ahead log start point: 29/72000028 on timeline 1) B/ b/ W, F  [7 `6 R
pg_basebackup: starting background WAL receiver7 S" z! s6 \7 s4 J+ k% A
pg_basebackup: created temporary replication slot "pg_basebackup_28129"8 b3 p' u9 f. |# s8 @; b" T
140636462/140636462 kB (100%), 1/1 tablespace                                           S$ X' L3 {. G9 z
pg_basebackup: write-ahead log end point: 29/7218EAF0
  I# v. W9 W8 G+ fpg_basebackup: waiting for background process to finish streaming ...
* {7 x- g% `5 a$ F- V0 }0 j8 Q7 \pg_basebackup: syncing data to disk ...' J; G9 N9 Q7 Y" A$ |0 |% q
pg_basebackup: renaming backup_manifest.tmp to backup_manifest' o; Y9 I* v( C
pg_basebackup: base backup completed
: v& ^( t3 j1 P& `& j[postgres@aqzhxxh-pg-2 ~]$

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 16:26:43 | 显示全部楼层
[postgres@aqzhxxh-pg-2 ~]$ pg_basebackup -v -P -R -D /data/pgdata -U replicate -h 10.101.102.86 -p54327 c% J5 S, y. _- w/ ]; W; i( |
pg_basebackup: initiating base backup, waiting for checkpoint to complete
! F6 D! X% \7 S6 O0 N' Jpg_basebackup: checkpoint completed: ^& T, w* d$ V3 B+ |
pg_basebackup: write-ahead log start point: 29/75000028 on timeline 1
, O# V$ P" Z3 \9 Xpg_basebackup: starting background WAL receiver9 f! Q, I0 E: h% T- a+ w
pg_basebackup: created temporary replication slot "pg_basebackup_29262"9 [9 L+ M: ~* r8 h6 S
140644606/140644606 kB (100%), 1/1 tablespace                                         ' M1 J- C- F- C' Q& i) W# _% y5 y" |
pg_basebackup: write-ahead log end point: 29/7522D570
/ e, C+ ~3 N% E4 K: s8 \pg_basebackup: waiting for background process to finish streaming ..., Q) }) C( u# Z. B
pg_basebackup: syncing data to disk ...& c3 ?9 \. ^& R8 s  }' E
pg_basebackup: renaming backup_manifest.tmp to backup_manifest7 \* N! O2 o7 S. q: Y
pg_basebackup: base backup completed2 t/ l) s/ J- m5 h6 ]& Z
[postgres@aqzhxxh-pg-2 ~]$ pg_ctl -D /data/pgdata start
- J; q, i. P) c. g) s+ u' Twaiting for server to start....2022-01-13 16:24:13.290 CST [9337] LOG:  redirecting log output to logging collector process
" {8 ?5 n' Y  R4 a; ]. j2022-01-13 16:24:13.290 CST [9337] HINT:  Future log output will appear in directory "log".+ N: K# K8 V" \" ~1 o' ^1 Q
done" V' V( [0 y5 j: q9 y
server started, i/ Z. n7 f9 I1 S$ o
[postgres@aqzhxxh-pg-2 ~]$ psql
* \" |! Y, k' d) ]9 A, [: u& |psql (13.3)/ Q/ O. E2 w/ O
Type "help" for help.5 L9 z# S: G( A: A& W0 ]

5 Z7 r" e+ o% jpostgres=# select * from pg_stat_replication ;& M7 _2 s/ o2 V
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f
& w" k7 @, r" M+ t. F; Blush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time " ~, h+ P. k2 P, f  i/ G
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--' J) r" B  U8 `% A. q- Z$ ~8 m' x
---------+------------+-----------+-----------+------------+---------------+------------+------------
, }) w5 d6 P% T) j/ }(0 rows)
" `1 ]( \) r5 G2 X# H8 r, l6 a$ l$ ]: A  Q0 b' G
6 O. R5 Z- e5 q$ j
[postgres@aqzhxxh-pg-1 ~]$ psql, k8 Y, d0 k' t
psql (13.3)
! ]# a8 Y; m$ bType "help" for help.
1 }9 ~% E9 O# m. V7 ?postgres=# select * from pg_stat_replication ;1 H% Y9 Y( @4 f2 |6 U( |+ H
  pid  | usesysid |  usename  | application_name |  client_addr  | client_hostname | client_port |         backend_start         | backend_xmin |   state   
% {, ]3 T2 X2 m  I% G|  sent_lsn   |  write_lsn  |  flush_lsn  | replay_lsn  |    write_lag    |    flush_lag    |   replay_lag    | sync_priority | sync_state |          reply_
9 j8 K5 f( t! {) `7 e9 Jtime           " i- }2 d8 Y) A5 C
-------+----------+-----------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+-----------) d: s8 [, K; S& x( g/ X
+-------------+-------------+-------------+-------------+-----------------+-----------------+-----------------+---------------+------------+----------------
- d  S3 \* d+ K* ?! b) x---------------2 [& d* b" Y9 {2 s) M( q( R
29581 |    16384 | replicate | walreceiver      | 10.101.102.87 |                 |        2193 | 2022-01-13 16:23:56.283942+08 |              | streaming
; T% [- J/ v% {* O6 n1 [4 Z( Y| 29/7624DCE8 | 29/7624DCE8 | 29/7624DCE8 | 29/7624DCE8 | 00:00:00.000289 | 00:00:00.001832 | 00:00:00.001834 |             0 | async      | 2022-01-13 16:2. E$ e, C. h3 ]
4:17.862534+08
1 h* B3 _4 t5 `# ?. t(1 row)
9 S8 O5 w5 v* l) b3 Z' u2 H9 k
0 T, J; i- X( c  R1 \! |7 J3 K4 r( L% n6 s1 z/ W" b8 d% N1 G
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:24 , Processed in 0.022176 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表