postgresql - deptno/deptno.github.io GitHub Wiki

postgresql

helm chart

  • create database owner [ ROLE NAME ]

ν•¨μˆ˜

  • to_char - timestamp -> char
  • date_trunc - timestamp 값을 μœ μ§€ν•˜λ˜ μΆ”μΆœν•˜λŠ” λ°©μ‹μœΌλ‘œ ν•˜μ—¬ μ›ν•˜λŠ” κ°’λ§Œ μΆ”μΆœ(μ‹œκ°„λ‹¨μœ„ μ ˆμ‚­λ“±)

trigger & event

function 을 μ •μ˜ν•œλ‹€ μ •μ˜ν•œλ‹€ μ •μ˜μ— μ‚¬μš©ν•  수 μžˆλŠ” μ–Έμ–΄λŠ” μ•„λž˜μ™€ κ°™λ‹€

  • c
  • pl/plsql
  • pl/python node μ—μ„œ μ‚¬μš©μ„ ν•΄μ•Όν•˜λŠ”λ° ν•΄λ‹Ή μ–Έμ–΄λ₯Ό μ§€μ›ν•˜μ§€ μ•ŠμœΌλ‹ˆ pl/plsql 을 ν†΅ν•΄μ„œ event λ₯Ό λ°œμƒν‚€κ³  이λ₯Ό listen ν•˜λŠ” λ°©μ‹μ˜ κ΅¬ν˜„μ΄ κ°€λŠ₯ν•˜λ‹€
sequenceDiagram
  participant be as backend/node
  participant db as postgresql
  
  db ->> db: function F μ •μ˜
  note over db: `event λ°œμ†‘`
  db ->> db: trigger T μ •μ˜
  note over db: insert, update, delete μ‹œ function F μ‹€ν–‰
  be ->> db: LISTEN event
  be ->> db: add event listener on 'notification' 
  activate be
  db -->> db: insert evnet λ°œμƒ
  db -->> db: trigger T μ‹€ν–‰
  db -->> db: function F μ‹€ν–‰
  db ->> be: send notification: event 'user_define_channel'
  deactivate be
  be ->> be: handle event

error

helm

upgrade 2023-04-18

  • 헬름 차트λ₯Ό upgrade ν–ˆμ„λ•Œ μ—λŸ¬κ°€ 좜λ ₯λ˜μ§€ μ•Šμ•˜κ³  DEPLOYED 된 κ²ƒμœΌλ‘œ λ‘œκ·Έκ°€ 좜λ ₯λ˜μ–΄ κ·ΈλŸ°κ°€λ³΄λ‹€ ν–ˆλ‹€. values.yaml λ˜ν•œ μ μš©λ˜μ§€ μ•Šμ•˜λ‹€.
$ helm history postgresql

REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION
3               Tue Apr 18 05:41:30 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
4               Tue Apr 18 05:51:28 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
5               Tue Apr 18 11:14:45 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
6               Tue Apr 18 12:11:03 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
7               Tue Apr 18 12:13:16 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
8               Tue Apr 18 12:14:51 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
9               Tue Apr 18 12:15:18 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
10              Tue Apr 18 12:15:25 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
11              Tue Apr 18 12:15:33 2023        superseded      postgresql-12.1.9       15.1.0          Upgrade complete
12              Tue Apr 18 12:28:38 2023        deployed        postgresql-12.1.9       15.1.0          Upgrade complete
  • νžˆμŠ€ν† λ¦¬λ„ 잘 좜λ ₯λ˜λŠ” 것을 확인할 수 μžˆμ—ˆμœΌλ‚˜ μ‹€μ œλ‘œλŠ” 적용이 λ˜μ§€ μ•Šμ•˜λ‹€
  • μ€‘μš” debugging 을 μœ„ν•΄ --debug --dry-run 을 μ˜΅μ…˜μ„ μΆ”κ°€ν•˜λ‹ˆ μ—λŸ¬λ₯Ό 확인할 수 μžˆμ—ˆλ‹€.
  • '--set global.postgresql.auth.postgresPassword=$POSTGRES_PASSWORD' λ₯Ό μΆ”κ°€ν•˜κ³  ENV λ³€μˆ˜λ₯Ό μ‰˜ μ‹œμž‘λΆ€λΆ„μ— λ„£μ–΄μ„œ μ£Όμž…ν•˜μ˜€μœΌλ‚˜ μ‹€νŒ¨ν–ˆλ‹€.
