postgresql - deptno/deptno.github.io GitHub Wiki
postgresql
- create role user μ ν¨κ» κΆν μμ±
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
- permission denied for database
- duplicate key value violates unique constraint
- ON CONFLICT (id) DO NOTHING
- ON CONFLICT (id) SET UPDATE ...
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]