User Tools

Site Tools


сервис_postgresql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
сервис_postgresql [2025/05/12 14:48]
val [pg_dump]
сервис_postgresql [2026/06/11 11:11] (current)
val [Kubernetes]
Line 19: Line 19:
 ==== Kubernetes ==== ==== Kubernetes ====
  
-  * Как не надо делать:​ [[https://​www.digitalocean.com/​community/​tutorials/​how-to-deploy-postgres-to-kubernetes-cluster]]+  * Как не надо делать (уже исправили,​ но, комментарии остались:[[https://​www.digitalocean.com/​community/​tutorials/​how-to-deploy-postgres-to-kubernetes-cluster]]
  
 === Helm === === Helm ===
Line 28: Line 28:
   * Dynamic Volume Provisioning [[Система Kubernetes#​longhorn]]   * Dynamic Volume Provisioning [[Система Kubernetes#​longhorn]]
  
 +  * !!! Поменять repository и allowInsecureImages по аналогии Keycloak в [[Сервис Keycloak#​Kubernetes]]
 <​code>​ <​code>​
 kube1:​~/​my-postgres#​ helm show values oci://​registry-1.docker.io/​bitnamicharts/​postgresql --version 16.6.2 | tee values.yaml.orig kube1:​~/​my-postgres#​ helm show values oci://​registry-1.docker.io/​bitnamicharts/​postgresql --version 16.6.2 | tee values.yaml.orig
Line 55: Line 56:
  
   * [[https://​habr.com/​ru/​companies/​oleg-bunin/​articles/​766898/​|Операторы в Kubernetes]] и [[https://​habr.com/​ru/​companies/​flant/​articles/​684202/​|Обзор операторов PostgreSQL для Kubernetes. Часть 3: CloudNativePG]]   * [[https://​habr.com/​ru/​companies/​oleg-bunin/​articles/​766898/​|Операторы в Kubernetes]] и [[https://​habr.com/​ru/​companies/​flant/​articles/​684202/​|Обзор операторов PostgreSQL для Kubernetes. Часть 3: CloudNativePG]]
 +
 +  * Dynamic Volume Provisioning [[Система Kubernetes#​rancher local-path-provisioner]]
  
 <​code>​ <​code>​
Line 60: Line 63:
  
 kube1:~# kubectl -n cnpg-system get all kube1:~# kubectl -n cnpg-system get all
 +
 +kube1:~# mkdir my-pgcluster;​ cd $_
  
 kube1:​~/​my-pgcluster#​ echo -n keycloak | base64 kube1:​~/​my-pgcluster#​ echo -n keycloak | base64
Line 90: Line 95:
   storage:   storage:
     size: 10Gi     size: 10Gi
 +#    storageClass:​ local-path
 </​code><​code>​ </​code><​code>​
 kube1:​~/​my-pgcluster#​ kubectl create ns my-pgcluster-ns kube1:​~/​my-pgcluster#​ kubectl create ns my-pgcluster-ns
 +</​code>​ 
 +  * [[Система Kubernetes#​Kustomize]] 
 +<​code>​
 kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f keycloak-db-secret.yaml,​my-pgcluster.yaml kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f keycloak-db-secret.yaml,​my-pgcluster.yaml
- +</​code>​ 
-kube1# ​watch kubectl -n my-pgcluster-ns get all +== Проверка состояния кластера cnpg == 
- +<​code>​ 
-kube1# ###kubectl -n my-pgcluster-ns exec -it pod/​my-pgcluster-1 -- psql+kube1:​~/​my-pgcluster# kubectl -n my-pgcluster-ns get cluster 
 +NAME AGE INSTANCES READY STATUS PRIMARY 
 +... 
 +</​code>​ 
 +== Подключение к кластеру cnpg == 
 +<​code>​ 
 +kube1# kubectl -n my-pgcluster-ns exec -it pod/​my-pgcluster-1 -- psql
  
 kube1# ###psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak kube1# ###psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak
Line 110: Line 124:
  
 kube1:~# kubectl cnpg status my-pgcluster -n my-pgcluster-ns kube1:~# kubectl cnpg status my-pgcluster -n my-pgcluster-ns
 +
 +kube1:~# kubectl cnpg promote -n my-pgcluster-ns my-pgcluster my-pgcluster-1
  
 kube1:~# kubectl cnpg logs cluster my-pgcluster -n my-pgcluster-ns kube1:~# kubectl cnpg logs cluster my-pgcluster -n my-pgcluster-ns
 +</​code>​
 +== Миграция с вышедшего из строя узла ==
 +<​code>​
 +kube2:~# kubectl -n my-pgcluster-ns get pods
 +...
 +my-pgcluster-3 ​  ​0/​1 ​    ​Pending ​  ​0 ​         80m
 +
 +kube2# kubectl -n my-pgcluster-ns delete pvc my-pgcluster-3
 +
 +kube2# kubectl -n my-pgcluster-ns delete pods/​my-pgcluster-3
 </​code>​ </​code>​
 ===== Клиент psql ===== ===== Клиент psql =====
Line 122: Line 148:
  
 # sudo -u postgres psql # sudo -u postgres psql
 +
 +postgres=# SELECT version();
  
 postgres=# ALTER USER postgres WITH PASSWORD '​strongpassword';​ postgres=# ALTER USER postgres WITH PASSWORD '​strongpassword';​
Line 128: Line 156:
  
 postgres=# \l postgres=# \l
 +postgres=>​ SELECT datname FROM pg_database;​
  
 postgres=# CREATE USER keycloak WITH PASSWORD '​strongpassword';​ postgres=# CREATE USER keycloak WITH PASSWORD '​strongpassword';​
Line 144: Line 173:
  
 keycloak=# \d user_entity keycloak=# \d user_entity
 +
 +keycloak=# SELECT id, username FROM user_entity;​
  
 keycloak=# SELECT * FROM user_entity WHERE username='​admin';​ keycloak=# SELECT * FROM user_entity WHERE username='​admin';​
Line 181: Line 212:
 server# systemctl restart postgresql server# systemctl restart postgresql
  
-client$ psql postgres://​postgres:​strongpassword@IP_OR_DNS_NAME:​5432/​postgres #-c "​\dt"​+client$ psql postgres://​postgres:​strongpassword@IP_OR_DNS_NAME:​5432/​postgres 
 + 
 +root@my-debian:​~psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak ​-c "​\dt"​ 
 + 
 +kube1:~# host my-pgcluster-rw.my-pgcluster-ns.svc.cluster.local 169.254.25.10 
 + 
 +kube1:~# telnet 10.233.N.M 5432
 </​code>​ </​code>​
  
Line 217: Line 254:
 ===== Потоковая репликация ===== ===== Потоковая репликация =====
  
-  * [[https://prudnitskiy.pro/ru/post/2018-01-05-pgsql-replica/|Потоковая репликация в PostgreSQL ​– короткое введение]]+  * [[https://selectel.ru/blog/​tutorials/how-to-set-up-replication-in-postgresql/|Как настроить ​репликацию в PostgreSQL]]
  
 ===== Резервное копирование и восстановление ===== ===== Резервное копирование и восстановление =====
Line 255: Line 292:
 kube1:~# kubectl -n my-postgres-ns exec -ti pod/​my-postgres-postgresql-0 -- env PGPASSWORD="​strongpassword"​ psql -U postgres -c "​CREATE USER keycloak WITH PASSWORD '​strongpassword';"​ kube1:~# kubectl -n my-postgres-ns exec -ti pod/​my-postgres-postgresql-0 -- env PGPASSWORD="​strongpassword"​ psql -U postgres -c "​CREATE USER keycloak WITH PASSWORD '​strongpassword';"​
  
-kube1:~# cat ~/​keycloak.dump | kubectl -n my-postgres-ns exec -i pod/​my-postgres-postgresql-0 -- env PGPASSWORD="​strongpassword"​ pg_restore -C -d postgres -U postgres+kube1:​~# ​ssh gate.corp13.un ​cat /tmp/​keycloak.dump | kubectl -n my-postgres-ns exec -i pod/​my-postgres-postgresql-0 -- env PGPASSWORD="​strongpassword"​ pg_restore -C -d postgres -U postgres
 </​code>​ </​code>​
  
Line 335: Line 372:
 kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f my-scheduled-backup.yaml kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f my-scheduled-backup.yaml
  
-kube1# kubectl -n my-pgcluster-ns describe ​backup ​my-scheduled-backup+kube1# kubectl -n my-pgcluster-ns describe ​backups.postgresql.cnpg.io ​my-scheduled-backup
  
-kube1# kubectl -n my-pgcluster-ns get backup+kube1# kubectl -n my-pgcluster-ns get backups.postgresql.cnpg.io
 </​code>​ </​code>​
  
Line 345: Line 382:
  
 <​code>​ <​code>​
-kube1:~/my-pgcluster#​ kubectl -n my-pgcluster-ns create secret generic minio-secret \+kube1:~# kubectl create ns my-pgcluster-ns 
 + 
 +kube1:~# kubectl -n my-pgcluster-ns create secret generic minio-secret \
   --from-literal=ACCESS_KEY_ID=root \   --from-literal=ACCESS_KEY_ID=root \
   --from-literal=ACCESS_SECRET_KEY=strongpassword   --from-literal=ACCESS_SECRET_KEY=strongpassword
сервис_postgresql.1747050526.txt.gz · Last modified: 2025/05/12 14:48 by val