/ manifests / base / postgresql / README.md
README.md
  1  <https://github.com/CrunchyData/postgres-operator-examples/blob/main/kustomize/postgres/postgres.yaml>
  2  
  3  <https://access.crunchydata.com/documentation/postgres-operator/latest/tutorials/backups-disaster-recovery/backup-management>
  4  oc annotate postgrescluster db postgres-operator.crunchydata.com/pgbackrest-backup="$(date)"
  5  oc annotate postgrescluster db --overwrite postgres-operator.crunchydata.com/pgbackrest-backup="$(date)"
  6  
  7  # Run from cronjob
  8  
  9  oc create job --from=cronjob/db-repo1-diff db-repo1-diff
 10  
 11  ### Run a pgbackrest one off inside the db pod
 12  
 13  ```
 14  oc rsh sts/db-instance-hnkw
 15  pgbackrest backup --stanza=db --repo=1 --type=full
 16  ```
 17  
 18  # Upgrade to psql 15
 19  
 20  <https://forum.djangoproject.com/t/a-guide-to-setting-up-django-with-postgresql-15/16514/4>
 21  <https://gist.github.com/axelbdt/74898d80ceee51b69a16b575345e8457>
 22  
 23  # What container images are available
 24  
 25  * https://catalog.redhat.com/software/containers/crunchydata/crunchy-postgres/595e65ef1fbe9833203ff782
 26  * https://catalog.redhat.com/software/containers/crunchydata/crunchy-pgbackrest/6011d5992937381f8e956d7f
 27  
 28  and look for `ubi8-14` images for postgres 14.
 29  But removing the image spec from the postgrescluster CR will use the default image.
 30  
 31  # Register the operator
 32  
 33  Crunchy Postgres for Kubernetes now requires registration for operator upgrades. Register now to be ready for your next upgrade. See https://access.crunchydata.com/register-cpk for details.
 34  
 35  ## WTF uid changes after OCP cluster upgrade
 36  
 37  ```
 38  2024-01-24 16:24:35,105 INFO: Lock owner: ; I am db-instance-hnkw-0
 39  2024-01-24 16:24:35,105 INFO: starting as a secondary
 40  2024-01-24 16:24:35,451 ERROR: Exception during execution of long running task restarting after failure
 41  Traceback (most recent call last):
 42  File "/usr/local/lib/python3.6/site-packages/patroni/async_executor.py", line 166, in run
 43  wakeup = func(*args) if args else func()
 44  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/__init__.py", line 1094, in follow
 45  ret = self.start(timeout=timeout, block_callbacks=change_role, role=role) or None
 46  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/__init__.py", line 701, in start
 47  self.config.write_postgresql_conf(configuration)
 48  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/config.py", line 465, in write_postgresql_conf
 49  self._sanitize_auto_conf()
 50  File "/usr/lib64/python3.6/contextlib.py", line 88, in __exit__
 51  next(self.gen)
 52  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/config.py", line 394, in config_writer
 53  self.set_file_permissions(filename)
 54  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/config.py", line 382, in set_file_permissions
 55  os.chmod(filename, pg_perm.file_create_mode)
 56  PermissionError: [Errno 1] Operation not permitted: '/pgdata/pg14/postgresql.conf'
 57  /tmp/postgres:5432 - no response
 58  2024-01-24 16:24:35,479 ERROR: unable to create backup copies of configuration files
 59  Traceback (most recent call last):
 60  File "/usr/local/lib/python3.6/site-packages/patroni/postgresql/config.py", line 408, in save_configuration_files
 61  shutil.copy(config_file, backup_file)
 62  ```
 63  
 64  The uid of the postgres user changed from 1000750000 to 1000800000
 65  
 66  ```
 67  ❯ oc logs sts/db-instance-hnkw -f -c postgres-startup
 68  Initializing ...
 69  ::postgres-operator: uid::1000800000
 70  ::postgres-operator: gid::0 1000800000
 71  ::postgres-operator: postgres path::/usr/pgsql-14/bin/postgres
 72  ::postgres-operator: postgres version::postgres (PostgreSQL) 14.10
 73  ::postgres-operator: config directory::/pgdata/pg14
 74  ::postgres-operator: data directory::/pgdata/pg14
 75  ::postgres-operator: pgBackRest log directory::/pgdata/pgbackrest/log
 76  ::postgres-operator: data version::14
 77  ::postgres-operator: wal directory::/pgdata/pg14_wal
 78  
 79  ❯ oc rsh sts/db-instance-hnkw
 80  sh-4.4$ ls -la /pgdata/
 81  total 24
 82  drwxrwsrwx.  5 root       postgres    52 Aug 22 17:08 .
 83  dr-xr-xr-x.  1 root       root        56 Jan 24 17:46 ..
 84  drwx--S---. 19 postgres   postgres  4096 Jan 24 16:23 pg14
 85  drwxrws---.  3 1000750000 postgres 65536 Jan 24 15:35 pg14_wal
 86  drwxrwsr-x.  3 1000750000 postgres    17 May  3  2023 pgbackrest
 87  ```
 88  
 89  We can't change the uid of the postgres user in the container, so we need to change the uid of the files in the volume.
 90  
 91  ```
 92  ❯ oc get pvc db-instance-hnkw-pgdata -o yaml | grep volumeName
 93    volumeName: pvc-d290bea6-77ab-4b22-95b0-608b814ed036
 94  
 95  oc debug node/phobos
 96  sh-4.4# mount | grep pvc-d290bea6-77ab-4b22-95b0-608b814ed036
 97  /dev/topolvm/6c4c5f6a-f0f5-4342-98c8-9179e01671ca on /host/var/lib/kubelet/pods/bee3afd8-80d0-4dff-be1c-8134aaa9d11b/volumes/kubernetes.io~csi/pvc-d290bea6-77ab-4b22-95b0-608b814ed036/mount type xfs (rw,relatime,seclabel,nouuid,attr2,inode64,logbufs=8,logbsize=128k,sunit=256,swidth=256,noquota)
 98  sh-4.4# cd /host/var/lib/kubelet/pods/bee3afd8-80d0-4dff-be1c-8134aaa9d11b/volumes/kubernetes.io~csi/pvc-d290bea6-77ab-4b22-95b0-608b814ed036/
 99  sh-4.4# ls -la
100  total 4
101  drwxr-x---. 3 root root        40 Jan 24 20:04 .
102  drwxr-x---. 3 root root        54 Jan 24 20:04 ..
103  drwxrwsrwx. 5 root 1000800000  52 Aug 22 17:08 mount
104  -rw-r--r--. 1 root root       278 Jan 24 20:04 vol_data.json
105  find mount -uid 1000750000 -exec chown -h 1000800000 {} \;
106  ```