You've already forked mastodon-utils
mirror of
https://github.com/jakejarvis/mastodon-utils.git
synced 2025-06-27 15:05:43 -04:00
add postgres & pgbouncer notes
This commit is contained in:
87
notes/postgres.md
Normal file
87
notes/postgres.md
Normal file
@ -0,0 +1,87 @@
|
||||
# Postgres
|
||||
|
||||
## Optimization
|
||||
|
||||
- https://pgtune.leopard.in.ua/#/
|
||||
|
||||
### PgBouncer
|
||||
|
||||
- https://docs.joinmastodon.org/admin/scaling/#pgbouncer
|
||||
- https://masto.host/mastodon-pgbouncer-guide/
|
||||
|
||||
#### Installation
|
||||
|
||||
creating the pgbouncer admin user:
|
||||
|
||||
```bash
|
||||
DB_PASSWORD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c32; echo)
|
||||
echo "pgbouncer password (save this securely): $DB_PASSWORD"
|
||||
echo "CREATE USER pgbouncer WITH PASSWORD '$DB_PASSWORD' CREATEDB" | sudo -u postgres psql -f -
|
||||
```
|
||||
|
||||
#### Config
|
||||
|
||||
.env.production:
|
||||
|
||||
```sh
|
||||
DB_HOST=localhost
|
||||
DB_USER=mastodon
|
||||
DB_NAME=mastodon_production
|
||||
DB_PASS=
|
||||
|
||||
# change from postgres port (default: 5432) to pgbouncer (default: 6432)
|
||||
DB_PORT=6432
|
||||
# add this:
|
||||
PREPARED_STATEMENTS=false
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
/etc/pgbouncer/pgbouncer.ini:
|
||||
|
||||
```ini
|
||||
[databases]
|
||||
mastodon_production = host=127.0.0.1 port=5432 dbname=mastodon_production user=mastodon password=
|
||||
|
||||
[pgbouncer]
|
||||
listen_addr = localhost
|
||||
listen_port = 6432
|
||||
auth_type = md5
|
||||
auth_file = /etc/pgbouncer/userlist.txt
|
||||
admin_users = pgbouncer
|
||||
pool_mode = transaction
|
||||
max_client_conn = 100
|
||||
default_pool_size = 20
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
/etc/pgbouncer/userlist.txt:
|
||||
|
||||
generate md5 hash of postgres passwords with `echo -n "pass" | md5sum`
|
||||
|
||||
```
|
||||
"mastodon" "md5xxxxxxxx"
|
||||
"pgbouncer" "md5xxxxxxxx"
|
||||
```
|
||||
|
||||
## Connecting from TablePlus.app via Tailscale
|
||||
|
||||
/etc/postgresql/15/main/postgres.conf
|
||||
|
||||
```
|
||||
listen_addresses = '*'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
/etc/postgresql/15/main/pg_hba.conf:
|
||||
|
||||
```
|
||||
# tailscale
|
||||
host all all 100.64.0.0/10 md5
|
||||
```
|
||||
|
||||
---
|
||||
|
||||

|
@ -36,7 +36,7 @@ systemctl status redis-exporter.service
|
||||
|
||||
/home/mastodon/live/.env.production:
|
||||
|
||||
```
|
||||
```sh
|
||||
STATSD_ADDR=localhost:9125
|
||||
```
|
||||
|
||||
@ -129,7 +129,7 @@ scrape_configs:
|
||||
|
||||
---
|
||||
|
||||
json-config.yml:
|
||||
/etc/prometheus/json-config.yml:
|
||||
|
||||
```yml
|
||||
modules:
|
||||
|
@ -40,7 +40,7 @@ sudo -u mastodon "$RBENV_ROOT/bin/rbenv" global "$RUBY_VERSION"
|
||||
# run migrations:
|
||||
# https://docs.joinmastodon.org/admin/upgrading/
|
||||
echo "Running pre-deploy database migrations..."
|
||||
sudo -u mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
sudo -u mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production DB_PORT=5432 "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
|
||||
# restart mastodon
|
||||
echo "Restarting services (round 1/2)..."
|
||||
@ -50,7 +50,7 @@ sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
|
||||
echo "Clearing cache..."
|
||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$APP_ROOT/bin/tootctl" cache clear
|
||||
echo "Running post-deploy database migrations..."
|
||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
sudo -u mastodon RAILS_ENV=production DB_PORT=5432 "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||
|
||||
# restart mastodon again
|
||||
echo "Restarting services (round 2/2)..."
|
||||
|
Reference in New Issue
Block a user