$ POSTGRES_PASSWORD=$(kubectl get secret --namespace "postgresql" postgresql -o jsonpath="{.data.postgres-password}" | base64 -d) helm upgrade -i postgresql chart/postgresql -n postgresql --debug --set global.postgresql.auth.postgresPassword=$POSTGRES_PASSWORD --dry-run

history.go:56: [debug] getting history for release postgresql
upgrade.go:142: [debug] preparing upgrade for postgresql
Error: UPGRADE FAILED: execution error at (postgresql/templates/secrets.yaml:17:24):
PASSWORDS ERROR: You must provide your current passwords when upgrading the release.
                 Note that even after reinstallation, old credentials may be needed as they may be kept in persistent volume claims.
                 Further information can be obtained at https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#credential-errors-while-upgrading-chart-releases

    'global.postgresql.auth.postgresPassword' must not be empty, please add '--set global.postgresql.auth.postgresPassword=$POSTGRES_PASSWORD' to the command. To get the current value:

        export POSTGRES_PASSWORD=$(kubectl get secret --namespace "postgresql" postgresql -o jsonpath="{.data.postgres-password}" | base64 -d)

helm.go:84: [debug] execution error at (postgresql/templates/secrets.yaml:17:24):
PASSWORDS ERROR: You must provide your current passwords when upgrading the release.
                 Note that even after reinstallation, old credentials may be needed as they may be kept in persistent volume claims.
                 Further information can be obtained at https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#credential-errors-while-upgrading-chart-releases

    'global.postgresql.auth.postgresPassword' must not be empty, please add '--set global.postgresql.auth.postgresPassword=$POSTGRES_PASSWORD' to the command. To get the current value:

        export POSTGRES_PASSWORD=$(kubectl get secret --namespace "postgresql" postgresql -o jsonpath="{.data.postgres-password}" | base64 -d)

UPGRADE FAILED
main.newUpgradeCmd.func2
        helm.sh/helm/v3/cmd/helm/upgrade.go:202
github.com/spf13/cobra.(*Command).execute
        github.com/spf13/[email protected]/command.go:916
github.com/spf13/cobra.(*Command).ExecuteC
        github.com/spf13/[email protected]/command.go:1044
github.com/spf13/cobra.(*Command).Execute
        github.com/spf13/[email protected]/command.go:968
main.main
        helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
        runtime/proc.go:250
runtime.goexit
        runtime/asm_arm64.s:1172
  • λΆ„λ¦¬λœ 라인으둜 export POSTGRES_PASSWORD=$(...) λ₯Ό shell μžμ²΄μ— μ£Όμž…μ„ ν•˜κ³  λ‚˜μ„œμ•Ό λͺ…λ Ήμ–΄κ°€ μ„±κ³΅ν•˜λŠ” 것을 확인할 수 μžˆλ‹€.
$ export POSTGRES_PASSWORD=$(kubectl get secret --namespace "postgresql" postgresql -o jsonpath="{.data.postgres-password}" | base64 -d)
$ helm upgrade -i postgresql chart/postgresql -n postgresql --debug --set global.postgresql.auth.postgresPassword=$POSTGRES_PASSWORD --dry-run

history.go:56: [debug] getting history for release postgresql
upgrade.go:142: [debug] preparing upgrade for postgresql
upgrade.go:150: [debug] performing update for postgresql
upgrade.go:313: [debug] dry run for postgresql
Release "postgresql" has been upgraded. Happy Helming!
NAME: postgresql
LAST DEPLOYED: Tue Apr 18 12:27:39 2023
  • 그리고 ν¬νŠΈν¬μ›Œλ”©(localhost λ₯Ό μœ„ν•΄)도 ν™•μΈν•˜μž

lock

SELECT pid, *
FROM pg_locks l
         JOIN pg_class t ON l.relation = t.oid AND t.relkind = 'r'
where relname ='[TABLE_NAME]'

pid ν™•μΈν•΄μ„œ μ»¨ν…Œμ΄λ„ˆ 접속후

kill [PID]

link