Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db 2 #88

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open

Db 2 #88

Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ go.work.sum
.prod.env

coverage.out.tmp

# Pgbadger reports
internal/db/postgres/pgbadger/reports/
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func bindEnv(v *viper.Viper) error {
envBindings := map[string]string{
"postgres.port": "POSTGRES_PORT",
"postgres.dbname": "POSTGRES_DB",
"postgres.user": "POSTGRES_USER",
"postgres.password": "POSTGRES_PASSWORD",
"postgres.user": "POSTGRES_APP_USER",
"postgres.password": "POSTGRES_APP_PASSWORD",
"minio.user": "MINIO_USER",
"minio.password": "MINIO_PASSWORD",
"service.auth.csrf.salt": "CSRF_SALT",
Expand Down
2 changes: 1 addition & 1 deletion config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ postgres:
sslMode: false
driver: postgres

maxOpenConns: 60
maxOpenConns: 100
connMaxLifetime: 120
maxIdleConns: 30
connMaxIdleTime: 20
Expand Down
2 changes: 1 addition & 1 deletion config/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ postgres:
sslMode: false
driver: postgres

maxOpenConns: 60
maxOpenConns: 100
connMaxLifetime: 120
maxIdleConns: 30
connMaxIdleTime: 20
Expand Down
2 changes: 2 additions & 0 deletions docker/.dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ POSTGRES_PORT=5432
POSTGRES_DB=db
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_APP_USER=novamusic_app_user
POSTGRES_APP_PASSWORD=novamusic_app_password

MINIO_USER=user
MINIO_PASSWORD=password
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:16

RUN apt-get update && apt-get install -y pgbadger
6 changes: 5 additions & 1 deletion docker/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ services:

postgres:
container_name: novamusic-postgres
image: postgres:16
build:
dockerfile: docker/Dockerfile.postgres
context: ..
platform: linux/amd64
env_file: .dev.env
environment:
Expand All @@ -171,6 +173,8 @@ services:
retries: 3
volumes:
- postgres-data:/var/lib/postgresql/data
- ../internal/db/postgres/configuration/:/etc/postgresql/
command: postgres -c config_file=/etc/postgresql/postgresql.conf
networks:
- prometheus

Expand Down
6 changes: 5 additions & 1 deletion docker/docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ services:

postgres:
container_name: novamusic-postgres
image: postgres:16
build:
dockerfile: docker/Dockerfile.postgres
context: ..
platform: linux/amd64
env_file: .prod.env
environment:
Expand All @@ -181,6 +183,8 @@ services:
retries: 3
volumes:
- postgres-volume:/var/lib/postgresql/data
- ../internal/db/postgres/configuration/:/etc/postgresql/
command: postgres -c config_file=/etc/postgresql/postgresql.conf
networks:
- prometheus

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/microcosm-cc/bluemonday v1.0.27
github.com/minio/minio-go/v7 v7.0.79
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
Expand All @@ -25,6 +26,7 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -34,6 +36,7 @@ require (
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down Expand Up @@ -45,6 +47,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -74,6 +78,8 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.79 h1:SvJZpj3hT0RN+4KiuX/FxLfPZdsuegy6d/2PiemM/bM=
Expand Down Expand Up @@ -185,8 +191,6 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0=
google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
86 changes: 86 additions & 0 deletions internal/db/postgres/configuration/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'
Starlexxx marked this conversation as resolved.
Show resolved Hide resolved

#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

logging_collector = on

log_directory = 'log' # directory with log files, can be absolute or relative to PGDATA

log_filename = 'postgresql-%a.log' # log file name pattern based on day of week.
# it is needed for log_truncate_on_rotation
# because files will be rewritten every week.

log_rotation_age = 1d # automatic rotation of logfiles will
# happen after that time.
# 0 disables.
# creates new log file every day and
# its name will contain day of week
# according to log_filename.

log_rotation_size = 0 # automatic rotation of logfiles will
# happen after that much log output.
# 0 disables.

log_truncate_on_rotation = on # file with the
# same name as the new log file will be
# truncated rather than appended to.
# files will have the same names every week
# according to log_filename.
# so files will be stored for a week.

# - When to Log -

log_min_duration_statement = 1000 # -1 is disabled, 0 logs all statements
# and their durations, > 0 logs only
# statements running at least this number
# of milliseconds

#------------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------

# - Statement Behavior -

statement_timeout = 5s # maximum statement execution time
# abort any statement that takes more than the specified amount of time

lock_timeout = 3s # maximum time that any statement will wait for acquiring a lock on a table, index, row, or other database object
# abort any statement that waits longer than the specified amount of time

# - Locale and Formatting -

lc_messages='en_US.UTF-8' # for pgBadger

# - Shared Library Preloading -

shared_preload_libraries = 'pg_stat_statements, auto_explain'

#------------------------------------------------------------------------------
# PG_STAT_STATEMENTS
#------------------------------------------------------------------------------

pg_stat_statements.max = 10000 # maximum number of statements tracked by the module

pg_stat_statements.track = all # also track nested statements

#------------------------------------------------------------------------------
# AUTO_EXPLAIN
#------------------------------------------------------------------------------

auto_explain.log_min_duration = 500 # -1 (default) disables logging of plans
# minimum statement execution time, in milliseconds,
# that will cause the statement's plan to be logged

auto_explain.log_analyze = on # causes EXPLAIN ANALYZE output, rather than just EXPLAIN output

auto_explain.log_verbose = on # equivalent to the VERBOSE option of EXPLAIN.
Loading