Skip to main content

pg_tuna

Project description

pg-tuna

pg_tuna PyPI version fury.io

PostgreSQL + <({(>(

pg-tuna is a cli program to generate optimal PostgreSQL and AWS PostgreSQL RDS settings. It outputs for AWS RDS already the needed units conversion so the settings can be easily applied.

It is based on excelent work of:

This tool only supports Linux there is no option to choose any other platform and why ;)

Install && run

$ pip install pg-tuna

Run it like:

$ pg-tuna --db-type web  --db-version 11 --memory 8 --cpu-num 8 --disk-type ssd

#-------------------------------------------------------------------------------------------------------------------------
# pg-tuna run on 2023-06-28
# Settings used: db_type = web | db_version = 11 | connections = None | total_memory = 8 | cpu_num = 8 | disk_type = ssd 
# Based on 8 GB RAM, platform Linux, 200 clients and web workload
#---------------------------------------------------------- PG ----------------------------------------------------------

 max_connections = 200
 random_page_cost = 1.1
 shared_buffers = 2048 MB
 effective_cache_size = 6144 MB
 work_mem = 2621 kB
 maintenance_work_mem = 512 MB
 min_wal_size = 1024 MB
 max_wal_size = 4096 MB
 checkpoint_completion_target = 0.9
 wal_buffers = 16 MB
 default_statistics_target = 100
 max_parallel_workers_per_gather = 4.0
 max_worker_processes = 8
 max_parallel_workers = 8
 max_parallel_maintenance_workers = 4.0

#---------------------------------------------------------- AWS ----------------------------------------------------------

 max_connections = 200
 random_page_cost = 1.1
 shared_buffers = 262144 pages (8kB)
 effective_cache_size = 786432 pages (8kB)
 work_mem = 2621 kB
 maintenance_work_mem = 524288 kB
 min_wal_size = 1024 MB
 max_wal_size = 4096 MB
 checkpoint_completion_target = 0.9
 wal_buffers = 2048 pages (8kB)
 default_statistics_target = 100
 max_parallel_workers_per_gather = 4.0
 max_worker_processes = 8
 max_parallel_workers = 8
 max_parallel_maintenance_workers = 4.0

Debugging performance

To debug performance issues we first need to indentify the slow queries. Then we can start benchmarking them and apply changes to our code (adding indexes, modify our ERM , or apply optimized settings to PostgreSQL)

To test queries PostgreSQL has a nice tool pgbench. If you like me can't ssh into the PostgreSQL server and you don't like to install PostgreSQL to get pgbench use the included Dockerfile (it will only create a 8MB image).

https://www.PostgreSQLql.org/docs/10/pgbench.html

pgbench

$ docker build -t pg_tuna/pgbench .

Set settings in env.list to connect to your PostgreSQL instance

We use a query defined in bench/select_count.sql to run our performance tests.

Run

$ docker run -it --env-file ./env.list -v `pwd`/bench:/var/bench pg_tuna/pgbench pgbench -c 10 -j 4 -t 100 -f /var/bench/select_count.sql

Run via local jumphost

$ docker run -it --network="host" --env-file ./env.list -v `pwd`/bench:/var/bench pg_tuna/pgbench pgbench -c 10 -j 4 -t 100 -f /var/bench/select_count.sql

Deploy

$ pip install build twine
$ python -m build
$ twine upload -r pypi dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pg_tuna-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

pg_tuna-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pg_tuna-0.1.1.tar.gz.

File metadata

  • Download URL: pg_tuna-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pg_tuna-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c7ae8231022dbf8f4150528124927a9c9a0be991b18f04fdb00649aff0ccfa1
MD5 267bb18a5ce0e1ca998f15dbc1f944dc
BLAKE2b-256 c1341018b648c5a72e83c1b39ebbab1471e7da461708fa1357d79806165aa925

See more details on using hashes here.

File details

Details for the file pg_tuna-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pg_tuna-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pg_tuna-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc15d8cb3852f457d3ca9d691fd0cf3cf4e511bdbda733783be25e7ee683b887
MD5 37f4ca7b738e6cfbb4338a6e326c07d3
BLAKE2b-256 6e40c523a827628769ac1a93091eb9d4940a1a1808778f038f7e63d67e52c453

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page