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

pg数据库操作

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2022-1-13 13:36:13 | 显示全部楼层 |阅读模式
[postgres@aqzhxxh-pg-1 log]$ psql
2 M% g( T3 A+ }psql (13.3): G+ k! z7 @6 G) l- c, t( p
Type "help" for help.
3 j/ L3 h. Y/ q9 g3 w7 ^& i" H2 Epostgres=# select * from pg_stat_replication;2 C8 ~% L" D2 W9 G1 j" [
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f
9 t6 d9 L7 o; Q- C8 G. k7 u# flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time / @& @6 A- I# F) |# C4 `! k4 H
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--& O# J9 }/ y* }3 f. X9 n7 s
---------+------------+-----------+-----------+------------+---------------+------------+------------6 O: k$ K3 P2 _5 H; v
(0 rows)
: x. f" n4 v4 q/ M8 W. G1 dpostgres=# select * from pg_replication_slots ;
$ r& ?% j, [5 |$ ?" u# K slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn | wal_status
" R0 F6 e: y8 |  q | safe_wal_size ) F* }1 x* i: T+ m7 c
-----------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------+-----------
9 j8 s/ g, Y( I& D6 @$ T! _& t-+---------------. K8 T3 ^6 y8 p" G2 K/ U4 o
(0 rows)1 F' L5 t1 L9 G$ ]4 H% a% u
postgres=# checkpoint ;; ^, d5 b6 e" \0 }7 E1 ?
CHECKPOINT7 G" M/ E2 u! f/ J: T4 P
postgres=#
% O  j, F* e$ {" @4 Q* C

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 14:39:09 | 显示全部楼层
postgres=# show max_wal_size;
+ c2 b) J! ]* y. Q1 T5 ?$ N max_wal_size " f. k* z* @' F* f7 `" O
--------------: D: |( g1 |# ]5 \
8GB
7 n3 Q) |& o, M(1 row)$ n/ H  s& {  D& j
3 d; ?1 Q, k0 ]3 P& s9 u5 f; X" A# D  B
postgres=#
+ C% r& f7 n5 f! q2 z  _7 s# n; h" j

) B5 f& B. U' G0 W[postgres@aqzhxxh-pg-1 pgdata]$ pg_ctl status
% }8 o( I6 T! d( I6 }" C* X+ e0 U& hpg_ctl: server is running (PID: 11857)5 a5 D2 q2 U4 Y7 _! B
/home/postgres/FlyingDB13/bin/postgres' ]2 c& [. h: l1 _. p$ L( Z
[postgres@aqzhxxh-pg-1 pgdata]$ psql
8 i9 _0 k/ `; v5 {$ {psql (13.3)* U( W0 m0 |% n. `# F$ U
Type "help" for help.
! x$ u# A* s  h6 p& Y# \
% `# e1 N* g8 d; M# a% A( H) F/ V* Xpostgres=# show archive_command ;
4 P& q0 T1 ~! x9 _, s archive_command & s: v/ K- |$ N, R7 E  J4 e' [
-----------------
4 r) R6 j$ E8 E2 e% c" E7 b+ E date
( b9 k# V; ?+ t# |7 K. N. F(1 row)$ P. K" l' h+ Q: ~7 X  r% v
[postgres@aqzhxxh-pg-1 pgdata]$ psql
$ C' @0 [4 g- Ppsql (13.3)* _" w9 f, @; t% ~3 g/ i
Type "help" for help.7 H2 N, u/ C6 w( U4 e

* \: Y" y4 k8 i! b, Kpostgres=# show archive_command ;
( K4 m6 V( M' F0 s archive_command + E4 }! U' q, U$ i
-----------------
0 u( ?5 t: ?. }4 [! q date. [3 ^! F# n8 w9 q5 @8 {! z/ h
(1 row)
) m( y7 v8 v3 q$ A
, [7 I3 F4 F3 npostgres=# checkpoint ;
; {* P) f9 `+ gCHECKPOINT* Q8 l* _  V1 n8 ^3 b: n+ W
postgres=# select * from pg_stat_replication ;- ]* |1 u. o, c6 y4 W
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f+ B, B, Q2 \* K; ^& y
lush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time $ F- W/ N) F$ h0 d! \& R0 S
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--
; v4 B4 M: d  A9 e( ^---------+------------+-----------+-----------+------------+---------------+------------+------------
+ B+ \" D( `4 M+ ?: I(0 rows)/ q2 f$ i" [8 ~) l* b" J
  p# `0 _8 B. e9 l+ E: G, O6 P* k$ }
postgres=# select pg_is_in_recovery();6 c, D: [& O2 a. q3 q# G' c
pg_is_in_recovery
+ P, G6 I; k" \) R-------------------
8 j9 q7 I# t7 z# A% P4 n# v f; Z. h4 d7 F/ {7 {0 S2 L* e
(1 row)
" }9 H# }; e9 k5 w) E6 w% f7 t- Q, N5 I( Z% ~8 U( m0 z8 q
postgres=#

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 15:41:35 | 显示全部楼层
postgres=# show   primary_conninfo;
6 X; q4 w$ e* P& B6 z                                                                                                           primary_conninfo                                 ' M! @- I+ A( [# u7 T
                                                                          
. X7 U  O# X7 p9 D; h( K; m------------------------------------------------------------------------------------------------------------------------------------------------------------; Z3 u+ ]% q7 {" R+ }& [: @
--------------------------------------------------------------------------
9 p% C! ]% N/ b' D% _+ l user=replicate passfile='/home/postgres/.pgpass' channel_binding=prefer host=10.101.102.86 port=5432 sslmode=prefer sslcompression=0 ssl_min_protocol_versi
- J) O2 Q! \. }' V3 m$ L/ Ton=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any
$ m$ J3 n8 c( D: h; }; S) o(1 row)' i$ g8 a8 Q: [6 |; h

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2022-1-13 16:04:09 | 显示全部楼层
[postgres@aqzhxxh-pg-2 ~]$ pg_ctl -D /data/pgdata stop
1 P, Y$ s& j$ F9 h2 h0 gwaiting for server to shut down......... done( x5 x8 Z0 q2 V" d
server stopped
) ^/ M1 N2 g1 e6 H8 Z5 e. v[postgres@aqzhxxh-pg-2 ~]$ mv /data/pgdata/ /data/pgdata_0113  t  }& g# D7 d7 s+ o
[postgres@aqzhxxh-pg-2 ~]$ pg_basebackup -Ft -v -P -R -D /data/pgdata -U replicate -h 10.101.102.86 -p5432
% h- \' }. k% }3 apg_basebackup: initiating base backup, waiting for checkpoint to complete
& W) z( i& T# [0 B7 f' w- kpg_basebackup: checkpoint completed
' _. E5 X9 i' @, M0 apg_basebackup: write-ahead log start point: 29/72000028 on timeline 1) H& \& G; [) ?
pg_basebackup: starting background WAL receiver: }! ^( _3 X* k9 A# |& [
pg_basebackup: created temporary replication slot "pg_basebackup_28129"
6 {5 G4 h4 Y- J( X+ R' P140636462/140636462 kB (100%), 1/1 tablespace                                         
6 V7 x; @) q( h6 L! N5 y! e/ f- _, n8 epg_basebackup: write-ahead log end point: 29/7218EAF0
, {) S* i. s: t# O' Jpg_basebackup: waiting for background process to finish streaming ...
+ C8 V$ A' P6 x2 D9 w3 Rpg_basebackup: syncing data to disk ...8 I$ I* F; B+ f, p
pg_basebackup: renaming backup_manifest.tmp to backup_manifest& _7 Z( N" C/ M. O6 n/ j4 M
pg_basebackup: base backup completed
2 j" b5 P* C2 z6 F. n[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 -p5432
! I8 l: e& G9 C" d2 [/ epg_basebackup: initiating base backup, waiting for checkpoint to complete/ w; A" V- C5 v0 W# K
pg_basebackup: checkpoint completed2 E8 ~! |. d1 A- [% R  K
pg_basebackup: write-ahead log start point: 29/75000028 on timeline 1- o8 D2 D# @# a0 R6 `+ D& W1 L
pg_basebackup: starting background WAL receiver6 b; R2 N+ Y: |2 W9 c6 M4 _* P- c
pg_basebackup: created temporary replication slot "pg_basebackup_29262"" P0 L" }( Z8 Y
140644606/140644606 kB (100%), 1/1 tablespace                                         7 U5 c- a" r' s3 Q9 ^/ h3 E
pg_basebackup: write-ahead log end point: 29/7522D570
8 x" c1 H- U5 k- J# E( k9 \+ f# Ppg_basebackup: waiting for background process to finish streaming ...
9 f# g$ n. N: b/ `pg_basebackup: syncing data to disk ...4 v( I2 b$ l# {8 V3 U
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
* Z; b2 I. B5 ~0 z" upg_basebackup: base backup completed
5 q( J8 P9 w; h; l# t; C+ m- J[postgres@aqzhxxh-pg-2 ~]$ pg_ctl -D /data/pgdata start0 b/ a7 L4 x& c7 s0 [% K8 }4 P
waiting for server to start....2022-01-13 16:24:13.290 CST [9337] LOG:  redirecting log output to logging collector process7 x# U% }, G  K
2022-01-13 16:24:13.290 CST [9337] HINT:  Future log output will appear in directory "log".. H6 f; t5 W$ b8 X, W
done& Z$ a* M; f6 `9 i$ z, U0 f9 Y
server started
" P) G; B' g& g0 v2 v[postgres@aqzhxxh-pg-2 ~]$ psql! [' l" S3 v% B0 ~* T
psql (13.3)
. S5 e  p! X0 q) F4 D2 {" `3 iType "help" for help.
# R4 y3 h2 G/ F5 E
. \8 }1 w' R: C1 d8 C) npostgres=# select * from pg_stat_replication ;0 V8 ^# F8 V4 B* Z/ s
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | f
' C) N" _% n; v1 @! N$ U6 Glush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state | reply_time - [7 x- i5 V$ Z) U) v: n; }) i/ ^' ~
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+--------------+-------+----------+-----------+--' b: Z  @4 U4 C$ j5 g% \
---------+------------+-----------+-----------+------------+---------------+------------+------------
1 ]  i( M4 Y" ~(0 rows). C( `1 Z4 r. C  n6 t9 c0 m5 _1 C
6 A! {- o8 I6 C$ `+ k8 _
: ]- e: J! H7 o0 r" G1 y) P% i
[postgres@aqzhxxh-pg-1 ~]$ psql5 s# ~, _& `& r3 Q/ f* x) C8 z
psql (13.3)8 B7 t: |5 d6 a2 {0 _
Type "help" for help.
6 e9 P9 N# K: E% Z! Ypostgres=# select * from pg_stat_replication ;
7 Z- N% T( E- a' B! z; O% S! U  pid  | usesysid |  usename  | application_name |  client_addr  | client_hostname | client_port |         backend_start         | backend_xmin |   state   
; |8 f: U- L# n- g& j: j|  sent_lsn   |  write_lsn  |  flush_lsn  | replay_lsn  |    write_lag    |    flush_lag    |   replay_lag    | sync_priority | sync_state |          reply_' y$ p; s8 m5 D* a/ P) s
time           
/ N# f& l# x* G- o$ r1 K-------+----------+-----------+------------------+---------------+-----------------+-------------+-------------------------------+--------------+-----------# S. @4 O% l, S' g/ S4 H
+-------------+-------------+-------------+-------------+-----------------+-----------------+-----------------+---------------+------------+----------------
1 w; k: B1 ~8 `- P+ D+ d---------------
+ j2 X* V" W6 L7 c+ k4 U# w 29581 |    16384 | replicate | walreceiver      | 10.101.102.87 |                 |        2193 | 2022-01-13 16:23:56.283942+08 |              | streaming
( S; l8 `. a) @2 ~4 T# W8 @* R| 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: g9 N5 E6 t' V( c$ ~
4:17.862534+08' I, w8 x4 g* u0 y, Y6 {( O
(1 row)
/ g- c" z% B* e2 r8 B  f: U
4 g* a, N& S! D8 h. e% V$ x5 ]; m6 L2 u: H3 r/ N
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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